This commit is contained in:
1 parent
16019ee649
commit
329b7756f4
17 files changed
+754
-85
No files matched your search
@@ -0,0 +1,201 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
from typing import Any, Callable
|
||||
|
||||
from douyin.updater.bootstrap import load_update_settings, run_startup_update_check_early
|
||||
from gui.dashboard_app import theme
|
||||
from gui.dashboard_app.widgets import rounded_surface
|
||||
|
||||
|
||||
class UpdateProgressWindow:
|
||||
"""Small standalone update progress window used before the main GUI exists."""
|
||||
|
||||
def __init__(self, title: str = "软件更新") -> None:
|
||||
self.root = tk.Tk()
|
||||
self.root.title(title)
|
||||
self.root.resizable(False, False)
|
||||
self.root.configure(bg=theme.BG)
|
||||
theme.setup_styles(self.root)
|
||||
self.root.protocol("WM_DELETE_WINDOW", lambda: None)
|
||||
|
||||
frame = tk.Frame(self.root, bg=theme.BG, padx=28, pady=26)
|
||||
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=26, pady=24)
|
||||
inner.pack(fill="both", expand=True)
|
||||
|
||||
top = tk.Frame(inner, bg=theme.SURFACE)
|
||||
top.pack(fill="x")
|
||||
tk.Label(
|
||||
top,
|
||||
text="正在更新",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEXT,
|
||||
font=("Microsoft YaHei UI", 19, "bold"),
|
||||
).pack(side="left")
|
||||
self.mode = tk.Label(
|
||||
top,
|
||||
text="检查中",
|
||||
bg=theme.BLUE_SOFT,
|
||||
fg=theme.BLUE,
|
||||
font=("Microsoft YaHei UI", 12, "bold"),
|
||||
padx=12,
|
||||
pady=5,
|
||||
)
|
||||
self.mode.pack(side="right")
|
||||
|
||||
self.stage = tk.Label(
|
||||
inner,
|
||||
text="正在连接更新服务器",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEXT,
|
||||
font=("Microsoft YaHei UI", 14, "bold"),
|
||||
)
|
||||
self.stage.pack(anchor="w", pady=(20, 5))
|
||||
self.detail = tk.Label(
|
||||
inner,
|
||||
text="优先尝试差量更新,失败后才回退完整安装包",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.MUTED,
|
||||
font=theme.FONT_SMALL,
|
||||
)
|
||||
self.detail.pack(anchor="w", pady=(0, 14))
|
||||
self.percent = tk.Label(
|
||||
inner,
|
||||
text="0%",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEAL_DARK,
|
||||
font=("Microsoft YaHei UI", 24, "bold"),
|
||||
)
|
||||
self.percent.pack(anchor="e")
|
||||
self.bar = ttk.Progressbar(inner, mode="determinate", length=460, maximum=100)
|
||||
self.bar.pack(fill="x", pady=(3, 10), ipady=4)
|
||||
self.sub = tk.Label(
|
||||
inner,
|
||||
text="准备中",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.SUBTLE,
|
||||
font=("Microsoft YaHei UI", 11),
|
||||
)
|
||||
self.sub.pack(anchor="w")
|
||||
|
||||
self.root.update_idletasks()
|
||||
w, h = self.root.winfo_width(), self.root.winfo_height()
|
||||
sw, sh = self.root.winfo_screenwidth(), self.root.winfo_screenheight()
|
||||
self.root.geometry(f"+{max(0, (sw - w) // 2)}+{max(0, (sh - h) // 2)}")
|
||||
|
||||
def callback(self) -> Callable[[dict[str, Any]], None]:
|
||||
return lambda event: self.root.after(0, lambda event=event: self.update(event))
|
||||
|
||||
def update(self, event: dict[str, Any]) -> None:
|
||||
apply_update_progress_event(
|
||||
event,
|
||||
mode_label=self.mode,
|
||||
stage_label=self.stage,
|
||||
detail_label=self.detail,
|
||||
percent_label=self.percent,
|
||||
bar=self.bar,
|
||||
sub_label=self.sub,
|
||||
)
|
||||
self.root.update_idletasks()
|
||||
|
||||
def close(self) -> None:
|
||||
try:
|
||||
self.root.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def run_gui_startup_update_check_early(app_name: str) -> None:
|
||||
"""Run startup updater with a visible GUI progress window when enabled."""
|
||||
try:
|
||||
settings = load_update_settings()
|
||||
except Exception:
|
||||
settings = None
|
||||
if settings is None or not settings.enabled:
|
||||
run_startup_update_check_early(app_name=app_name)
|
||||
return
|
||||
|
||||
progress = UpdateProgressWindow()
|
||||
try:
|
||||
run_startup_update_check_early(
|
||||
app_name=app_name,
|
||||
progress_callback=progress.callback(),
|
||||
)
|
||||
finally:
|
||||
progress.close()
|
||||
|
||||
|
||||
def apply_update_progress_event(
|
||||
event: dict[str, Any],
|
||||
*,
|
||||
mode_label: tk.Label,
|
||||
stage_label: tk.Label,
|
||||
detail_label: tk.Label,
|
||||
percent_label: tk.Label,
|
||||
bar: ttk.Progressbar,
|
||||
sub_label: tk.Label,
|
||||
) -> None:
|
||||
stage = str(event.get("stage") or "")
|
||||
message = str(event.get("message") or "")
|
||||
kind = str(event.get("kind") or "")
|
||||
stage_text = message or {
|
||||
"manifest_fetch": "正在连接更新服务器",
|
||||
"manifest_verify": "正在校验更新签名",
|
||||
"delta_download_start": "正在下载差量包",
|
||||
"delta_verify": "正在校验差量包",
|
||||
"delta_validate": "正在检查差量包内容",
|
||||
"delta_launch": "正在应用差量更新",
|
||||
"delta_failed": "差量更新失败,准备回退完整安装包",
|
||||
"delta_unavailable": "未找到当前版本可用的差量包",
|
||||
"delta_skipped": "上次差量更新未完成",
|
||||
"full_prepare": "准备下载完整安装包",
|
||||
"full_download_start": "正在下载完整安装包",
|
||||
"full_verify": "正在校验完整安装包",
|
||||
"full_launch": "正在启动安装器",
|
||||
}.get(stage, "正在处理更新")
|
||||
|
||||
if kind == "delta" or stage.startswith("delta_"):
|
||||
mode_text = "差量更新"
|
||||
mode_bg, mode_fg = theme.TEAL_SOFT, theme.TEAL_DARK
|
||||
elif kind == "full" or stage.startswith("full_"):
|
||||
mode_text = "完整安装包"
|
||||
mode_bg, mode_fg = theme.AMBER_SOFT, theme.AMBER
|
||||
else:
|
||||
mode_text = "检查中"
|
||||
mode_bg, mode_fg = theme.BLUE_SOFT, theme.BLUE
|
||||
|
||||
mode_label.config(text=mode_text, bg=mode_bg, fg=mode_fg)
|
||||
stage_label.config(text=stage_text)
|
||||
|
||||
done = int(event.get("done") or 0)
|
||||
total = int(event.get("total") or 0)
|
||||
if stage == "download_progress" and total > 0:
|
||||
percent = max(0, min(100, round(done * 100 / total)))
|
||||
bar.config(value=percent)
|
||||
percent_label.config(text=f"{percent}%")
|
||||
detail_label.config(text=f"已下载 {done // (1024 * 1024)} MB / {max(1, total // (1024 * 1024))} MB")
|
||||
elif stage.endswith("_start"):
|
||||
bar.config(value=5)
|
||||
percent_label.config(text="0%")
|
||||
detail_label.config(text="正在建立下载任务")
|
||||
elif stage in {"delta_verify", "delta_validate", "full_verify"}:
|
||||
bar.config(value=92)
|
||||
percent_label.config(text="92%")
|
||||
detail_label.config(text="下载完成,正在校验完整性")
|
||||
elif stage in {"delta_launch", "full_launch"}:
|
||||
bar.config(value=100)
|
||||
percent_label.config(text="100%")
|
||||
detail_label.config(text="校验完成,正在启动更新器")
|
||||
elif stage in {"delta_failed", "delta_unavailable", "delta_skipped"}:
|
||||
bar.config(value=0)
|
||||
percent_label.config(text="回退")
|
||||
detail_label.config(text=str(event.get("error") or "将下载完整安装包"))
|
||||
else:
|
||||
bar.config(value=max(8, int(float(bar["value"] or 0))))
|
||||
percent_label.config(text="")
|
||||
|
||||
sub_label.config(text=str(event.get("path") or event.get("url") or ""))
|
||||
+89
-14
@@ -24,6 +24,7 @@ from gui.components.config_vars import build_config_vars
|
||||
from gui.components.mousewheel_guard import disable_spinbox_mousewheel
|
||||
from gui.components.run_params_builder import get_params as build_run_params
|
||||
from gui.components.screenshot_action import do_screenshot
|
||||
from gui.components.update_progress import apply_update_progress_event
|
||||
from gui.components.wifi_adb_dialog import open_wifi_adb_dialog
|
||||
from gui.components.wifi_adb_one_click_scan import on_scan_one_click
|
||||
from gui.components.wifi_adb_pick_dialog import open_scan_pick_dialog
|
||||
@@ -541,7 +542,13 @@ class DashboardApp:
|
||||
|
||||
def worker() -> None:
|
||||
try:
|
||||
result = perform_forced_update(settings=load_manual_update_settings())
|
||||
result = perform_forced_update(
|
||||
settings=load_manual_update_settings(),
|
||||
progress_callback=lambda event: self.root.after(
|
||||
0,
|
||||
lambda event=event: self._update_progress_window(progress, event),
|
||||
),
|
||||
)
|
||||
self.root.after(0, lambda: self._finish_update_progress(progress, lambda: self._show_update_result(result)))
|
||||
except UpdateError as exc:
|
||||
self.root.after(0, lambda: self._finish_update_progress(progress, lambda: self._show_update_error(str(exc))))
|
||||
@@ -555,27 +562,81 @@ class DashboardApp:
|
||||
win.title("检查更新")
|
||||
win.transient(self.root)
|
||||
win.resizable(False, False)
|
||||
win.configure(bg=theme.SURFACE)
|
||||
win.configure(bg=theme.BG)
|
||||
win.protocol("WM_DELETE_WINDOW", lambda: None)
|
||||
frame = tk.Frame(win, bg=theme.SURFACE, padx=24, pady=22)
|
||||
frame = tk.Frame(win, bg=theme.BG, padx=26, pady=24)
|
||||
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=22)
|
||||
inner.pack(fill="both", expand=True)
|
||||
|
||||
top = tk.Frame(inner, bg=theme.SURFACE)
|
||||
top.pack(fill="x")
|
||||
tk.Label(
|
||||
frame,
|
||||
text="正在检查更新",
|
||||
top,
|
||||
text="软件更新",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEXT,
|
||||
font=("Microsoft YaHei UI", 16, "bold"),
|
||||
).pack(anchor="w")
|
||||
tk.Label(
|
||||
frame,
|
||||
font=("Microsoft YaHei UI", 18, "bold"),
|
||||
).pack(side="left")
|
||||
mode = tk.Label(
|
||||
top,
|
||||
text="检查中",
|
||||
bg=theme.TEAL_SOFT,
|
||||
fg=theme.TEAL_DARK,
|
||||
font=("Microsoft YaHei UI", 12, "bold"),
|
||||
padx=12,
|
||||
pady=5,
|
||||
)
|
||||
mode.pack(side="right")
|
||||
|
||||
stage = tk.Label(
|
||||
inner,
|
||||
text=message,
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEXT,
|
||||
font=("Microsoft YaHei UI", 14, "bold"),
|
||||
)
|
||||
stage.pack(anchor="w", pady=(18, 4))
|
||||
detail = tk.Label(
|
||||
inner,
|
||||
text="优先尝试差量更新,失败后才回退完整安装包",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.MUTED,
|
||||
font=theme.FONT_UI,
|
||||
).pack(anchor="w", pady=(8, 14))
|
||||
bar = ttk.Progressbar(frame, mode="indeterminate", length=340)
|
||||
bar.pack(fill="x")
|
||||
bar.start(12)
|
||||
font=theme.FONT_SMALL,
|
||||
)
|
||||
detail.pack(anchor="w", pady=(0, 14))
|
||||
pct = tk.Label(
|
||||
inner,
|
||||
text="0%",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.TEAL_DARK,
|
||||
font=("Microsoft YaHei UI", 22, "bold"),
|
||||
)
|
||||
pct.pack(anchor="e")
|
||||
bar = ttk.Progressbar(inner, mode="determinate", length=420, maximum=100)
|
||||
bar.pack(fill="x", pady=(3, 10), ipady=3)
|
||||
sub = tk.Label(
|
||||
inner,
|
||||
text="准备中",
|
||||
bg=theme.SURFACE,
|
||||
fg=theme.SUBTLE,
|
||||
font=("Microsoft YaHei UI", 11),
|
||||
)
|
||||
sub.pack(anchor="w")
|
||||
|
||||
win._update_labels = { # type: ignore[attr-defined]
|
||||
"mode": mode,
|
||||
"stage": stage,
|
||||
"detail": detail,
|
||||
"pct": pct,
|
||||
"bar": bar,
|
||||
"sub": sub,
|
||||
}
|
||||
self._update_progress_window(win, {"stage": "manifest_fetch", "message": message})
|
||||
|
||||
try:
|
||||
win.update_idletasks()
|
||||
x = self.root.winfo_rootx() + (self.root.winfo_width() - win.winfo_width()) // 2
|
||||
@@ -586,6 +647,20 @@ class DashboardApp:
|
||||
pass
|
||||
return win
|
||||
|
||||
def _update_progress_window(self, progress: tk.Toplevel, event: dict) -> None:
|
||||
labels = getattr(progress, "_update_labels", None)
|
||||
if not labels:
|
||||
return
|
||||
apply_update_progress_event(
|
||||
event,
|
||||
mode_label=labels["mode"],
|
||||
stage_label=labels["stage"],
|
||||
detail_label=labels["detail"],
|
||||
percent_label=labels["pct"],
|
||||
bar=labels["bar"],
|
||||
sub_label=labels["sub"],
|
||||
)
|
||||
|
||||
def _finish_update_progress(self, progress: tk.Toplevel, callback) -> None:
|
||||
try:
|
||||
progress.grab_release()
|
||||
|
||||
@@ -8,10 +8,10 @@ _BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
if str(_BASE_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(_BASE_DIR))
|
||||
|
||||
from douyin.updater.bootstrap import run_startup_update_check_early
|
||||
from gui.components.update_progress import run_gui_startup_update_check_early
|
||||
|
||||
|
||||
run_startup_update_check_early(app_name="gui_app")
|
||||
run_gui_startup_update_check_early(app_name="gui_app")
|
||||
|
||||
from douyin.core.version import print_version_banner # noqa: E402
|
||||
from gui.gui_app import main # noqa: E402
|
||||
|
||||
+50
-2
@@ -7,6 +7,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import Optional
|
||||
@@ -132,15 +133,62 @@ def list_adb_devices(adb_exe: str) -> list[str]:
|
||||
errors="replace",
|
||||
check=False,
|
||||
env=_adb_env(),
|
||||
timeout=5,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
except (FileNotFoundError, subprocess.TimeoutExpired):
|
||||
return []
|
||||
devices: list[str] = []
|
||||
for line in (proc.stdout or "").splitlines()[1:]:
|
||||
parts = line.split()
|
||||
if len(parts) >= 2 and parts[1] == "device":
|
||||
devices.append(parts[0])
|
||||
return devices
|
||||
return _normalize_mdns_device_serials(adb_exe, devices)
|
||||
|
||||
|
||||
def _normalize_mdns_device_serials(adb_exe: str, devices: list[str]) -> list[str]:
|
||||
"""Convert Android wireless-debug mDNS serials to stable ip:port targets."""
|
||||
mdns_serials = [d for d in devices if "._adb" in d or d.startswith("adb-")]
|
||||
if not mdns_serials:
|
||||
return devices
|
||||
mdns_targets: list[str] = []
|
||||
try:
|
||||
proc = subprocess.run(
|
||||
[adb_exe, "mdns", "services"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
check=False,
|
||||
env=_adb_env(),
|
||||
timeout=2,
|
||||
)
|
||||
if proc.returncode == 0:
|
||||
for line in (proc.stdout or "").splitlines():
|
||||
if "_adb-tls-pairing" in line or "_adb" not in line:
|
||||
continue
|
||||
m = re.search(r"(\d{1,3}(?:\.\d{1,3}){3}):(\d{1,5})", line)
|
||||
if m:
|
||||
mdns_targets.append(f"{m.group(1)}:{m.group(2)}")
|
||||
except Exception:
|
||||
mdns_targets = []
|
||||
|
||||
out: list[str] = []
|
||||
has_ip_target = any(_is_ip_port_device(d) for d in devices) or bool(mdns_targets)
|
||||
for device in devices:
|
||||
if device in mdns_serials and mdns_targets:
|
||||
for target in mdns_targets:
|
||||
if target not in out:
|
||||
out.append(target)
|
||||
continue
|
||||
if device in mdns_serials and has_ip_target:
|
||||
continue
|
||||
if device not in out:
|
||||
out.append(device)
|
||||
return out
|
||||
|
||||
|
||||
def _is_ip_port_device(device: str) -> bool:
|
||||
return bool(re.fullmatch(r"\d{1,3}(?:\.\d{1,3}){3}:\d{1,5}", str(device or "").strip()))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from dataclasses import dataclass
|
||||
from typing import Callable, Iterable, Optional
|
||||
|
||||
from .adb import _adb_env
|
||||
from .adb import _adb_env, list_adb_devices
|
||||
|
||||
|
||||
DEFAULT_ADB_PORT = 5555
|
||||
@@ -728,6 +728,21 @@ def discover_mdns_targets(adb_exe: str) -> list[tuple[str, int]]:
|
||||
return targets
|
||||
|
||||
|
||||
def discover_connected_wifi_targets(adb_exe: str) -> list[tuple[str, int]]:
|
||||
"""Return already-connected WiFi ADB targets from adb devices as scan fallback."""
|
||||
targets: list[tuple[str, int]] = []
|
||||
seen: set[tuple[str, int]] = set()
|
||||
for device in list_adb_devices(adb_exe):
|
||||
parsed = _parse_target_ip_port(device)
|
||||
if not parsed:
|
||||
continue
|
||||
if parsed in seen:
|
||||
continue
|
||||
seen.add(parsed)
|
||||
targets.append(parsed)
|
||||
return targets
|
||||
|
||||
|
||||
def verify_adb_target(adb_exe: str, target: str, timeout: float = 5.0) -> tuple[str, str]:
|
||||
"""对一个 ip:port 调 `adb connect <target>`,解析输出。
|
||||
|
||||
@@ -886,11 +901,17 @@ def discover_adb_devices(
|
||||
|
||||
# 2) mDNS 发现(Android 11+ 无线调试常见随机端口)
|
||||
mdns_targets = discover_mdns_targets(adb_exe)
|
||||
connected_wifi_targets = discover_connected_wifi_targets(adb_exe)
|
||||
if on_phase and mdns_targets:
|
||||
try:
|
||||
on_phase(f"mDNS 发现 {len(mdns_targets)} 个 ADB 候选目标")
|
||||
except Exception:
|
||||
pass
|
||||
if on_phase and connected_wifi_targets:
|
||||
try:
|
||||
on_phase(f"已连接设备兜底发现 {len(connected_wifi_targets)} 个 WiFi ADB 目标")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
quick_open_targets: list[tuple[str, int]] = []
|
||||
quick_hosts: list[str] = []
|
||||
@@ -954,7 +975,8 @@ def discover_adb_devices(
|
||||
all_open_targets.extend(open_targets)
|
||||
|
||||
# 合并 mDNS + 网段扫描,并去重
|
||||
all_targets = list(mdns_targets)
|
||||
all_targets = list(connected_wifi_targets)
|
||||
all_targets.extend(mdns_targets)
|
||||
all_targets.extend(quick_open_targets)
|
||||
all_targets.extend(all_open_targets)
|
||||
uniq_open: list[tuple[str, int]] = []
|
||||
|
||||
@@ -8,10 +8,10 @@ _BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
if str(_BASE_DIR) not in sys.path:
|
||||
sys.path.insert(0, str(_BASE_DIR))
|
||||
|
||||
from douyin.updater.bootstrap import run_startup_update_check_early
|
||||
from gui.components.update_progress import run_gui_startup_update_check_early
|
||||
|
||||
|
||||
run_startup_update_check_early(app_name="gui_dashboard_app")
|
||||
run_gui_startup_update_check_early(app_name="gui_dashboard_app")
|
||||
|
||||
from gui.dashboard_app.app import main # noqa: E402
|
||||
|
||||
|
||||
Reference in new issue
Block a user