Skip to content

Commit efb8942

Browse files
committed
feat(runner): direct launch
1 parent ad735ee commit efb8942

2 files changed

Lines changed: 55 additions & 41 deletions

File tree

launcher/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
HTTPS_PROXY = os.environ.get("HTTPS_PROXY", "")
3535
LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "logs")
3636
LAUNCHER_LOG_FILE_PATH = os.path.join(LOG_DIR, "launch_app.log")
37+
DIRECT_LAUNCH = os.environ.get("DIRECT_LAUNCH", False)
3738

3839
# --- WebSocket 端点正则表达式 ---
3940
import re

launcher/runner.py

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SAVED_AUTH_DIR,
2020
determine_proxy_configuration,
2121
parse_args,
22+
DIRECT_LAUNCH
2223
)
2324
from launcher.internal import run_internal_camoufox
2425
from launcher.logging_setup import setup_launcher_logging
@@ -77,7 +78,8 @@ def run(self):
7778

7879
self._check_deprecated_auth_file()
7980
self._determine_launch_mode()
80-
self._handle_auth_file_selection()
81+
if not DIRECT_LAUNCH:
82+
self._handle_auth_file_selection()
8183
self._check_xvfb()
8284
self._check_server_port()
8385

@@ -158,6 +160,12 @@ def _determine_launch_mode(self):
158160
"3" if platform.system() == "Linux" else "1"
159161
)
160162

163+
if DIRECT_LAUNCH:
164+
self.final_launch_mode = (
165+
default_mode_from_env or "headless"
166+
)
167+
return
168+
161169
logger.info("--- 请选择启动模式 (未通过命令行参数指定) ---")
162170
if env_launch_mode and default_mode_from_env:
163171
logger.info(
@@ -443,47 +451,52 @@ def _resolve_auth_file_path(self):
443451
if available_profiles:
444452
# 对可用配置文件列表进行排序,以确保一致的显示顺序
445453
available_profiles.sort(key=lambda x: x["name"])
446-
print("-" * 60 + "\n 找到以下可用的认证文件:", flush=True)
447-
for i, profile in enumerate(available_profiles):
448-
print(f" {i + 1}: {profile['name']}", flush=True)
449-
print(
450-
" N: 不加载任何文件 (使用浏览器当前状态)\n" + "-" * 60,
451-
flush=True,
452-
)
453-
choice = input_with_timeout(
454-
f" 请选择要加载的认证文件编号 (输入 N 或直接回车则不加载, {self.args.auth_save_timeout}s超时): ",
455-
self.args.auth_save_timeout,
456-
)
457-
if choice.strip().lower() not in ["n", ""]:
458-
try:
459-
choice_index = int(choice.strip()) - 1
460-
if 0 <= choice_index < len(available_profiles):
461-
selected_profile = available_profiles[choice_index]
462-
self.effective_active_auth_json_path = selected_profile[
463-
"path"
464-
]
465-
logger.info(
466-
f" 已选择加载认证文件: {selected_profile['name']}"
467-
)
468-
print(
469-
f" 已选择加载: {selected_profile['name']}",
470-
flush=True,
471-
)
472-
else:
473-
logger.info(
474-
" 无效的选择编号或超时。将不加载认证文件。"
475-
)
476-
print(
477-
" 无效的选择编号或超时。将不加载认证文件。",
478-
flush=True,
479-
)
480-
except ValueError:
481-
logger.info(" 无效的输入。将不加载认证文件。")
482-
print(" 无效的输入。将不加载认证文件。", flush=True)
454+
if DIRECT_LAUNCH:
455+
selected_profile = available_profiles[0]
456+
self.effective_active_auth_json_path = selected_profile["path"]
457+
logger.info(f" 直接启动模式:自动选择第一个可用认证文件: {selected_profile['name']}")
483458
else:
484-
logger.info(" 好的,不加载认证文件或超时。")
485-
print(" 好的,不加载认证文件或超时。", flush=True)
486-
print("-" * 60, flush=True)
459+
print("-" * 60 + "\n 找到以下可用的认证文件:", flush=True)
460+
for i, profile in enumerate(available_profiles):
461+
print(f" {i + 1}: {profile['name']}", flush=True)
462+
print(
463+
" N: 不加载任何文件 (使用浏览器当前状态)\n" + "-" * 60,
464+
flush=True,
465+
)
466+
choice = input_with_timeout(
467+
f" 请选择要加载的认证文件编号 (输入 N 或直接回车则不加载, {self.args.auth_save_timeout}s超时): ",
468+
self.args.auth_save_timeout,
469+
)
470+
if choice.strip().lower() not in ["n", ""]:
471+
try:
472+
choice_index = int(choice.strip()) - 1
473+
if 0 <= choice_index < len(available_profiles):
474+
selected_profile = available_profiles[choice_index]
475+
self.effective_active_auth_json_path = selected_profile[
476+
"path"
477+
]
478+
logger.info(
479+
f" 已选择加载认证文件: {selected_profile['name']}"
480+
)
481+
print(
482+
f" 已选择加载: {selected_profile['name']}",
483+
flush=True,
484+
)
485+
else:
486+
logger.info(
487+
" 无效的选择编号或超时。将不加载认证文件。"
488+
)
489+
print(
490+
" 无效的选择编号或超时。将不加载认证文件。",
491+
flush=True,
492+
)
493+
except ValueError:
494+
logger.info(" 无效的输入。将不加载认证文件。")
495+
print(" 无效的输入。将不加载认证文件。", flush=True)
496+
else:
497+
logger.info(" 好的,不加载认证文件或超时。")
498+
print(" 好的,不加载认证文件或超时。", flush=True)
499+
print("-" * 60, flush=True)
487500
else:
488501
logger.info(" 未找到认证文件。将使用浏览器当前状态。")
489502
print(" 未找到认证文件。将使用浏览器当前状态。", flush=True)

0 commit comments

Comments
 (0)