|
19 | 19 | SAVED_AUTH_DIR, |
20 | 20 | determine_proxy_configuration, |
21 | 21 | parse_args, |
| 22 | + DIRECT_LAUNCH |
22 | 23 | ) |
23 | 24 | from launcher.internal import run_internal_camoufox |
24 | 25 | from launcher.logging_setup import setup_launcher_logging |
@@ -77,7 +78,8 @@ def run(self): |
77 | 78 |
|
78 | 79 | self._check_deprecated_auth_file() |
79 | 80 | self._determine_launch_mode() |
80 | | - self._handle_auth_file_selection() |
| 81 | + if not DIRECT_LAUNCH: |
| 82 | + self._handle_auth_file_selection() |
81 | 83 | self._check_xvfb() |
82 | 84 | self._check_server_port() |
83 | 85 |
|
@@ -158,6 +160,12 @@ def _determine_launch_mode(self): |
158 | 160 | "3" if platform.system() == "Linux" else "1" |
159 | 161 | ) |
160 | 162 |
|
| 163 | + if DIRECT_LAUNCH: |
| 164 | + self.final_launch_mode = ( |
| 165 | + default_mode_from_env or "headless" |
| 166 | + ) |
| 167 | + return |
| 168 | + |
161 | 169 | logger.info("--- 请选择启动模式 (未通过命令行参数指定) ---") |
162 | 170 | if env_launch_mode and default_mode_from_env: |
163 | 171 | logger.info( |
@@ -443,47 +451,52 @@ def _resolve_auth_file_path(self): |
443 | 451 | if available_profiles: |
444 | 452 | # 对可用配置文件列表进行排序,以确保一致的显示顺序 |
445 | 453 | 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']}") |
483 | 458 | 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) |
487 | 500 | else: |
488 | 501 | logger.info(" 未找到认证文件。将使用浏览器当前状态。") |
489 | 502 | print(" 未找到认证文件。将使用浏览器当前状态。", flush=True) |
|
0 commit comments