feat: add --no-tg flag to launch.pyw for multi-machine sync
This commit is contained in:
24
launch.pyw
24
launch.pyw
@@ -17,7 +17,7 @@ def get_screen_width():
|
|||||||
except: return 1920
|
except: return 1920
|
||||||
|
|
||||||
def start_streamlit(port):
|
def start_streamlit(port):
|
||||||
global proc, tgproc
|
global proc
|
||||||
cmd = [
|
cmd = [
|
||||||
sys.executable, "-m", "streamlit", "run", "stapp.py",
|
sys.executable, "-m", "streamlit", "run", "stapp.py",
|
||||||
"--server.port", str(port),
|
"--server.port", str(port),
|
||||||
@@ -26,8 +26,7 @@ def start_streamlit(port):
|
|||||||
]
|
]
|
||||||
proc = subprocess.Popen(cmd)
|
proc = subprocess.Popen(cmd)
|
||||||
atexit.register(proc.kill)
|
atexit.register(proc.kill)
|
||||||
tgproc = subprocess.Popen([sys.executable, "tgapp.py"], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(tgproc.kill)
|
|
||||||
|
|
||||||
def inject(text):
|
def inject(text):
|
||||||
window.evaluate_js(f"""
|
window.evaluate_js(f"""
|
||||||
@@ -76,10 +75,21 @@ def idle_monitor():
|
|||||||
print(f'[Idle Monitor] Error: {e}')
|
print(f'[Idle Monitor] Error: {e}')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
port = sys.argv[1] if len(sys.argv) > 1 else "8501"
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('port', nargs='?', default='8501')
|
||||||
|
parser.add_argument('--no-tg', action='store_true', help='不启动 Telegram Bot')
|
||||||
|
args = parser.parse_args()
|
||||||
|
port = args.port
|
||||||
t = threading.Thread(target=start_streamlit, args=(port,), daemon=True)
|
t = threading.Thread(target=start_streamlit, args=(port,), daemon=True)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
if not args.no_tg:
|
||||||
|
tgproc = subprocess.Popen([sys.executable, "tgapp.py"], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
|
atexit.register(tgproc.kill)
|
||||||
|
print('[Launch] Telegram Bot started')
|
||||||
|
else: print('[Launch] Telegram Bot disabled (--no-tg)')
|
||||||
|
|
||||||
monitor_thread = threading.Thread(target=idle_monitor, daemon=True)
|
monitor_thread = threading.Thread(target=idle_monitor, daemon=True)
|
||||||
monitor_thread.start()
|
monitor_thread.start()
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
@@ -90,10 +100,8 @@ if __name__ == '__main__':
|
|||||||
window = webview.create_window(
|
window = webview.create_window(
|
||||||
title='GenericAgent',
|
title='GenericAgent',
|
||||||
url=f'http://localhost:{port}',
|
url=f'http://localhost:{port}',
|
||||||
width=WINDOW_WIDTH,
|
width=WINDOW_WIDTH, height=WINDOW_HEIGHT,
|
||||||
height=WINDOW_HEIGHT,
|
|
||||||
x=x_pos, y=TOP_PADDING,
|
x=x_pos, y=TOP_PADDING,
|
||||||
resizable=True,
|
resizable=True, text_select=True
|
||||||
text_select=True
|
|
||||||
)
|
)
|
||||||
webview.start()
|
webview.start()
|
||||||
Reference in New Issue
Block a user