mirror of
https://github.com/borgbase/vorta
synced 2024-12-22 07:43:09 +00:00
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:
parent
78a22de54e
commit
d0c138a0c2
5 changed files with 15 additions and 21 deletions
|
@ -15,21 +15,18 @@ def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
signal.signal(signal.SIGINT, signal.SIG_DFL) # catch ctrl-c and exit
|
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_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:
|
if want_version:
|
||||||
print(f"Vorta {__version__}")
|
print(f"Vorta {__version__}")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# We assume that a frozen binary is a fat single-file binary made with
|
if want_background:
|
||||||
# PyInstaller. These are not compatible with forking into background here:
|
|
||||||
if not (want_foreground or frozen_binary):
|
|
||||||
if os.fork():
|
if os.fork():
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
init_logger(foreground=want_foreground)
|
init_logger(background=want_background)
|
||||||
|
|
||||||
# Init database
|
# Init database
|
||||||
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
|
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
|
||||||
|
|
|
@ -54,9 +54,10 @@ def __init__(self, args_raw, single_app=False):
|
||||||
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
|
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if not (hasattr(args, 'daemonize') and args.daemonize):
|
if getattr(args, 'daemonize', False):
|
||||||
if (hasattr(args, 'foreground') and args.foreground) or SettingsModel.get(key='foreground').value:
|
pass
|
||||||
self.open_main_window_action()
|
elif SettingsModel.get(key='foreground').value:
|
||||||
|
self.open_main_window_action()
|
||||||
|
|
||||||
self.backup_started_event.connect(self.backup_started_event_response)
|
self.backup_started_event.connect(self.backup_started_event_response)
|
||||||
self.backup_finished_event.connect(self.backup_finished_event_response)
|
self.backup_finished_event.connect(self.backup_finished_event_response)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
def init_logger(foreground=False):
|
def init_logger(background=False):
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
logging.getLogger('peewee').setLevel(logging.INFO)
|
logging.getLogger('peewee').setLevel(logging.INFO)
|
||||||
logging.getLogger('apscheduler').setLevel(logging.INFO)
|
logging.getLogger('apscheduler').setLevel(logging.INFO)
|
||||||
|
@ -32,7 +32,9 @@ def init_logger(foreground=False):
|
||||||
fh.setFormatter(formatter)
|
fh.setFormatter(formatter)
|
||||||
logger.addHandler(fh)
|
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 = logging.StreamHandler()
|
||||||
ch.setLevel(logging.DEBUG)
|
ch.setLevel(logging.DEBUG)
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
|
|
|
@ -220,9 +220,9 @@ def get_misc_settings():
|
||||||
'Automatically start Vorta at login')
|
'Automatically start Vorta at login')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'key': 'foreground', 'value': False, 'type': 'checkbox',
|
'key': 'foreground', 'value': True, 'type': 'checkbox',
|
||||||
'label': trans_late('settings',
|
'label': trans_late('settings',
|
||||||
'Run Vorta in the foreground when started manually')
|
'Open main window on startup')
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
if sys.platform == 'darwin':
|
if sys.platform == 'darwin':
|
||||||
|
@ -261,8 +261,6 @@ def init_db(con):
|
||||||
if created and setting['key'] == "use_light_icon":
|
if created and setting['key'] == "use_light_icon":
|
||||||
# Check if macOS with enabled dark mode or Linux with GNOME DE
|
# 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', '')
|
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":
|
if created and setting['key'] == "enable_notifications_success":
|
||||||
s.value = not bool(is_system_tray_available())
|
s.value = not bool(is_system_tray_available())
|
||||||
s.label = setting['label']
|
s.label = setting['label']
|
||||||
|
|
|
@ -178,13 +178,9 @@ def parse_args():
|
||||||
parser.add_argument('--version', '-V',
|
parser.add_argument('--version', '-V',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Show version and exit.")
|
help="Show version and exit.")
|
||||||
parser.add_argument('--foreground', '-f',
|
parser.add_argument('--daemonize', '-d',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="Don't fork into background and open main window on startup.")
|
help="Fork to background and don't open 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.")
|
|
||||||
|
|
||||||
return parser.parse_known_args()[0]
|
return parser.parse_known_args()[0]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue