1717
1818Keys = keyboard .Key
1919last_btn : Keys
20+
21+ # constants
2022TIME_STEP = 1 # seconds
2123STARTUP_SWITCH = True
2224
25+ PROJECT_NAME = "SRR"
26+ PROJECT_EXECUTABLE = PROJECT_NAME + ".exe"
27+
2328PATH_APPDATA_LOCAL = Path (os .getenv ("LOCALAPPDATA" )).resolve ()
24- PATH_TO_PROGRAM = PATH_APPDATA_LOCAL / "SRR"
29+ PATH_TO_PROGRAM = PATH_APPDATA_LOCAL / PROJECT_NAME
2530PATH_CURRENT_FILE = Path (sys .argv [0 ]).resolve ()
2631PATH_BASE_DIR = PATH_CURRENT_FILE .parent
2732
@@ -36,7 +41,11 @@ class ScreenSettings:
3641def write_logs (e : Union [Exception , BaseException ]):
3742 def write (exception : Union [Exception , BaseException ], method : str = 'a' ):
3843 with open ((PATH_TO_PROGRAM / "log.txt" ), method , encoding = 'utf-8' ) as log :
39- log .write (f'{ datetime .datetime .today ()} \n { repr (exception )} \n { reschanger .get_resolution ()} \n ' )
44+ log .write (f'{ datetime .datetime .today ()} \n { repr (exception )} \n '
45+ f'Your, current screen specs (width, height, refresh rate(min/max)): { reschanger .get_resolution ()} \n ' )
46+ ctypes .windll .user32 .MessageBoxW (
47+ None , f"The SRR program terminated with the following error:\n { str (e )} " , "Error" , 0
48+ )
4049
4150 try :
4251 write (e , 'a' )
@@ -109,7 +118,7 @@ async def srr_loop(time_step, prss: ScreenSettings, psss: ScreenSettings):
109118def is_app_running (app_name ):
110119 processes = psutil .process_iter ()
111120 for process in processes :
112- if process .name () == app_name :
121+ if process .name () == app_name and process . exe () == PATH_TO_PROGRAM / PROJECT_EXECUTABLE :
113122 return True
114123
115124
@@ -132,19 +141,19 @@ async def main():
132141 # print(sys.argv) # debug info
133142 if not Path .exists (PATH_TO_PROGRAM ) and PATH_CURRENT_FILE .suffix == ".exe" :
134143 PATH_TO_PROGRAM .mkdir (parents = True , exist_ok = True )
135- shutil .copy (PATH_CURRENT_FILE , PATH_TO_PROGRAM / "SRR.exe" )
144+ shutil .copy (PATH_CURRENT_FILE , PATH_TO_PROGRAM / PROJECT_EXECUTABLE )
136145
137146 key = winreg .OpenKey (
138147 winreg .HKEY_LOCAL_MACHINE ,
139148 "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" ,
140149 0 , winreg .KEY_SET_VALUE
141150 )
142- winreg .SetValueEx (key , "SRR" , 0 , winreg .REG_SZ , str (PATH_TO_PROGRAM / "SRR.exe" ))
151+ winreg .SetValueEx (key , PROJECT_NAME , 0 , winreg .REG_SZ , str (PATH_TO_PROGRAM / PROJECT_EXECUTABLE ))
143152 winreg .CloseKey (key )
144153
145154 if PATH_BASE_DIR != PATH_TO_PROGRAM :
146- if not is_app_running ("SRR.exe" ):
147- os .startfile (PATH_TO_PROGRAM / "SRR.exe" )
155+ if not is_app_running (PROJECT_EXECUTABLE ):
156+ os .startfile (PATH_TO_PROGRAM / PROJECT_EXECUTABLE )
148157 else :
149158 ctypes .windll .user32 .MessageBoxW (
150159 None , "Another instance of SRR is already running." , "Warning" , 0
@@ -163,9 +172,6 @@ async def main():
163172 await switch_rate (cur_power_state (), performance_state , powersave_state )
164173 await srr_loop (TIME_STEP , performance_state , powersave_state )
165174 except Exception as e :
166- ctypes .windll .user32 .MessageBoxW (
167- None , f"The SRR program terminated with the following error:\n { repr (e )} " , "Error" , 0
168- )
169175 write_logs (e )
170176
171177
0 commit comments