77import winreg
88import psutil
99import shutil
10- from typing import Union , Dict , SupportsInt , AnyStr , Tuple
1110import ctypes
1211
1312from pathlib import Path
1413from pynput import keyboard
14+ from typing import Union , Dict , SupportsInt , AnyStr , Tuple
1515
1616import reschanger
1717
@@ -106,9 +106,17 @@ async def srr_loop(time_step, prss: ScreenSettings, psss: ScreenSettings):
106106 last_state = current_state
107107
108108
109+ def is_app_running (app_name ):
110+ processes = psutil .process_iter ()
111+ for process in processes :
112+ if process .name () == app_name :
113+ return True
114+
115+
109116def load_config () -> Tuple [ScreenSettings , ScreenSettings ]:
110117 with open (PATH_TO_PROGRAM / "config.json" , "r" ) as config :
111118 stream = config .read ()
119+
112120 params = json .JSONDecoder ().decode (stream )
113121
114122 powersave_dict = params ["powersave-state" ]
@@ -121,7 +129,7 @@ def load_config() -> Tuple[ScreenSettings, ScreenSettings]:
121129
122130
123131async def main ():
124- print (sys .argv )
132+ # print(sys.argv) # debug info
125133 if not Path .exists (PATH_TO_PROGRAM ) and PATH_CURRENT_FILE .suffix == ".exe" :
126134 PATH_TO_PROGRAM .mkdir (parents = True , exist_ok = True )
127135 shutil .copy (PATH_CURRENT_FILE , PATH_TO_PROGRAM / "SRR.exe" )
@@ -139,6 +147,14 @@ async def main():
139147 params = cur_monitor_specs ()
140148 json .dump (params , config , indent = 4 )
141149
150+ if PATH_BASE_DIR != PATH_TO_PROGRAM :
151+ if not is_app_running ("SRR.exe" ):
152+ os .startfile (PATH_TO_PROGRAM / "SRR.exe" )
153+ else :
154+ ctypes .windll .user32 .MessageBoxW (None , "Another instance of SRR is already running." ,
155+ "Warning" , 0 )
156+ os ._exit (- 1 )
157+
142158 powersave_state , performance_state = load_config ()
143159
144160 try :
0 commit comments