fix: require license for dashboard gui

This commit is contained in:
Your Name committed 2026-06-27 23:35:24 +08:00
1 parent 383c947a03
commit 39996405d5
3 files changed
+54 -2

No files matched your search

+16 -2
View File
@@ -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__":
+2
View File
@@ -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"}
+36
View File
@@ -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",