diff --git a/synodic_client/application/qt.py b/synodic_client/application/qt.py index 1df55c8..0a6b8d7 100644 --- a/synodic_client/application/qt.py +++ b/synodic_client/application/qt.py @@ -6,6 +6,7 @@ from porringer.api import API, APIParameters from porringer.schema import ListPluginsParameters, LocalConfiguration +from PySide6.QtCore import Qt from PySide6.QtWidgets import QApplication from synodic_client.application.screen.screen import Screen @@ -42,14 +43,15 @@ def application() -> None: app = QApplication([]) app.setQuitOnLastWindowClosed(False) - screen = Screen() + # Reduce CPU usage when idle - process events less aggressively + app.setAttribute(Qt.ApplicationAttribute.AA_CompressHighFrequencyEvents) - # Store tray screen as instance attribute using object.__setattr__ - # to avoid type checking issues with dynamic attributes - tray_screen = TrayScreen(app, client, icon, screen.window) - object.__setattr__(app, 'tray', tray_screen) + _screen = Screen() + _tray = TrayScreen(app, client, icon, _screen.window) - app.exec_() + # sys.exit ensures proper cleanup and exit code propagation + # Leading underscore indicates references kept alive intentionally until exec() returns + sys.exit(app.exec()) if __name__ == '__main__': diff --git a/synodic_client/application/screen/screen.py b/synodic_client/application/screen/screen.py index 92cd4a2..f2a7e9a 100644 --- a/synodic_client/application/screen/screen.py +++ b/synodic_client/application/screen/screen.py @@ -9,13 +9,26 @@ class MainWindow(QMainWindow): def __init__(self) -> None: """Initialize the main window.""" super().__init__() + self.setWindowTitle('Synodic Client') + + def show(self) -> None: + """Show the window, initializing UI lazily on first show.""" + # Future: Initialize heavy UI components here on first show + super().show() class Screen: """Screen class for the Synodic Client application.""" - def __init__(self): - """Initialize the screen.""" - self.window = MainWindow() + _window: MainWindow | None = None + + @property + def window(self) -> MainWindow: + """Lazily create the main window on first access. - self.window.setWindowTitle('Synodic Client') + Returns: + The MainWindow instance. + """ + if self._window is None: + self._window = MainWindow() + return self._window diff --git a/synodic_client/updater.py b/synodic_client/updater.py index 3e3f470..caca249 100644 --- a/synodic_client/updater.py +++ b/synodic_client/updater.py @@ -462,7 +462,7 @@ def _apply_windows_update(self, current_exe: Path, new_exe: Path, backup_path: P if sys.platform == 'win32': # CREATE_NEW_CONSOLE = 0x00000200, DETACHED_PROCESS = 0x00000008 flags = 0x00000200 | 0x00000008 - + subprocess.Popen( ['cmd', '/c', str(script_path)], creationflags=flags,