Skip to content

Commit 687bfdf

Browse files
committed
just check once on startup for running
1 parent 52fe898 commit 687bfdf

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

tc2_launcher/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from tc2_launcher.gui import start_gui
1010
from tc2_launcher.run import (
11+
DEV_INSTANCE,
1112
clean_self_update,
1213
default_dest_dir,
1314
launch_game,
@@ -53,7 +54,7 @@ def main():
5354

5455
launch_gui = len(sys.argv) == 3
5556
else:
56-
if update_self(version):
57+
if not DEV_INSTANCE and update_self(version):
5758
sys.exit(0)
5859
return
5960

tc2_launcher/gui.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import webview
77

88
from tc2_launcher.run import (
9+
DEV_INSTANCE,
910
change_install_folder,
1011
get_launch_options,
1112
launch_game,
@@ -80,8 +81,8 @@ def on_game_exit():
8081
update_and_notify(window)
8182

8283

83-
def check_launch_game():
84-
pid = wait_game_running()
84+
def check_launch_game(time_limit: float = 0):
85+
pid = wait_game_running(time_limit)
8586
has_pid = pid is not None
8687
res = 2 if has_pid else 0
8788
get_window().evaluate_js(f"setLaunchState({res});")
@@ -93,11 +94,10 @@ def check_launch_game():
9394

9495

9596
def on_loaded(window):
96-
if not check_launch_game():
97+
if not check_launch_game(-1):
9798
update_and_notify(window)
9899

99100

100-
debug = not getattr(sys, "frozen", False)
101101
entry_path = get_entrypoint()
102102
entry = str(entry_path)
103103
entry_parent = entry_path.parent
@@ -113,7 +113,7 @@ def start_gui():
113113
window.state.opts = extra_options_str
114114
window.events.loaded += lambda: on_loaded(window)
115115
try:
116-
webview.start(icon=str(entry_parent / "favicon.ico"), debug=debug)
116+
webview.start(icon=str(entry_parent / "favicon.ico"), debug=DEV_INSTANCE)
117117
except Exception as e:
118118
if os.name == "posix" and sys.platform != "darwin":
119119
subprocess.run(

tc2_launcher/run.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
TC2_REPO = "mastercomfig/tc2"
1818
LAUNCHER_REPO = "mastercomfig/tc2-launcher"
1919

20+
DEV_INSTANCE = not getattr(sys, "frozen", False)
21+
2022

2123
def default_dest_dir() -> Path:
2224
if sys.platform == "darwin":
@@ -414,15 +416,24 @@ def wait_game_exit(pid, callback):
414416
wait_game_exit_thread.start()
415417

416418

417-
def wait_game_running() -> int | None:
419+
DEFAULT_TIME_LIMIT = 5
420+
421+
422+
def wait_game_running(time_limit: float = DEFAULT_TIME_LIMIT) -> int | None:
418423
game_exe_name = _get_game_exe_name(running_process=True)
419-
time_limit = 5
424+
interval = 0.2
425+
if time_limit == 0:
426+
time_limit = DEFAULT_TIME_LIMIT
427+
elif time_limit < 0:
428+
time_limit = interval
420429
while time_limit > 0:
421430
for p in psutil.process_iter(["pid", "name"]):
422431
if p.info["name"] == game_exe_name:
423432
return p.pid
433+
if time_limit <= interval:
434+
break
424435
before = timer()
425-
sleep(0.2)
436+
sleep(interval)
426437
time_limit -= timer() - before
427438
return None
428439

0 commit comments

Comments
 (0)