-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathapp_launcher.py
More file actions
78 lines (65 loc) · 2.39 KB
/
app_launcher.py
File metadata and controls
78 lines (65 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import sys
import time
import subprocess
import threading
import logging
import uvicorn
import webbrowser
try:
from .manager import app
except ImportError:
from manager import app
# Configuration
PORT = 9000
HOST = os.environ.get("MANAGER_HOST", "127.0.0.1")
DASHBOARD_URL = f"http://{HOST}:{PORT}"
def open_dashboard_window():
"""
Attempts to open the dashboard in a dedicated 'App' window using Edge or Chrome.
Falls back to default system browser.
"""
time.sleep(2) # Give server a moment to start
print(f"Opening dashboard at {DASHBOARD_URL}")
if sys.platform == "win32":
# Try to find standard paths for Edge and Chrome
paths = [
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
r"C:\Program Files\Microsoft\Edge\Application\msedge.exe",
r"C:\Program Files\Google\Chrome\Application\chrome.exe",
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
]
for path in paths:
if os.path.exists(path):
try:
subprocess.Popen([path, f"--app={DASHBOARD_URL}"])
print(f"Launched App Mode using: {path}")
return
except Exception as e:
print(f"Failed to launch {path}: {e}")
# Fallback to standard browser opening
print("Browser executable for App Mode not found, opening in default browser...")
webbrowser.open(DASHBOARD_URL)
def main():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
print("--- AI Studio Proxy Manager ---")
print(f"Starting Manager Backend on {DASHBOARD_URL}...")
# Launch browser in a separate thread (unless disabled)
if os.environ.get("NO_BROWSER_AUTO_OPEN", "").lower() not in ("true", "1", "yes"):
threading.Thread(target=open_dashboard_window, daemon=True).start()
else:
print("Browser auto-open disabled by environment variable.")
# Run server
try:
uvicorn.run(app, host=HOST, port=PORT, log_level="error")
except KeyboardInterrupt:
print("\nStopping...")
except Exception as e:
print(f"\nError starting server: {e}")
# input("Press Enter to exit...") # CLI模式下通常不阻塞退出
if __name__ == "__main__":
main()
input("Press Enter to exit...")