diff --git a/runtime.py b/runtime.py index 50b471f..a664d4d 100644 --- a/runtime.py +++ b/runtime.py @@ -242,7 +242,17 @@ def launch_and_prepare(debug_mode=False, debug_target=""): state_store.init_db() seed_legacy_config() - # 1. 安能 Electron 应用路径(state.db,前端站点配置;seed 已灌入) + # 1. 读 debug 配置(config.yaml;服务模式也生效)+ 安能路径(state.db,seed 已灌入) + if os.path.exists(CONFIG_PATH): + try: + with open(CONFIG_PATH, "r", encoding="utf-8") as f: + _cfg = yaml.safe_load(f) or {} + _dbg = _cfg.get("debug", {}) or {} + if _dbg.get("enabled"): + debug_mode = True + debug_target = str(_dbg.get("target_site", "") or "") + except Exception as e: + print(f"⚠️ 读取 config.yaml(debug) 失败: {e}") anneng_app_path = state_store.get_setting("安能", "app_path") # 2. 确定要挂载的网页站点 + 安能标记 @@ -366,7 +376,7 @@ def launch_and_prepare(debug_mode=False, debug_target=""): def _dismiss_initial_popups(pages_map): - """顺心 / 百世 初始弹窗清理。""" + """顺心 / 百世 / 韵达 初始弹窗清理。""" if "顺心" in pages_map: for acct, sx_page in enumerate(pages_map["顺心"], start=1): try: @@ -410,6 +420,14 @@ def _dismiss_initial_popups(pages_map): print(" ✅ 【百世】初始弹窗处理完成。") except Exception: pass + if "韵达" in pages_map: + try: + yd_page = pages_map["韵达"] + yd_page.bring_to_front() + print(">> 正在检查【韵达】音频设备授权提示...") + site_yunda.dismiss_audio_prompt(yd_page) + except Exception: + pass # ============================ 任务派发 ============================ diff --git a/site_yunda.py b/site_yunda.py index 8ba848b..5d451d7 100644 --- a/site_yunda.py +++ b/site_yunda.py @@ -45,10 +45,25 @@ def with_retry(site_name, label, flow, reset, max_attempts=3): HOME_URL = "https://ky-sso.yunda56.com" +def dismiss_audio_prompt(page): + """关闭韵达「音频设备未授权」提示弹窗(点确定);未出现则跳过。 + + 该弹窗在主页(含重试重载后)会重复出现,故需在每次主页加载后清理。""" + try: + modal = page.locator(".ivu-modal-confirm", has_text="音频设备未授权").first + modal.wait_for(state="visible", timeout=2000) + modal.locator(".ivu-modal-confirm-footer button.ivu-btn-primary").click() + print(" ✅ 【韵达】已关闭音频设备授权提示。") + return True + except Exception: + return False + + def yunda_reset(page): """异常兜底:重置韵达到初始态(跳首页 URL,丢弃当前页面状态,登录态保留)。""" page.goto(HOME_URL) page.wait_for_timeout(1500) + dismiss_audio_prompt(page) # 主页重载后音频授权提示会复现,清理之 def _remove_if_exists(path):