1+ import multiprocessing
12import os
23import subprocess
34import sys
5+ import threading
46from pathlib import Path
7+ from typing import Optional
58
69import webview
710
@@ -28,14 +31,14 @@ def exists(path):
2831 if path .exists ():
2932 return path
3033
31- queries = ["../gui/index.html " , "../Resources/gui/index.html " , "./gui/index.html " ]
34+ queries = ["../gui" , "../Resources/gui" , "./gui" ]
3235
3336 for query in queries :
3437 result = exists (query )
3538 if result :
3639 return result
3740
38- raise Exception ("No index.html found" )
41+ raise Exception ("No gui directory found" )
3942
4043
4144class Api :
@@ -93,21 +96,74 @@ def check_launch_game(time_limit: float = 0):
9396 return False
9497
9598
99+ def check_queue ():
100+ while True :
101+ if not current_queue :
102+ return
103+ cmd = current_queue .get ()
104+ if cmd == "close" :
105+ close_gui ()
106+ return
107+
108+
96109def on_loaded (window ):
110+ if current_queue :
111+ threading .Thread (target = check_queue ).start ()
112+ if current_entry != "index" :
113+ return
97114 if not check_launch_game (- 1 ):
98115 update_and_notify (window )
99116
100117
101- entry_path = get_entrypoint ()
102- entry = str (entry_path )
103- entry_parent = entry_path .parent
118+ entry_parent = get_entrypoint ()
119+ current_entry : str | None = None
120+ current_queue : Optional [multiprocessing .Queue ] = None
121+
122+
123+ def close_gui ():
124+ window = get_window ()
125+ window .destroy ()
126+
127+
128+ def start_gui_separate (entry_name : str = "index" , ** kwargs ):
129+ q = multiprocessing .Queue ()
130+ p = multiprocessing .Process (
131+ target = _start_gui_private , args = (entry_name , q ), kwargs = kwargs
132+ )
133+ p .start ()
134+ return p , q
135+
136+
137+ def start_gui (entry_name : str = "index" , ** kwargs ):
138+ _start_gui_private (entry_name , ** kwargs )
104139
105140
106- def start_gui ():
141+ def _start_gui_private (
142+ entry_name : str = "index" , queue : Optional [multiprocessing .Queue ] = None , ** kwargs
143+ ):
144+ global current_entry
145+ global current_queue
107146 extra_options = get_launch_options ()
108147 extra_options_str = " " .join (extra_options )
148+ entry = str (entry_parent / f"{ entry_name } .html" )
149+ current_entry = entry_name
150+ current_queue = queue
151+ width = 800
152+ height = 600
153+ min_size = (640 , 360 )
154+ if entry_name == "update" :
155+ width = 400
156+ height = 533
157+ min_size = (400 , 533 )
109158 window = webview .create_window (
110- "Team Comtress Launcher" , entry , js_api = Api (), min_size = (640 , 360 )
159+ "Team Comtress Launcher" ,
160+ entry ,
161+ js_api = Api (),
162+ min_size = min_size ,
163+ width = width ,
164+ height = height ,
165+ background_color = "#212121" ,
166+ ** kwargs ,
111167 )
112168 if window :
113169 window .state .opts = extra_options_str
0 commit comments