@@ -990,28 +990,42 @@ def restart_application(self):
990990 """Restarts the application to apply settings changes."""
991991 import sys
992992 import os
993+ import subprocess
994+ import shutil
993995
994996 log .info ("Restarting application to apply settings changes..." )
995-
996- # Get the current application instance
997997 app = self .window .get_application ()
998998 if app :
999- # Close the current application
1000999 app .quit ()
10011000
1002- # Restart the application
10031001 try :
1004- # Get the original command line arguments
1005- args = sys .argv [:]
1006- log .debug (f"Restarting with args: { args } " )
1002+ clipse_gui_path = shutil .which ("clipse-gui" )
1003+
1004+ if clipse_gui_path :
1005+ args = [clipse_gui_path ] + sys .argv [1 :]
1006+ log .debug (f"Restarting with system executable: { args } " )
1007+ subprocess .Popen (args , cwd = os .getcwd ())
1008+ elif getattr (sys , "frozen" , False ):
1009+ executable = sys .executable
1010+ args = [executable ] + sys .argv [1 :]
1011+ log .debug (f"Restarting with frozen executable: { args } " )
1012+ subprocess .Popen (args , cwd = os .getcwd ())
1013+ else :
1014+ original_cmd = sys .argv [0 ]
1015+ if os .path .isfile (original_cmd ) and os .access (original_cmd , os .X_OK ):
1016+ args = [original_cmd ] + sys .argv [1 :]
1017+ log .debug (f"Restarting with original command: { args } " )
1018+ subprocess .Popen (args , cwd = os .getcwd ())
1019+ else :
1020+ raise Exception (f"Cannot find executable: { original_cmd } " )
10071021
1008- # Use os.execv to replace the current process
1009- os .execv (sys .executable , [sys .executable ] + args )
10101022 except Exception as e :
10111023 log .error (f"Failed to restart application: { e } " )
1012- # Fallback: just quit the application
1013- if app :
1014- app .quit ()
1024+
1025+ if app :
1026+ app .quit ()
1027+ else :
1028+ sys .exit (0 )
10151029
10161030 def on_preview_key_press (self , preview_window , event ):
10171031 """Handles key presses within the preview window."""
@@ -1161,6 +1175,16 @@ def on_key_press(self, widget, event):
11611175 else :
11621176 app = self .window .get_application ()
11631177 if app :
1178+ # Try to minimize to tray if enabled, otherwise quit
1179+ from . import constants
1180+
1181+ if (
1182+ hasattr (app , "tray_manager" )
1183+ and app .tray_manager
1184+ and constants .MINIMIZE_TO_TRAY
1185+ ):
1186+ if app .tray_manager .minimize_to_tray ():
1187+ return True # Successfully minimized to tray
11641188 app .quit ()
11651189 else :
11661190 log .warning ("Application instance is None. Cannot quit." )
@@ -1276,6 +1300,16 @@ def on_key_press(self, widget, event):
12761300 else :
12771301 app = self .window .get_application ()
12781302 if app :
1303+ # Try to minimize to tray if enabled, otherwise quit
1304+ from . import constants
1305+
1306+ if (
1307+ hasattr (app , "tray_manager" )
1308+ and app .tray_manager
1309+ and constants .MINIMIZE_TO_TRAY
1310+ ):
1311+ if app .tray_manager .minimize_to_tray ():
1312+ return True # Successfully minimized to tray
12791313 app .quit ()
12801314 else :
12811315 log .warning ("Application instance is None. Cannot quit." )
0 commit comments