2424APPDATA_PATH = os .path .join (os .environ .get ('APPDATA' ), APP_NAME )
2525ARGUMENTS_FILE_PATH = os .path .join (APPDATA_PATH , "arguments.txt" )
2626
27-
2827process = None
2928SCRIPT_FOR_AUTOSTART = f'"{ sys .executable } "'
3029RUN_KEY = r"Software\Microsoft\Windows\CurrentVersion\Run"
3130
31+
3232def ensure_appdata_structure ():
33- """Ensures the %appdata%\uxplay-windows directory and arguments.txt file exist."""
3433 print (f"Ensuring application data directory: { APPDATA_PATH } " )
3534 os .makedirs (APPDATA_PATH , exist_ok = True )
3635 if not os .path .exists (ARGUMENTS_FILE_PATH ):
3736 print (f"Creating default arguments file: { ARGUMENTS_FILE_PATH } " )
3837 with open (ARGUMENTS_FILE_PATH , 'w' ) as f :
39- f .write ('' ) # Create an empty file, users can add arguments later
38+ f .write ('' ) # Create an empty file, users can add arguments later
4039 print ("Default arguments.txt created." )
4140 else :
4241 print ("arguments.txt already exists." )
4342
43+
4444def get_user_arguments ():
45- """Reads arguments from the arguments.txt file."""
4645 if not os .path .exists (ARGUMENTS_FILE_PATH ):
4746 print (f"Warning: { ARGUMENTS_FILE_PATH } not found. No custom arguments will be used." )
4847 return []
@@ -60,14 +59,15 @@ def get_user_arguments():
6059 print (f"Error reading arguments from { ARGUMENTS_FILE_PATH } : { e } " )
6160 return []
6261
62+
6363def start_server ():
6464 global process
6565 if process and process .poll () is None :
6666 print ("UxPlay server is already running." )
6767 return # already running
6868
6969 print ("Attempting to start UxPlay server..." )
70-
70+
7171 # Get user-defined arguments
7272 user_args = get_user_arguments ()
7373 command = [UXPLAY_PATH ] + user_args
@@ -84,6 +84,7 @@ def start_server():
8484 except Exception as e :
8585 print (f"An error occurred while starting UxPlay: { e } " )
8686
87+
8788def stop_server ():
8889 global process
8990 if process and process .poll () is None :
@@ -103,11 +104,13 @@ def stop_server():
103104 elif process is None :
104105 print ("UxPlay server is not running." )
105106
107+
106108def restart_server (icon , item ):
107109 print ("Restarting UxPlay server..." )
108110 stop_server ()
109111 start_server ()
110112
113+
111114def is_autostart_enabled ():
112115 try :
113116 with winreg .OpenKey (winreg .HKEY_CURRENT_USER , RUN_KEY , 0 , winreg .KEY_READ ) as key :
@@ -119,6 +122,7 @@ def is_autostart_enabled():
119122 print (f"Error checking autostart: { e } " )
120123 return False
121124
125+
122126def enable_autostart ():
123127 try :
124128 with winreg .OpenKey (winreg .HKEY_CURRENT_USER , RUN_KEY , 0 , winreg .KEY_SET_VALUE ) as key :
@@ -127,6 +131,7 @@ def enable_autostart():
127131 except Exception as e :
128132 print (f"Error enabling autostart: { e } " )
129133
134+
130135def disable_autostart ():
131136 try :
132137 with winreg .OpenKey (winreg .HKEY_CURRENT_USER , RUN_KEY , 0 , winreg .KEY_SET_VALUE ) as key :
@@ -137,33 +142,37 @@ def disable_autostart():
137142 except Exception as e :
138143 print (f"Error disabling autostart: { e } " )
139144
145+
140146def toggle_autostart (icon , item ):
141147 if is_autostart_enabled ():
142148 disable_autostart ()
143149 else :
144150 enable_autostart ()
145151
152+
146153def open_arguments_file (icon , item ):
147- """Opens the arguments.txt file in the default text editor."""
148154 if not os .path .exists (ARGUMENTS_FILE_PATH ):
149- ensure_appdata_structure () # Ensure it exists before trying to open
155+ ensure_appdata_structure () # Ensure it exists before trying to open
150156 try :
151- os .startfile (ARGUMENTS_FILE_PATH ) # Windows-specific way to open file with default app
157+ os .startfile (ARGUMENTS_FILE_PATH ) # Windows-specific way to open file with default app
152158 print (f"Opened arguments file: { ARGUMENTS_FILE_PATH } " )
153159 except Exception as e :
154160 print (f"Error opening arguments file: { e } " )
155161 print ("You can manually navigate to:" )
156162 print (APPDATA_PATH )
157163
164+
158165def show_license (icon , item ):
159166 webbrowser .open ('https://github.com/leapbtw/uxplay-windows/blob/main/LICENSE.md' )
160167
168+
161169def exit_tray_icon (icon , item ):
162170 print ("Exiting application..." )
163171 stop_server ()
164172 icon .stop ()
165173 print ("Application exited." )
166174
175+
167176def main ():
168177 # Ensure AppData structure exists before anything else
169178 ensure_appdata_structure ()
@@ -181,7 +190,7 @@ def main():
181190 toggle_autostart ,
182191 checked = lambda item : is_autostart_enabled ()
183192 ),
184- pystray .MenuItem ("Edit UxPlay Arguments" , open_arguments_file ), # New menu item
193+ pystray .MenuItem ("Edit UxPlay Arguments" , open_arguments_file ), # New menu item
185194 pystray .MenuItem ("License" , show_license ),
186195 pystray .MenuItem ("Exit" , exit_tray_icon )
187196 )
@@ -198,5 +207,6 @@ def delayed_start():
198207 tray_icon .run ()
199208 print ("Tray icon stopped." )
200209
210+
201211if __name__ == "__main__" :
202212 main ()
0 commit comments