Add option for starting Vorta in foreground.

This commit is contained in:
Brendan Van Hook 2019-04-16 17:07:57 -04:00 committed by Hofer-Julian
parent b300ef042a
commit d6347b6caf
4 changed files with 33 additions and 6 deletions

View File

@ -54,8 +54,9 @@ class VortaApp(QtSingleApplication):
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
args = parse_args()
if hasattr(args, 'foreground') and args.foreground:
self.open_main_window_action()
if not (hasattr(args, 'background') and args.background):
if (hasattr(args, 'foreground') and args.foreground) or SettingsModel.get(key='foreground').value:
self.open_main_window_action()
self.backup_started_event.connect(self.backup_started_event_response)
self.backup_finished_event.connect(self.backup_finished_event_response)

View File

@ -5,7 +5,7 @@ LINUX_STARTUP_FILE = """\
[Desktop Entry]
Name=Vorta
GenericName=Backup Software
Exec={}
Exec={} --background
Terminal=false
Icon=vorta
Categories=Utility
@ -18,7 +18,8 @@ X-GNOME-Autostart-Delay=20
def open_app_at_startup(enabled=True):
"""
This function adds/removes the current app bundle from Login items in macOS or most Linux desktops
On macOS, this function adds/removes the current app bundle from Login items
while on Linux it adds a .desktop file at ~/.config/autostart
"""
if sys.platform == 'darwin':
from Foundation import NSDictionary
@ -51,7 +52,7 @@ def open_app_at_startup(enabled=True):
if enabled:
if Path('/.flatpak-info').exists():
# Vorta runs as flatpak
autostart_file_path.write_text(LINUX_STARTUP_FILE.format('flatpak run com.borgbase.vorta'))
autostart_file_path.write_text(LINUX_STARTUP_FILE.format('flatpak run com.borgbase.Vorta'))
else:
autostart_file_path.write_text(LINUX_STARTUP_FILE.format('vorta'))

View File

@ -11,6 +11,7 @@ from datetime import datetime, timedelta
import peewee as pw
from playhouse.migrate import SqliteMigrator, migrate
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon
from vorta.i18n import trans_late
from vorta.utils import slugify, uses_dark_mode
@ -218,7 +219,7 @@ def get_misc_settings():
'key': 'autostart', 'value': False, 'type': 'checkbox',
'label': trans_late('settings',
'Automatically start Vorta at login')
}
},
]
if sys.platform == 'darwin':
settings += [
@ -233,6 +234,14 @@ def get_misc_settings():
'Include pre-release versions when checking for updates')
},
]
if sys.platform.startswith('linux'):
settings += [
{
'key': 'foreground', 'value': False, 'type': 'checkbox',
'label': trans_late('settings',
'Run Vorta in the foreground when started manually')
},
]
return settings
@ -257,6 +266,8 @@ def init_db(con):
if created and setting['key'] == "use_light_icon":
# Check if macOS with enabled dark mode or Linux with GNOME DE
s.value = bool(uses_dark_mode()) or 'GNOME' in os.environ.get('XDG_CURRENT_DESKTOP', '')
if created and setting['key'] == "foreground":
s.value = not bool(is_system_tray_available())
s.label = setting['label']
s.save()
@ -354,3 +365,12 @@ def init_db(con):
ArchiveModel.insert_many(data[i:i + size], fields=fields).execute()
_apply_schema_update(current_schema, 13)
def is_system_tray_available():
''' Can only be called when the event loop isn't running yet '''
app = QApplication([])
tray = QSystemTrayIcon()
is_available = tray.isSystemTrayAvailable()
app.quit()
return is_available

View File

@ -180,6 +180,11 @@ def parse_args():
parser.add_argument('--foreground', '-f',
action='store_true',
help="Don't fork into background and open main window on startup.")
if sys.platform.startswith("linux"):
parser.add_argument('--background', '-b',
action='store_true',
help="Fork into background. This option takes precedence over other settings.")
return parser.parse_known_args()[0]