Run in foreground by default (#380)

* Run in foreground by default
* Open main window on startup by default.
* Remove redundant comment
* PEP8 fixes
This commit is contained in:
Manuel Riel 2020-01-03 22:23:06 +08:00 committed by GitHub
parent 78a22de54e
commit d0c138a0c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 21 deletions

View File

@ -15,21 +15,18 @@ def main():
args = parse_args()
signal.signal(signal.SIGINT, signal.SIG_DFL) # catch ctrl-c and exit
frozen_binary = getattr(sys, 'frozen', False)
want_version = getattr(args, 'version', False)
want_foreground = getattr(args, 'foreground', False) and not getattr(args, 'daemonize', False)
want_background = getattr(args, 'daemonize', False)
if want_version:
print(f"Vorta {__version__}")
sys.exit()
# We assume that a frozen binary is a fat single-file binary made with
# PyInstaller. These are not compatible with forking into background here:
if not (want_foreground or frozen_binary):
if want_background:
if os.fork():
sys.exit()
init_logger(foreground=want_foreground)
init_logger(background=want_background)
# Init database
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))

View File

@ -54,9 +54,10 @@ class VortaApp(QtSingleApplication):
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
args = parse_args()
if not (hasattr(args, 'daemonize') and args.daemonize):
if (hasattr(args, 'foreground') and args.foreground) or SettingsModel.get(key='foreground').value:
self.open_main_window_action()
if getattr(args, 'daemonize', False):
pass
elif 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

@ -14,7 +14,7 @@ from .config import LOG_DIR
logger = logging.getLogger()
def init_logger(foreground=False):
def init_logger(background=False):
logger.setLevel(logging.DEBUG)
logging.getLogger('peewee').setLevel(logging.INFO)
logging.getLogger('apscheduler').setLevel(logging.INFO)
@ -32,7 +32,9 @@ def init_logger(foreground=False):
fh.setFormatter(formatter)
logger.addHandler(fh)
if foreground: # log to console, when running in foreground
if background:
pass
else: # log to console, when running in foreground
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)

View File

@ -220,9 +220,9 @@ def get_misc_settings():
'Automatically start Vorta at login')
},
{
'key': 'foreground', 'value': False, 'type': 'checkbox',
'key': 'foreground', 'value': True, 'type': 'checkbox',
'label': trans_late('settings',
'Run Vorta in the foreground when started manually')
'Open main window on startup')
},
]
if sys.platform == 'darwin':
@ -261,8 +261,6 @@ 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())
if created and setting['key'] == "enable_notifications_success":
s.value = not bool(is_system_tray_available())
s.label = setting['label']

View File

@ -178,13 +178,9 @@ def parse_args():
parser.add_argument('--version', '-V',
action='store_true',
help="Show version and exit.")
parser.add_argument('--foreground', '-f',
parser.add_argument('--daemonize', '-d',
action='store_true',
help="Don't fork into background and open main window on startup.")
if sys.platform.startswith("linux"):
parser.add_argument('--daemonize', '-d',
action='store_true',
help="Daemonize and don't open window on startup.")
help="Fork to background and don't open window on startup.")
return parser.parse_known_args()[0]