mirror of
https://github.com/borgbase/vorta
synced 2025-02-22 22:30:41 +00:00
Implement autostart linux by @Hofer-Julian (#191)
This commit is contained in:
parent
1eb4959000
commit
8612703df2
4 changed files with 79 additions and 31 deletions
72
src/vorta/autostart.py
Normal file
72
src/vorta/autostart.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
import sys
|
||||
from pathlib import Path
|
||||
from PyQt5 import QtCore
|
||||
from setuptools import Distribution
|
||||
from setuptools.command.install import install
|
||||
|
||||
|
||||
LINUX_STARTUP_FILE = """\
|
||||
[Desktop Entry]
|
||||
Name=Vorta
|
||||
GenericName=Backup Software
|
||||
Exec={}/vorta
|
||||
Terminal=false
|
||||
Icon=vorta
|
||||
Categories=Utility
|
||||
Type=Application
|
||||
StartupNotify=false
|
||||
X-GNOME-Autostart-enabled=true
|
||||
"""
|
||||
|
||||
|
||||
def open_app_at_startup(enabled=True):
|
||||
"""
|
||||
This function adds/removes the current app bundle from Login items in macOS or most Linux desktops
|
||||
"""
|
||||
if sys.platform == 'darwin':
|
||||
from Foundation import NSDictionary
|
||||
|
||||
from Cocoa import NSBundle, NSURL
|
||||
from CoreFoundation import kCFAllocatorDefault
|
||||
# CF = CDLL(find_library('CoreFoundation'))
|
||||
from LaunchServices import (LSSharedFileListCreate, kLSSharedFileListSessionLoginItems,
|
||||
LSSharedFileListInsertItemURL, kLSSharedFileListItemHidden,
|
||||
kLSSharedFileListItemLast, LSSharedFileListItemRemove)
|
||||
|
||||
app_path = NSBundle.mainBundle().bundlePath()
|
||||
url = NSURL.alloc().initFileURLWithPath_(app_path)
|
||||
login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
|
||||
props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden)
|
||||
|
||||
new_item = LSSharedFileListInsertItemURL(login_items, kLSSharedFileListItemLast,
|
||||
None, None, url, props, None)
|
||||
if not enabled:
|
||||
LSSharedFileListItemRemove(login_items, new_item)
|
||||
elif sys.platform.startswith('linux'):
|
||||
config_path = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.ConfigLocation)
|
||||
autostart_file_path = Path(config_path) / 'autostart' / 'vorta.desktop'
|
||||
if enabled:
|
||||
dir_entry_point = get_setuptools_script_dir()
|
||||
autostart_file_path.write_text(LINUX_STARTUP_FILE.format(dir_entry_point))
|
||||
else:
|
||||
if autostart_file_path.exists():
|
||||
autostart_file_path.unlink()
|
||||
|
||||
|
||||
# Get entry point of vorta
|
||||
# From https://stackoverflow.com/questions/
|
||||
# 25066084/get-entry-point-script-file-location-in-setuputils-package
|
||||
class OnlyGetScriptPath(install):
|
||||
def run(self):
|
||||
# does not call install.run() by design
|
||||
self.distribution.install_scripts = self.install_scripts
|
||||
|
||||
|
||||
def get_setuptools_script_dir():
|
||||
dist = Distribution({'cmdclass': {'install': OnlyGetScriptPath}})
|
||||
dist.dry_run = True # not sure if necessary, but to be safe
|
||||
dist.parse_config_files()
|
||||
command = dist.get_command_obj('install')
|
||||
command.ensure_finalized()
|
||||
command.run()
|
||||
return dist.install_scripts
|
|
@ -211,15 +211,15 @@ def get_misc_settings():
|
|||
'key': 'enable_notifications_success', 'value': False, 'type': 'checkbox',
|
||||
'label': trans_late('settings',
|
||||
'Also notify about successful background tasks')
|
||||
},
|
||||
{
|
||||
'key': 'autostart', 'value': False, 'type': 'checkbox',
|
||||
'label': trans_late('settings',
|
||||
'Automatically start Vorta at login')
|
||||
}
|
||||
]
|
||||
if sys.platform == 'darwin':
|
||||
settings += [
|
||||
{
|
||||
'key': 'autostart', 'value': False, 'type': 'checkbox',
|
||||
'label': trans_late('settings',
|
||||
'Automatically start Vorta at login')
|
||||
},
|
||||
{
|
||||
'key': 'check_for_updates', 'value': True, 'type': 'checkbox',
|
||||
'label': trans_late('settings',
|
||||
|
|
|
@ -222,31 +222,6 @@ def uses_dark_mode():
|
|||
return None
|
||||
|
||||
|
||||
def open_app_at_startup(enabled=True):
|
||||
"""
|
||||
This function adds/removes the current app bundle from Login items in macOS
|
||||
"""
|
||||
if sys.platform == 'darwin':
|
||||
from Foundation import NSDictionary
|
||||
|
||||
from Cocoa import NSBundle, NSURL
|
||||
from CoreFoundation import kCFAllocatorDefault
|
||||
# CF = CDLL(find_library('CoreFoundation'))
|
||||
from LaunchServices import (LSSharedFileListCreate, kLSSharedFileListSessionLoginItems,
|
||||
LSSharedFileListInsertItemURL, kLSSharedFileListItemHidden,
|
||||
kLSSharedFileListItemLast, LSSharedFileListItemRemove)
|
||||
|
||||
app_path = NSBundle.mainBundle().bundlePath()
|
||||
url = NSURL.alloc().initFileURLWithPath_(app_path)
|
||||
login_items = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, None)
|
||||
props = NSDictionary.dictionaryWithObject_forKey_(True, kLSSharedFileListItemHidden)
|
||||
|
||||
new_item = LSSharedFileListInsertItemURL(login_items, kLSSharedFileListItemLast,
|
||||
None, None, url, props, None)
|
||||
if not enabled:
|
||||
LSSharedFileListItemRemove(login_items, new_item)
|
||||
|
||||
|
||||
def format_archive_name(profile, archive_name_tpl):
|
||||
"""
|
||||
Generate an archive name. Default:
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
from PyQt5.QtWidgets import QCheckBox
|
||||
|
||||
from vorta.i18n import translate
|
||||
from vorta.utils import get_asset, open_app_at_startup
|
||||
from vorta.utils import get_asset
|
||||
from vorta.autostart import open_app_at_startup
|
||||
from vorta.models import SettingsModel, BackupProfileMixin, get_misc_settings
|
||||
from vorta._version import __version__
|
||||
from vorta.views.utils import get_theme_class
|
||||
|
|
Loading…
Reference in a new issue