mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
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:
+13
-9
@@ -59,7 +59,18 @@ class SingleInstance(QObject):
|
|||||||
def on_raise(self):
|
def on_raise(self):
|
||||||
pass
|
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):
|
def run_gui(app):
|
||||||
|
single = app._single_instance
|
||||||
custom_colors = {}
|
custom_colors = {}
|
||||||
if state.accent_color:
|
if state.accent_color:
|
||||||
custom_colors["primary"] = state.accent_color
|
custom_colors["primary"] = state.accent_color
|
||||||
@@ -98,13 +109,6 @@ def run_gui(app):
|
|||||||
widget.raise_()
|
widget.raise_()
|
||||||
widget.activateWindow()
|
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
|
single.on_raise = show_from_tray
|
||||||
|
|
||||||
set_main_window(widget)
|
set_main_window(widget)
|
||||||
@@ -120,10 +124,10 @@ def keyboardinterrupthandler(signum, frame):
|
|||||||
def main():
|
def main():
|
||||||
# Begin counting startup time
|
# Begin counting startup time
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|
||||||
# Initialize UI Engine
|
# Initialize UI Engine
|
||||||
app = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
|
||||||
|
# Check if SoftwareManager is already running
|
||||||
|
check_running(app)
|
||||||
# Parse saved files
|
# Parse saved files
|
||||||
read_config()
|
read_config()
|
||||||
logs = get_download_logs()
|
logs = get_download_logs()
|
||||||
|
|||||||
Reference in New Issue
Block a user