Skip to content

Commit f97a90c

Browse files
committed
Prettied code <3:
- Made program more user-friendly - Small bug fixes - Made test.bat more efficient
1 parent b1958f4 commit f97a90c

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

main.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import winreg
88
import psutil
99
import shutil
10-
from typing import Union, Dict, SupportsInt, AnyStr, Tuple
1110
import ctypes
1211

1312
from pathlib import Path
1413
from pynput import keyboard
14+
from typing import Union, Dict, SupportsInt, AnyStr, Tuple
1515

1616
import 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+
109116
def 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

123131
async 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:

test.bat

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@echo off
2+
rmdir /s /q %localappdata%\SRR
23
python -m venv .venv
34
.\.venv\Scripts\pip3.exe install -r requirements.txt
4-
.\.venv\Scripts\pyinstaller.exe -n SRR -F --clean main.py
5-
.\dist\SRR.exe
5+
.\.venv\Scripts\pyinstaller.exe -n SRR-test -F --clean main.py
6+
.\dist\SRR-test.exe

0 commit comments

Comments
 (0)