From 39996405d568abb261c50b8f33e3415590e2ed4c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 27 Jun 2026 23:35:24 +0800 Subject: [PATCH] fix: require license for dashboard gui --- gui/dashboard_app/app.py | 18 +++++++++++-- gui/dashboard_app/page_config.py | 2 ++ tests/test_startup_update_bootstrap.py | 36 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/gui/dashboard_app/app.py b/gui/dashboard_app/app.py index 1dc7bf8..f593802 100644 --- a/gui/dashboard_app/app.py +++ b/gui/dashboard_app/app.py @@ -1,10 +1,16 @@ from __future__ import annotations +import os import tkinter as tk from tkinter import messagebox, ttk from douyin.core.version import print_version_banner -from douyin.license.license_manager import get_default_activation_url, install_license_or_activate +from douyin.license.license_manager import ( + get_default_activation_url, + install_license_or_activate, + require_online_license_or_exit, + start_online_license_monitor, +) from gui.components.config_io import save_ui_to_config from gui.components.config_vars import build_config_vars from gui.components.mousewheel_guard import disable_spinbox_mousewheel @@ -23,6 +29,10 @@ from .page_registry import PAGES from .widgets import ScrollFrame, SlimScrollbar, button, clear, nav_button, rounded_surface, status_pill +def enforce_dashboard_license_required() -> None: + os.environ["DOUYIN_LICENSE_REQUIRED"] = "1" + + class DashboardApp: def __init__(self) -> None: self.root = tk.Tk() @@ -473,11 +483,15 @@ class DashboardApp: def main() -> None: + enforce_dashboard_license_required() + require_online_license_or_exit() try: print_version_banner("gui_dashboard_app") except Exception: pass - DashboardApp().run() + app = DashboardApp() + start_online_license_monitor(on_line=app._on_runner_line) + app.run() if __name__ == "__main__": diff --git a/gui/dashboard_app/page_config.py b/gui/dashboard_app/page_config.py index a7a4dae..3db7560 100644 --- a/gui/dashboard_app/page_config.py +++ b/gui/dashboard_app/page_config.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import tkinter as tk from douyin.license.license_manager import get_license_status_payload @@ -172,6 +173,7 @@ def build_license(parent: tk.Misc, data: DashboardData, ctx: PageContext) -> Non ctx.vars["license_key_var"] = tk.StringVar(value="") pack_fields(box, ctx, [("输入卡密", "license_key_var", "")], columns=1) try: + os.environ["DOUYIN_LICENSE_REQUIRED"] = "1" payload = get_license_status_payload() except Exception as exc: payload = {"ok": False, "message": f"读取授权状态失败:{exc}", "reason": "status_error"} diff --git a/tests/test_startup_update_bootstrap.py b/tests/test_startup_update_bootstrap.py index 98e8df3..636cd1d 100644 --- a/tests/test_startup_update_bootstrap.py +++ b/tests/test_startup_update_bootstrap.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import subprocess import sys from pathlib import Path @@ -74,6 +75,41 @@ def test_dashboard_gui_runs_update_bootstrap_before_gui_imports(): _assert_packaging_uses_wrapper("gui\\gui_dashboard_app_entry.py", "gui\\dashboard_app\\app.py") +def test_dashboard_gui_main_forces_license_required(monkeypatch): + from gui.dashboard_app import app as dashboard_app + + calls = {"app_started": False, "monitor_started": False, "required_at_check": ""} + + class FakeDashboardApp: + def __init__(self) -> None: + calls["app_started"] = True + + def _on_runner_line(self, line: str) -> None: + pass + + def run(self) -> None: + calls["run_called"] = True + + def fake_require_online_license_or_exit() -> None: + calls["required_at_check"] = os.environ.get("DOUYIN_LICENSE_REQUIRED", "") + + def fake_start_online_license_monitor(**_kwargs): + calls["monitor_started"] = True + return None + + monkeypatch.delenv("DOUYIN_LICENSE_REQUIRED", raising=False) + monkeypatch.setattr(dashboard_app, "DashboardApp", FakeDashboardApp) + monkeypatch.setattr(dashboard_app, "require_online_license_or_exit", fake_require_online_license_or_exit) + monkeypatch.setattr(dashboard_app, "start_online_license_monitor", fake_start_online_license_monitor) + + dashboard_app.main() + + assert calls["required_at_check"] == "1" + assert calls["app_started"] is True + assert calls["monitor_started"] is True + assert calls["run_called"] is True + + def test_web_gui_runs_update_bootstrap_before_gui_imports(): _assert_bootstrap_before( "gui/web_gui_entry.py",