From eb9d5d60d18daf84dbdb3e1deb1a1816ac1a3a4b Mon Sep 17 00:00:00 2001 From: Vxrtrauter <101264710+Vxrtrauter@users.noreply.github.com> Date: Thu, 9 Apr 2026 23:31:09 +0200 Subject: [PATCH] fix: Centralize single-instance check and refactor startup Introduce check_running(app) to create and check SingleInstance early in main(), store it on app._single_instance, and reuse that instance in run_gui() instead of constructing a new one. Move single-instance exit logic (print, closehelper, force_exit) into the new helper and wire single.on_raise to show_from_tray. Also replace the previous consoleLog call with print and add a comment indicating the check is for SoftwareManager already running. This centralizes startup single-instance handling and avoids creating multiple SingleInstance objects. --- src/main.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.py b/src/main.py index 7ab5c2e..7802e75 100644 --- a/src/main.py +++ b/src/main.py @@ -59,7 +59,18 @@ class SingleInstance(QObject): def on_raise(self): pass +def check_running(app): + single = SingleInstance() + if single.is_running: + print("Another instance is already running. Exiting this instance.") + closehelper() + force_exit() + + app._single_instance = single + + def run_gui(app): + single = app._single_instance custom_colors = {} if state.accent_color: custom_colors["primary"] = state.accent_color @@ -98,13 +109,6 @@ def run_gui(app): widget.raise_() widget.activateWindow() - single = SingleInstance() - if single.is_running: - consoleLog("Another instance is already running. Exiting this instance.") - closehelper() - force_exit() - - app._single_instance = single single.on_raise = show_from_tray set_main_window(widget) @@ -120,10 +124,10 @@ def keyboardinterrupthandler(signum, frame): def main(): # Begin counting startup time start_time = time.perf_counter() - # Initialize UI Engine app = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv) - + # Check if SoftwareManager is already running + check_running(app) # Parse saved files read_config() logs = get_download_logs()