diff --git a/gui/dashboard_app/app.py b/gui/dashboard_app/app.py index 5009431..579d4e8 100644 --- a/gui/dashboard_app/app.py +++ b/gui/dashboard_app/app.py @@ -77,6 +77,7 @@ class DashboardApp: self.ocr_results: list = [] self._scan_busy = {"flag": False} self.nav_buttons: dict[str, tk.Widget] = {} + self._startup_progress: tk.Toplevel | None = None self._build_shell() self.status_var.trace_add("write", lambda *_: self._sync_status_pill()) @@ -444,13 +445,95 @@ class DashboardApp: if self.runner.is_running(): self.status_var.set("已在运行中") return + progress = self._show_startup_progress() try: + self._update_startup_progress(progress, 12, "保存配置", "正在写入当前界面参数") self.save_config() - self.runner.start(self._params()) + self._update_startup_progress(progress, 38, "解析设备", "正在确认 ADB 与目标设备") + params = self._params() + self._update_startup_progress(progress, 68, "启动主进程", "正在加载运行核心") + self.root.update_idletasks() + self.runner.start(params) + self._update_startup_progress(progress, 90, "等待运行日志", "主进程已启动,正在等待初始化输出") self.status_var.set("运行中") - self.refresh_data() + self.data = load_dashboard_data() except Exception as exc: + self._close_startup_progress(progress) self.status_var.set(f"启动失败:{exc}") + return + self.root.after(600, lambda: self._finish_startup_progress(progress)) + + def _show_startup_progress(self) -> tk.Toplevel: + win = tk.Toplevel(self.root) + win.title("启动运行") + win.transient(self.root) + win.resizable(False, False) + win.configure(bg=theme.BG) + win.protocol("WM_DELETE_WINDOW", lambda: None) + frame = tk.Frame(win, bg=theme.BG, padx=24, pady=22) + frame.pack(fill="both", expand=True) + card = rounded_surface(frame, fill=theme.SURFACE, outline=theme.BORDER, radius=theme.RADIUS_MD) + card.pack(fill="both", expand=True) + inner = tk.Frame(card, bg=theme.SURFACE, padx=24, pady=21) + inner.pack(fill="both", expand=True) + tk.Label(inner, text="正在初始化运行", bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 18, "bold")).pack(anchor="w") + stage = tk.Label(inner, text="准备中", bg=theme.SURFACE, fg=theme.TEXT, font=("Microsoft YaHei UI", 14, "bold")) + stage.pack(anchor="w", pady=(17, 4)) + detail = tk.Label(inner, text="正在准备启动环境", bg=theme.SURFACE, fg=theme.MUTED, font=theme.FONT_SMALL) + detail.pack(anchor="w", pady=(0, 13)) + pct = tk.Label(inner, text="0%", bg=theme.SURFACE, fg=theme.TEAL_DARK, font=("Microsoft YaHei UI", 20, "bold")) + pct.pack(anchor="e") + bar = ttk.Progressbar(inner, mode="determinate", length=420, maximum=100) + bar.pack(fill="x", pady=(3, 4), ipady=3) + win._startup_labels = {"stage": stage, "detail": detail, "pct": pct, "bar": bar} # type: ignore[attr-defined] + self._update_startup_progress(win, 5, "准备中", "正在准备启动环境") + try: + win.update_idletasks() + x = self.root.winfo_rootx() + (self.root.winfo_width() - win.winfo_width()) // 2 + y = self.root.winfo_rooty() + (self.root.winfo_height() - win.winfo_height()) // 2 + win.geometry(f"+{max(0, x)}+{max(0, y)}") + win.grab_set() + except Exception: + pass + self._startup_progress = win + return win + + def _update_startup_progress(self, progress: tk.Toplevel, percent: int, stage: str, detail: str) -> None: + labels = getattr(progress, "_startup_labels", None) + if not labels: + return + value = max(0, min(100, int(percent))) + labels["stage"].configure(text=stage) + labels["detail"].configure(text=detail) + labels["pct"].configure(text=f"{value}%") + labels["bar"].configure(value=value) + try: + progress.update_idletasks() + except Exception: + pass + + def _close_startup_progress(self, progress: tk.Toplevel | None) -> None: + if progress is None: + return + try: + progress.grab_release() + except Exception: + pass + try: + progress.destroy() + except Exception: + pass + if self._startup_progress is progress: + self._startup_progress = None + + def _finish_startup_progress(self, progress: tk.Toplevel | None) -> None: + if progress is None: + return + try: + self._update_startup_progress(progress, 100, "启动完成", "运行进程已开始") + except Exception: + pass + self._close_startup_progress(progress) def stop_run(self) -> None: self.runner.stop() diff --git a/gui/dashboard_app/page_data.py b/gui/dashboard_app/page_data.py index 5674cea..3d332f8 100644 --- a/gui/dashboard_app/page_data.py +++ b/gui/dashboard_app/page_data.py @@ -2,8 +2,11 @@ from __future__ import annotations import re import tkinter as tk +from pathlib import Path from tkinter import ttk +from douyin.core import path_config + from . import theme from .data import DashboardData, fmt_ts, load_dashboard_data from .page_context import PageContext @@ -189,7 +192,13 @@ def build_run_log(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> Non def build_preview(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: section(parent, "截图预览", "选择图片 / 打开pic目录 / 刷新预览") toolbar(parent, [("刷新预览", ctx.action("refresh"), "soft"), ("截图+OCR", ctx.action("screenshot_ocr"), "primary"), "打开pic目录"]) - preview_panel(parent, data.current_screenshot_path, "当前截图").pack(fill="both", expand=True) + preview_panel( + parent, + data.current_screenshot_path, + "当前截图", + auto_refresh_ms=1000, + path_getter=lambda: Path(path_config.get_screenshot_path()), + ).pack(fill="both", expand=True) RESERVATION_COLUMNS = ( @@ -379,7 +388,13 @@ def build_realtime(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> No body = tk.Frame(parent, bg=theme.BG) body.pack(fill="both", expand=True) text_panel(body, "动作流", data.action_log[-120:], height=16).pack(fill="both", expand=True, pady=(0, 12)) - preview_panel(body, data.current_screenshot_path, "实时截图").pack(fill="both", expand=True) + preview_panel( + body, + data.current_screenshot_path, + "实时截图", + auto_refresh_ms=1000, + path_getter=lambda: Path(path_config.get_screenshot_path()), + ).pack(fill="both", expand=True) def build_ocr(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: diff --git a/gui/dashboard_app/page_home.py b/gui/dashboard_app/page_home.py index b99aab0..ba4697d 100644 --- a/gui/dashboard_app/page_home.py +++ b/gui/dashboard_app/page_home.py @@ -4,9 +4,12 @@ import re import tkinter as tk import time from datetime import datetime +from pathlib import Path from threading import RLock from typing import Any +from douyin.core import path_config + from . import theme from .data import DashboardData, fmt_ts, load_dashboard_data from .page_data import HOME_RESERVATION_COLUMNS, _reservation_rows_for_display, reservation_auto_refresh_control @@ -216,7 +219,14 @@ def build_home(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> None: include_created=False, ).pack(side="left") - preview_panel(right, data.current_screenshot_path, "实时截图", max_size=(430, 620)).pack(fill="both", expand=True) + preview_panel( + right, + data.current_screenshot_path, + "实时截图", + max_size=(430, 620), + auto_refresh_ms=1000, + path_getter=lambda: Path(path_config.get_screenshot_path()), + ).pack(fill="both", expand=True) def _statistics_values(data: DashboardData, ctx: PageContext) -> tuple[dict[str, Any], str, str]: diff --git a/gui/dashboard_app/widgets.py b/gui/dashboard_app/widgets.py index 958dc09..52b0342 100644 --- a/gui/dashboard_app/widgets.py +++ b/gui/dashboard_app/widgets.py @@ -644,25 +644,75 @@ def toolbar(parent, actions: Sequence[tuple[str, Callable[[], None] | None, str] return row -def preview_panel(parent, image_path: Path | None, title: str = "截图预览", max_size: tuple[int, int] = (360, 560)) -> tk.Frame: +def _preview_signature(image_path: Path | None) -> tuple[str, int, int] | None: + try: + if not image_path or not image_path.exists(): + return None + st = image_path.stat() + return (str(image_path), int(getattr(st, "st_mtime_ns", int(st.st_mtime * 1_000_000_000))), int(st.st_size)) + except Exception: + return None + + +def preview_panel( + parent, + image_path: Path | None, + title: str = "截图预览", + max_size: tuple[int, int] = (360, 560), + *, + auto_refresh_ms: int = 0, + path_getter: Callable[[], Path | None] | None = None, +) -> tk.Frame: box = card(parent, title) body = tk.Frame(box, bg=theme.SURFACE_ALT, highlightbackground=theme.BORDER, highlightthickness=1) body.pack(fill="both", expand=True, padx=16, pady=(4, 16)) - if image_path and image_path.exists(): - try: - from PIL import Image, ImageTk + box._preview_signature = object() # type: ignore[attr-defined] - img = Image.open(image_path).convert("RGB") - img.thumbnail(max_size) - photo = ImageTk.PhotoImage(img) - label = tk.Label(body, image=photo, bg=theme.SURFACE_ALT) - label.image = photo - label.pack(expand=True, pady=12) - ttk.Label(body, text=os.path.basename(str(image_path)), background=theme.SURFACE_ALT, foreground=theme.MUTED).pack(pady=(0, 8)) - return box + def _render(path: Path | None, signature: tuple[str, int, int] | None) -> None: + box._preview_signature = signature # type: ignore[attr-defined] + for child in body.winfo_children(): + child.destroy() + if path and path.exists(): + try: + from PIL import Image, ImageTk + + img = Image.open(path).convert("RGB") + img.thumbnail(max_size) + photo = ImageTk.PhotoImage(img) + label = tk.Label(body, image=photo, bg=theme.SURFACE_ALT) + label.image = photo + label.pack(expand=True, pady=12) + ttk.Label(body, text=os.path.basename(str(path)), background=theme.SURFACE_ALT, foreground=theme.MUTED).pack(pady=(0, 8)) + return + except Exception: + pass + tk.Label(body, text="暂无截图\n点击“截图+OCR”后刷新", bg=theme.SURFACE_ALT, fg=theme.MUTED, font=("Microsoft YaHei UI", 13)).pack(expand=True) + + def _current_path() -> Path | None: + if path_getter is not None: + try: + return path_getter() + except Exception: + return image_path + return image_path + + def _refresh() -> None: + try: + if not box.winfo_exists(): + return except Exception: - pass - tk.Label(body, text="暂无截图\n点击“截图+OCR”后刷新", bg=theme.SURFACE_ALT, fg=theme.MUTED, font=("Microsoft YaHei UI", 13)).pack(expand=True) + return + path = _current_path() + signature = _preview_signature(path) + if signature != getattr(box, "_preview_signature", None): + _render(path, signature) + if auto_refresh_ms > 0: + try: + box.after(auto_refresh_ms, _refresh) + except Exception: + pass + + _refresh() return box diff --git a/packaging/README.md b/packaging/README.md index cbc8a4b..0bfbcf2 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -71,9 +71,18 @@ dist\DouyinGuaji-\ - `assets/`、`webui/`、`config/`:运行所需资源 - `platform-tools/`:随包 ADB 运行组件,至少包含 `adb.exe`、`AdbWinApi.dll`、`AdbWinUsbApi.dll` - `android-tools/`:随包手机侧辅助组件,当前包含 `ADBKeyboard.apk` +- `drivers/HiSuite/`:默认不随包;仅在显式传入华为/荣耀 HiSuite 官方安装器时复制 - `logs/`、`pic/`、`state/`:运行时输出目录 - `license.dat`:默认不随包分发;仅本地测试包需要时才使用 `-IncludeLicense` 显式复制 +华为/荣耀手机如果在新电脑上 MTP 或 ADB 识别异常,可先从华为官方页面下载 HiSuite 安装器,再在打包时显式带入: + +```powershell +powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -HiSuiteInstallerPath "C:\path\to\HiSuite.exe" +``` + +该参数只把安装器放入 `drivers\HiSuite\` 方便目标电脑手动安装,不会静默安装第三方驱动。 + 测试包如需临时带入本地 `license.dat`: ```powershell diff --git a/packaging/pyinstaller/build_windows.ps1 b/packaging/pyinstaller/build_windows.ps1 index 786181f..9d10537 100644 --- a/packaging/pyinstaller/build_windows.ps1 +++ b/packaging/pyinstaller/build_windows.ps1 @@ -9,6 +9,7 @@ param( [switch]$IncludeLicense, [switch]$ReuseCache, [string]$PlatformToolsDir = "", + [string]$HiSuiteInstallerPath = "", [string]$UpxDir = "" ) @@ -264,6 +265,26 @@ if (-not (Test-Path $AdbKeyboardApk)) { } Copy-Item -LiteralPath $AdbKeyboardApk -Destination (Join-Path $AndroidToolsTarget "ADBKeyboard.apk") -Force +if ($HiSuiteInstallerPath) { + if (-not (Test-Path -LiteralPath $HiSuiteInstallerPath)) { + throw "HiSuite installer not found: $HiSuiteInstallerPath" + } + $DriverTarget = Join-Path $DistRoot "drivers\HiSuite" + if (Test-Path $DriverTarget) { + Remove-Item -LiteralPath $DriverTarget -Recurse -Force + } + New-Item -ItemType Directory -Force $DriverTarget | Out-Null + $installerItem = Get-Item -LiteralPath $HiSuiteInstallerPath + Copy-Item -LiteralPath $installerItem.FullName -Destination (Join-Path $DriverTarget $installerItem.Name) -Force + @" +Huawei / Honor USB driver helper + +If Windows cannot show the phone as MTP or ADB is unstable, install HiSuite on the computer, reconnect the phone, choose File Transfer / MTP on the phone, and allow USB debugging authorization. + +This third-party installer is provided only when explicitly passed to the build script. +"@ | Set-Content -LiteralPath (Join-Path $DriverTarget "README.txt") -Encoding UTF8 +} + $licensePath = Join-Path $Root "license.dat" if ($IncludeLicense -and (Test-Path $licensePath)) { Copy-Item -LiteralPath $licensePath -Destination (Join-Path $DistRoot "license.dat") -Force diff --git a/tests/test_distribution_manifest.py b/tests/test_distribution_manifest.py index aaf7a6a..1fb080b 100644 --- a/tests/test_distribution_manifest.py +++ b/tests/test_distribution_manifest.py @@ -133,6 +133,24 @@ def test_distribution_manifest_blocks_unexpected_platform_tools_files(): assert "platform-tools/mke2fs.conf" in blocked +def test_distribution_manifest_allows_explicit_hisuite_driver_bundle_only(): + from tools.distribution_manifest import find_forbidden_distribution_entries + + entries = [ + "drivers/HiSuite/HiSuite_Installer.exe", + "drivers/HiSuite/README.txt", + "drivers/HiSuite/debug.log", + "drivers/OtherDriver/setup.exe", + ] + + blocked = find_forbidden_distribution_entries(entries) + + assert "drivers/HiSuite/HiSuite_Installer.exe" not in blocked + assert "drivers/HiSuite/README.txt" not in blocked + assert "drivers/HiSuite/debug.log" in blocked + assert "drivers/OtherDriver/setup.exe" in blocked + + def test_distribution_manifest_can_allow_license_for_local_test_package(): from tools.distribution_manifest import find_distribution_issues diff --git a/tools/distribution_manifest.py b/tools/distribution_manifest.py index 3e755b6..ab41ce9 100644 --- a/tools/distribution_manifest.py +++ b/tools/distribution_manifest.py @@ -94,6 +94,16 @@ ALLOWED_ANDROID_TOOLS_FILES = { "android-tools/adbkeyboard.apk", } +ALLOWED_DRIVER_PREFIXES = ( + "drivers/hisuite/", +) + +ALLOWED_DRIVER_SUFFIXES = { + ".exe", + ".msi", + ".txt", +} + ALLOWED_CONFIG_FILES = { "config/readme.md", "config/config.json", @@ -177,6 +187,10 @@ def is_forbidden_distribution_entry(entry: str, *, allow_license: bool = False) return lower not in ALLOWED_PLATFORM_TOOLS_FILES if lower.startswith("android-tools/"): return lower not in ALLOWED_ANDROID_TOOLS_FILES + if any(lower.startswith(prefix) for prefix in ALLOWED_DRIVER_PREFIXES): + return Path(lower).suffix not in ALLOWED_DRIVER_SUFFIXES + if lower.startswith("drivers/"): + return True if lower.startswith("config/"): return lower not in ALLOWED_CONFIG_FILES if any(lower.startswith(prefix.lower()) for prefix in FORBIDDEN_PREFIXES):