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.
This commit is contained in:
Vxrtrauter
2026-04-09 23:31:09 +02:00
parent 7aea5c882a
commit eb9d5d60d1
+13 -9
View File
@@ -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()