fix: allow first-run license activation
This commit is contained in:
1 parent
e315aaf80b
commit
407c3b37c2
10 files changed
+715
-23
No files matched your search
@@ -0,0 +1,501 @@
|
||||
{
|
||||
"needswitch": true,
|
||||
"infinite_loop_enabled": true,
|
||||
"wait_minutes": 5,
|
||||
"auto_update": {
|
||||
"enabled": true,
|
||||
"manifest_url": "",
|
||||
"fail_closed": true,
|
||||
"require_sha256": true,
|
||||
"timeout_seconds": 20,
|
||||
"installer_args": [
|
||||
"/VERYSILENT",
|
||||
"/SUPPRESSMSGBOXES",
|
||||
"/NORESTART",
|
||||
"/CURRENTUSER"
|
||||
]
|
||||
},
|
||||
"min_prize_value_yuan": 100.0,
|
||||
"min_participants": 0,
|
||||
"max_participants": 0,
|
||||
"skip_if_countdown_gt_seconds": 10,
|
||||
"reset_after_swipes_enabled": true,
|
||||
"reset_after_swipes": 20,
|
||||
"reset_after_swipes_action": "swipe",
|
||||
"reenter_live_entry_mode": "screen_center",
|
||||
"auto_join_fansclub": true,
|
||||
"fansclub_fail_action": "switch",
|
||||
"high_value_fudai_enabled": true,
|
||||
"high_value_fudai_threshold_yuan": 150.0,
|
||||
"high_value_fudai_join_ahead_seconds": 100,
|
||||
"high_value_fudai_max_swipe_back": 50,
|
||||
"high_value_fudai_max_reservations": 9999,
|
||||
"high_value_fudai_after_action": "continue",
|
||||
"high_value_room_revisit_enabled": false,
|
||||
"high_value_room_revisit_only_current_run": false,
|
||||
"reservation_back_verify_enabled": true,
|
||||
"reservation_back_swipe_delay": 0.1,
|
||||
"reservation_back_verify_wait_seconds": 3.0,
|
||||
"desktop_icon_x": 153,
|
||||
"desktop_icon_y": 260,
|
||||
"yanghao_fallback_live_x": 540,
|
||||
"yanghao_fallback_live_y": 2000,
|
||||
"yanghao_fallback_enter_live_x": 540,
|
||||
"yanghao_fallback_enter_live_y": 1200,
|
||||
"fudai_find_max_attempts": 99999,
|
||||
"fudai_icon_max_wait_seconds": 7.0,
|
||||
"fudai_icon_retry_delay_seconds": 0.1,
|
||||
"fudai_exit_after_misses": 7,
|
||||
"enable_back_on_misses": false,
|
||||
"fudai_click_wait_seconds": 1.5,
|
||||
"fudai_detail_initial_wait_seconds": 0.8,
|
||||
"fudai_detail_verified_wait_seconds": 0.2,
|
||||
"fudai_detail_retry_delay_seconds": 0.5,
|
||||
"fudai_detail_save_debug_images": true,
|
||||
"fudai_detail_ui_mode": "auto",
|
||||
"fudai_detail_ocr_content_enabled": true,
|
||||
"fudai_detail_ocr_value_enabled": true,
|
||||
"fudai_detail_ocr_countdown_enabled": true,
|
||||
"fudai_detail_ocr_task_enabled": true,
|
||||
"fudai_detail_ocr_task_count_enabled": true,
|
||||
"fudai_detail_ocr_button_enabled": true,
|
||||
"fudai_detail_ocr_participants_enabled": false,
|
||||
"fudai_detail_ocr_live_title_enabled": true,
|
||||
"pixel_detect_fudai_icon_enabled": true,
|
||||
"pixel_detect_coupon_popup_enabled": true,
|
||||
"pixel_detect_shopping_redpacket_enabled": true,
|
||||
"pixel_detect_lottery_result_enabled": true,
|
||||
"pixel_detect_attend_button_enabled": true,
|
||||
"pixel_detect_fansclub_join_enabled": true,
|
||||
"pixel_detect_fudai_detail_enabled": true,
|
||||
"pixel_detect_live_room_enabled": true,
|
||||
"ocr_lottery_result_enabled": true,
|
||||
"ocr_coupon_popup_enabled": true,
|
||||
"ocr_shopping_redpacket_enabled": false,
|
||||
"ocr_stage_page_enabled": true,
|
||||
"fudai_disable_content_recognition": false,
|
||||
"fudai_disable_task_recognition": false,
|
||||
"yanghao_recommend_duration_seconds": 180,
|
||||
"yanghao_recommend_interval_seconds": 600,
|
||||
"yanghao_like_prob": 0.1,
|
||||
"yanghao_fav_prob": 0.05,
|
||||
"yanghao_comment_prob": 0.25,
|
||||
"yanghao_icon_roi_size": 240,
|
||||
"yanghao_icon_match_threshold": 0.77,
|
||||
"yanghao_step_screenshot": true,
|
||||
"yanghao_like_roi_offset_x": 0,
|
||||
"yanghao_like_roi_offset_y": -50,
|
||||
"yanghao_like_roi_scale": 1.0,
|
||||
"yanghao_fav_roi_offset_x": 40,
|
||||
"yanghao_fav_roi_offset_y": 0,
|
||||
"yanghao_fav_roi_scale": 1.0,
|
||||
"yanghao_like_rect_x1": 933,
|
||||
"yanghao_like_rect_y1": 1164,
|
||||
"yanghao_like_rect_x2": 1042,
|
||||
"yanghao_like_rect_y2": 1262,
|
||||
"yanghao_fav_rect_x1": 938,
|
||||
"yanghao_fav_rect_y1": 1567,
|
||||
"yanghao_fav_rect_x2": 1036,
|
||||
"yanghao_fav_rect_y2": 1665,
|
||||
"contains_want": [],
|
||||
"contains_not_want": [
|
||||
"首饰盒",
|
||||
"袜子"
|
||||
],
|
||||
"fudai_quiet_hours_enabled": true,
|
||||
"fudai_quiet_start_hour": 2,
|
||||
"fudai_quiet_end_hour": 9,
|
||||
"yanghao_enabled": false,
|
||||
"yanghao_enable_actions": true,
|
||||
"yanghao_like_icon_x": 988,
|
||||
"yanghao_like_icon_y": 1218,
|
||||
"yanghao_fav_icon_x": 988,
|
||||
"yanghao_fav_icon_y": 1616,
|
||||
"yanghao_like_template_path": "assets/like.png",
|
||||
"yanghao_fav_template_path": "assets/fav.png",
|
||||
"yanghao_after_dwell_swipe_direction": "up",
|
||||
"yanghao_after_dwell_swipe_distance_px": 900,
|
||||
"yanghao_comment_btn_x": 988,
|
||||
"yanghao_comment_btn_y": 1410,
|
||||
"yanghao_dwell_on_action_min_seconds": 5.0,
|
||||
"yanghao_dwell_on_action_max_seconds": 20.0,
|
||||
"yanghao_comment_input_x": 0,
|
||||
"yanghao_comment_input_y": 0,
|
||||
"yanghao_comment_send_x": 0,
|
||||
"yanghao_comment_send_y": -1,
|
||||
"yanghao_comment_close_x": 0,
|
||||
"yanghao_comment_close_y": 0,
|
||||
"yanghao_comment_texts": [
|
||||
"好看!",
|
||||
"赞一个",
|
||||
"真不错",
|
||||
"喜欢这个风格",
|
||||
"太棒了",
|
||||
"很有创意",
|
||||
"支持一下",
|
||||
"笑死我了",
|
||||
"学习了",
|
||||
"被圈粉了",
|
||||
"期待更多",
|
||||
"必须收藏",
|
||||
"这也太治愈了",
|
||||
"质量很高",
|
||||
"简直绝了",
|
||||
"画面太美了",
|
||||
"配色好舒服",
|
||||
"氛围感满分",
|
||||
"做得很用心",
|
||||
"好想试试这个",
|
||||
"安利给朋友",
|
||||
"收藏备用",
|
||||
"太有意思了",
|
||||
"这音乐选得太绝",
|
||||
"太会了",
|
||||
"入坑了",
|
||||
"好惊喜",
|
||||
"真有参考价值",
|
||||
"好暖心的一条",
|
||||
"笑哭,我服了",
|
||||
"细节处理得很好",
|
||||
"太有才了",
|
||||
"看着就治愈",
|
||||
"学习到新方法",
|
||||
"大家都来看看",
|
||||
"点赞支持",
|
||||
"完美",
|
||||
"好看到不行"
|
||||
],
|
||||
"yanghao_like_keywords": [],
|
||||
"yanghao_fav_keywords": [],
|
||||
"stage_diag_max_time": 2.0,
|
||||
"stage_diag_max_step_time": 0.5,
|
||||
"live_room_match_threshold": 0.8,
|
||||
"enable_ocr_mode1": false,
|
||||
"fudai_template_match_enabled": false,
|
||||
"fudai_template_match_threshold": 0.7,
|
||||
"lucky_draw_red_ratio_threshold": 0.8,
|
||||
"shopping_redpacket_red_ratio_threshold": 0.2,
|
||||
"y_pianyi": 0,
|
||||
"skip_if_countdown_lt_seconds": 5,
|
||||
"no_attend_timeout_minutes": 30.0,
|
||||
"logging": {
|
||||
"level": "DEBUG",
|
||||
"file_path": "logs/unified.log",
|
||||
"keep_days": 1,
|
||||
"use_dated_logs": true,
|
||||
"rotation": {
|
||||
"enabled": true,
|
||||
"max_bytes": 10485760,
|
||||
"backup_count": 5,
|
||||
"when": "midnight",
|
||||
"interval": 1
|
||||
},
|
||||
"beautify_output": true,
|
||||
"show_timestamps": true,
|
||||
"show_execution_times": true,
|
||||
"debug_detail_level": "normal",
|
||||
"error_detail_level": "full",
|
||||
"action_log_format": "concise",
|
||||
"log_format_mode": "simple",
|
||||
"stage_diag_verbose": true,
|
||||
"color_output": true,
|
||||
"max_log_lines_display": 1000,
|
||||
"auto_scroll_logs": true,
|
||||
"performance_tracking": {
|
||||
"enabled": true,
|
||||
"track_function_calls": true,
|
||||
"track_database_queries": false,
|
||||
"slow_operation_threshold_ms": 100
|
||||
},
|
||||
"error_logging": {
|
||||
"capture_stack_traces": true,
|
||||
"include_context": true,
|
||||
"max_error_logs": 1000,
|
||||
"error_categories": [
|
||||
"ocr",
|
||||
"network",
|
||||
"validation",
|
||||
"system",
|
||||
"user_action"
|
||||
]
|
||||
},
|
||||
"compress_logs": true,
|
||||
"max_total_size_gb": 0.2,
|
||||
"compress_after_days": 1,
|
||||
"max_bytes": 104857600,
|
||||
"backup_count": 10,
|
||||
"enable_monitor": true,
|
||||
"monitor_warning_mb": 60.0,
|
||||
"monitor_critical_mb": 200.0
|
||||
},
|
||||
"debug_captures": {
|
||||
"enabled": true,
|
||||
"keep_days": 1,
|
||||
"max_files": 1000,
|
||||
"auto_cleanup": true,
|
||||
"async_save": false,
|
||||
"log_on_complete": false
|
||||
},
|
||||
"fudai_detail_template_threshold": 0.52,
|
||||
"switch_room_wait_after_stage_diag_seconds": 7.5,
|
||||
"coupon_template_match_threshold": 0.35,
|
||||
"attend_button_red_ratio_threshold": 0.25,
|
||||
"fansclub_join_red_ratio_threshold": 0.25,
|
||||
"shopping_redpacket_ocr_confidence_threshold": 0.35,
|
||||
"reservation_test_mode": false,
|
||||
"swipe_duration_ms": 250,
|
||||
"gui": {
|
||||
"theme": "litera",
|
||||
"realtime_status": {
|
||||
"refresh_interval_ms": 1000,
|
||||
"tail_items": 50
|
||||
}
|
||||
},
|
||||
"fansclub_click_delay": 0.6,
|
||||
"fansclub_auto_join_wait_seconds": 5.0,
|
||||
"fansclub_manual_wait_seconds": 3.0,
|
||||
"enable_streaming_screenshot": false,
|
||||
"yanghao_only": false,
|
||||
"record_room_title_mapping_enabled": true,
|
||||
"high_value_fudai_poll_before_seconds": 10.0,
|
||||
"high_value_room_revisit_min_interval_seconds": 300,
|
||||
"high_value_room_revisit_max_per_run": 20,
|
||||
"high_value_room_revisit_min_prize_value": 1000.0,
|
||||
"high_value_room_revisit_max_age_days": 1,
|
||||
"swipe_up_start_y": 1200,
|
||||
"swipe_up_end_y": 600,
|
||||
"swipe_down_back_enabled": false,
|
||||
"swipe_down_back_count": 3,
|
||||
"log_unified_enabled": true,
|
||||
"log_unified_path": "logs/unified.log",
|
||||
"region_coords_edit_enabled": false,
|
||||
"fudai_detail_body_bluepurple_threshold": 0.45,
|
||||
"fudai_detail_body_dark_threshold": 0.35,
|
||||
"fudai_task_status_template_threshold": 0.26,
|
||||
"fudai_detail_regions": {
|
||||
"legacy": {
|
||||
"content": [
|
||||
389,
|
||||
1273,
|
||||
1000,
|
||||
1534
|
||||
],
|
||||
"value": [
|
||||
643,
|
||||
1466,
|
||||
769,
|
||||
1656
|
||||
],
|
||||
"countdown_full": [
|
||||
390,
|
||||
1110,
|
||||
690,
|
||||
1230
|
||||
],
|
||||
"task_list": [
|
||||
50,
|
||||
1621,
|
||||
1032,
|
||||
1960
|
||||
],
|
||||
"task_count": [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"participants": [
|
||||
389,
|
||||
1273,
|
||||
1000,
|
||||
1534
|
||||
],
|
||||
"button": [
|
||||
306,
|
||||
2030,
|
||||
780,
|
||||
2180
|
||||
],
|
||||
"live_title": [
|
||||
130,
|
||||
120,
|
||||
560,
|
||||
225
|
||||
]
|
||||
},
|
||||
"v2_0_two_task": {
|
||||
"content": [
|
||||
360,
|
||||
1410,
|
||||
1035,
|
||||
1495
|
||||
],
|
||||
"value": [
|
||||
300,
|
||||
1585,
|
||||
650,
|
||||
1685
|
||||
],
|
||||
"countdown_full": [
|
||||
760,
|
||||
1328,
|
||||
1038,
|
||||
1398
|
||||
],
|
||||
"task_list": [
|
||||
60,
|
||||
1840,
|
||||
1030,
|
||||
2005
|
||||
],
|
||||
"task_count": [
|
||||
860,
|
||||
1770,
|
||||
1035,
|
||||
1875
|
||||
],
|
||||
"participants": [
|
||||
520,
|
||||
1325,
|
||||
760,
|
||||
1415
|
||||
],
|
||||
"button": [
|
||||
70,
|
||||
2020,
|
||||
1010,
|
||||
2165
|
||||
],
|
||||
"live_title": [
|
||||
130,
|
||||
120,
|
||||
560,
|
||||
225
|
||||
]
|
||||
},
|
||||
"v2_0_one_task": {
|
||||
"content": [
|
||||
360,
|
||||
1460,
|
||||
1035,
|
||||
1545
|
||||
],
|
||||
"value": [
|
||||
350,
|
||||
1640,
|
||||
760,
|
||||
1735
|
||||
],
|
||||
"countdown_full": [
|
||||
700,
|
||||
1390,
|
||||
990,
|
||||
1470
|
||||
],
|
||||
"info_line": [
|
||||
430,
|
||||
1315,
|
||||
1055,
|
||||
1435
|
||||
],
|
||||
"task_list": [
|
||||
61,
|
||||
1845,
|
||||
885,
|
||||
2005
|
||||
],
|
||||
"task_count": [
|
||||
889,
|
||||
1855,
|
||||
1040,
|
||||
1960
|
||||
],
|
||||
"participants": [
|
||||
516,
|
||||
1396,
|
||||
743,
|
||||
1443
|
||||
],
|
||||
"button": [
|
||||
70,
|
||||
2050,
|
||||
1010,
|
||||
2195
|
||||
],
|
||||
"live_title": [
|
||||
130,
|
||||
120,
|
||||
560,
|
||||
225
|
||||
]
|
||||
}
|
||||
},
|
||||
"pixel_regions": {
|
||||
"lottery_result": {
|
||||
"button": [
|
||||
250,
|
||||
1275,
|
||||
825,
|
||||
1435
|
||||
],
|
||||
"pixel": [
|
||||
290,
|
||||
1300,
|
||||
790,
|
||||
1415
|
||||
],
|
||||
"click": [
|
||||
540,
|
||||
1360,
|
||||
0,
|
||||
0
|
||||
]
|
||||
},
|
||||
"attend_button": [
|
||||
200,
|
||||
2000,
|
||||
880,
|
||||
2120
|
||||
],
|
||||
"fansclub_join": [
|
||||
200,
|
||||
1940,
|
||||
880,
|
||||
2140
|
||||
],
|
||||
"coupon_popup": [
|
||||
9,
|
||||
1173,
|
||||
1079,
|
||||
2255
|
||||
],
|
||||
"shopping_redpacket": [
|
||||
200,
|
||||
300,
|
||||
880,
|
||||
1400
|
||||
],
|
||||
"fudai_detail_body": [
|
||||
0,
|
||||
1160,
|
||||
1080,
|
||||
2250
|
||||
],
|
||||
"fudai_task_status": [
|
||||
820,
|
||||
1815,
|
||||
1050,
|
||||
2035
|
||||
],
|
||||
"live_room_icon_bbox": [
|
||||
999,
|
||||
172,
|
||||
1028,
|
||||
202
|
||||
]
|
||||
},
|
||||
"license": {
|
||||
"activation_url": "https://dy.absfan.cn/api/v1/activate",
|
||||
"timeout_seconds": 10
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ from tkinter import messagebox, ttk
|
||||
|
||||
from douyin.core.version import print_version_banner
|
||||
from douyin.license.license_manager import (
|
||||
check_license,
|
||||
get_default_activation_url,
|
||||
install_license_or_activate,
|
||||
require_online_license_or_exit,
|
||||
@@ -34,7 +35,7 @@ def enforce_dashboard_license_required() -> None:
|
||||
|
||||
|
||||
class DashboardApp:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, *, initial_page: str = "数据看板", license_locked: bool = False) -> None:
|
||||
self.root = tk.Tk()
|
||||
try:
|
||||
self.root.tk.call("tk", "scaling", 1.12)
|
||||
@@ -57,8 +58,10 @@ class DashboardApp:
|
||||
"yg_like_keywords_text": self.data.cfg.get("yanghao_like_keywords", []) or [],
|
||||
"yg_fav_keywords_text": self.data.cfg.get("yanghao_fav_keywords", []) or [],
|
||||
}
|
||||
self.current_page = "数据看板"
|
||||
self.status_var = tk.StringVar(value="就绪")
|
||||
self.current_page = initial_page if initial_page in PAGES else "数据看板"
|
||||
self.license_locked = bool(license_locked)
|
||||
self._license_monitor_started = False
|
||||
self.status_var = tk.StringVar(value="请先验证卡密" if self.license_locked else "就绪")
|
||||
self.adb_exe = find_adb_executable()
|
||||
self.device_var = tk.StringVar(value="")
|
||||
self.y_var = self.config_vars.get("y_var", tk.IntVar(value=0))
|
||||
@@ -73,6 +76,23 @@ class DashboardApp:
|
||||
self.root.after(300, self._try_reconnect_last_wifi)
|
||||
self.show_page(self.current_page)
|
||||
|
||||
def _ensure_license_ready(self) -> bool:
|
||||
if not self.license_locked:
|
||||
return True
|
||||
self.status_var.set("请先验证卡密")
|
||||
try:
|
||||
self.show_page("授权")
|
||||
except Exception:
|
||||
pass
|
||||
messagebox.showwarning("需要授权", "请先在“授权”页面输入卡密并验证成功。", parent=self.root)
|
||||
return False
|
||||
|
||||
def _start_license_monitor_once(self) -> None:
|
||||
if self._license_monitor_started:
|
||||
return
|
||||
start_online_license_monitor(on_line=self._on_runner_line)
|
||||
self._license_monitor_started = True
|
||||
|
||||
def _build_shell(self) -> None:
|
||||
shell = ttk.Frame(self.root, style="Dashboard.TFrame")
|
||||
shell.pack(fill="both", expand=True)
|
||||
@@ -338,6 +358,8 @@ class DashboardApp:
|
||||
self.status_var.set(f"刷新设备失败:{exc}")
|
||||
|
||||
def open_wifi_adb(self) -> None:
|
||||
if not self._ensure_license_ready():
|
||||
return
|
||||
self.show_page("WiFi ADB")
|
||||
open_wifi_adb_dialog(
|
||||
self.root,
|
||||
@@ -356,6 +378,8 @@ class DashboardApp:
|
||||
)
|
||||
|
||||
def scan_wifi(self) -> None:
|
||||
if not self._ensure_license_ready():
|
||||
return
|
||||
on_scan_one_click(
|
||||
adb_exe=self.adb_exe,
|
||||
scan_btn=self.scan_button,
|
||||
@@ -368,6 +392,8 @@ class DashboardApp:
|
||||
)
|
||||
|
||||
def _try_reconnect_last_wifi(self) -> None:
|
||||
if self.license_locked:
|
||||
return
|
||||
try_reconnect_last_wifi(
|
||||
self.root,
|
||||
adb_exe=self.adb_exe,
|
||||
@@ -377,6 +403,8 @@ class DashboardApp:
|
||||
)
|
||||
|
||||
def screenshot_ocr(self) -> None:
|
||||
if not self._ensure_license_ready():
|
||||
return
|
||||
do_screenshot(
|
||||
device_id=self._selected_device(),
|
||||
y_offset=int(self.y_var.get() or 0),
|
||||
@@ -392,6 +420,8 @@ class DashboardApp:
|
||||
self.status_var.set(f"OCR结果已更新:{len(results)} 项")
|
||||
|
||||
def start_run(self) -> None:
|
||||
if not self._ensure_license_ready():
|
||||
return
|
||||
if self.runner.is_running():
|
||||
self.status_var.set("已在运行中")
|
||||
return
|
||||
@@ -423,6 +453,8 @@ class DashboardApp:
|
||||
self.status_var.set("已停止(强制)")
|
||||
|
||||
def send_back_key(self) -> None:
|
||||
if not self._ensure_license_ready():
|
||||
return
|
||||
ok = self.runner.send_back_key(self._selected_device())
|
||||
self.status_var.set("返回键已发送" if ok else "发送返回键失败")
|
||||
|
||||
@@ -449,8 +481,11 @@ class DashboardApp:
|
||||
if status.ok:
|
||||
if var is not None:
|
||||
var.set("")
|
||||
self.license_locked = False
|
||||
self.status_var.set("卡密验证成功")
|
||||
self._start_license_monitor_once()
|
||||
messagebox.showinfo("卡密验证", "验证成功,授权已写入本机。", parent=self.root)
|
||||
self.show_page("数据看板")
|
||||
else:
|
||||
self.status_var.set(f"卡密验证失败:{status.message}")
|
||||
messagebox.showerror(
|
||||
@@ -484,13 +519,19 @@ class DashboardApp:
|
||||
|
||||
def main() -> None:
|
||||
enforce_dashboard_license_required()
|
||||
require_online_license_or_exit()
|
||||
local_status = check_license()
|
||||
if local_status.ok:
|
||||
require_online_license_or_exit()
|
||||
try:
|
||||
print_version_banner("gui_dashboard_app")
|
||||
except Exception:
|
||||
pass
|
||||
app = DashboardApp()
|
||||
start_online_license_monitor(on_line=app._on_runner_line)
|
||||
app = DashboardApp(
|
||||
initial_page="数据看板" if local_status.ok else "授权",
|
||||
license_locked=not local_status.ok,
|
||||
)
|
||||
if local_status.ok:
|
||||
app._start_license_monitor_once()
|
||||
app.run()
|
||||
|
||||
|
||||
|
||||
+7
-3
@@ -24,7 +24,7 @@ if __name__ == "__main__":
|
||||
run_startup_update_check_early(app_name="web_gui")
|
||||
|
||||
from douyin.core import path_config
|
||||
from douyin.license.license_manager import require_online_license_or_exit, start_online_license_monitor
|
||||
from douyin.license.license_manager import check_license, require_online_license_or_exit, start_online_license_monitor
|
||||
|
||||
# 从子包 re-export 顶层 helper(保持兼容)
|
||||
from gui.web_gui_pkg import (
|
||||
@@ -910,8 +910,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
|
||||
def main() -> int:
|
||||
require_online_license_or_exit()
|
||||
start_online_license_monitor(on_line=lambda line: print(line, flush=True))
|
||||
local_status = check_license()
|
||||
if local_status.ok:
|
||||
require_online_license_or_exit()
|
||||
start_online_license_monitor(on_line=lambda line: print(line, flush=True))
|
||||
else:
|
||||
print(f"[LICENSE] 等待授权: {local_status.reason} - {local_status.message}", flush=True)
|
||||
host = get_web_gui_host()
|
||||
# 支持 PORT / WEB_GUI_PORT 两种环境变量,默认 8000
|
||||
port = get_web_gui_port()
|
||||
|
||||
@@ -7,6 +7,7 @@ from urllib.parse import parse_qs
|
||||
|
||||
from douyin.core import path_config
|
||||
from douyin.license.license_manager import (
|
||||
check_license,
|
||||
get_default_activation_url,
|
||||
get_license_status_payload,
|
||||
install_license_or_activate,
|
||||
@@ -33,6 +34,23 @@ _EMPTY_PNG_BYTES = bytes.fromhex(
|
||||
"1f15c4890000000a49444154789c636000000200015dc1b2ea00000000"
|
||||
"49454e44ae426082"
|
||||
)
|
||||
_LICENSE_REQUIRED_POST_PATHS = {
|
||||
"/api/start-run",
|
||||
"/api/force-stop",
|
||||
"/api/pause",
|
||||
"/api/resume",
|
||||
"/api/back-key",
|
||||
"/api/wifi/enable",
|
||||
"/api/wifi/connect",
|
||||
"/api/wifi/disconnect",
|
||||
"/api/wifi/scan",
|
||||
"/api/wifi/last/clear",
|
||||
"/api/wifi/auto-reconnect",
|
||||
"/api/test-yanghao",
|
||||
"/api/test-comment",
|
||||
"/api/stop",
|
||||
"/api/screenshot",
|
||||
}
|
||||
|
||||
|
||||
def _is_local_request(handler) -> bool:
|
||||
@@ -72,6 +90,20 @@ def _license_activation_settings() -> tuple[str, int]:
|
||||
return activation_url, max(1, timeout_seconds)
|
||||
|
||||
|
||||
def _license_gate_payload() -> dict:
|
||||
status = check_license()
|
||||
payload = get_license_status_payload()
|
||||
payload.update(
|
||||
{
|
||||
"ok": False,
|
||||
"error": "license_required",
|
||||
"reason": status.reason,
|
||||
"message": status.message,
|
||||
}
|
||||
)
|
||||
return payload
|
||||
|
||||
|
||||
def _is_invalid_ports_spec(spec) -> bool:
|
||||
"""判断端口规格是否为明确非法输入。"""
|
||||
if spec is None:
|
||||
@@ -349,6 +381,8 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
return handler._send_json(
|
||||
{"ok": False, "error": "Invalid CSRF token"}, status=403
|
||||
)
|
||||
if u.path in _LICENSE_REQUIRED_POST_PATHS and not check_license().ok:
|
||||
return handler._send_json(_license_gate_payload(), status=403)
|
||||
|
||||
if u.path == "/api/config":
|
||||
body = handler._read_json()
|
||||
|
||||
+1
-1
@@ -100,5 +100,5 @@ dist\installer\DouyinGuaji-3.3.3-Setup.exe
|
||||
- 最终分发目录只应保留根目录三个 exe、一个 `_internal/`、运行时白名单 `assets/`、运行时白名单 `webui/`、`platform-tools/` 中的 ADB 白名单文件、`android-tools/ADBKeyboard.apk`、`config/README.md`、`logs/.keep`、`pic/.keep`、`state/.keep`。正式分发不要包含 `license.dat`、`README.md`、`artifacts/`、`tests/`、源码目录、调试截图、临时模板或 debug/README 页面。
|
||||
- 正式包会自带 ADB,不要求目标电脑额外安装 Android platform-tools 或配置 PATH。程序在需要中文输入且设备未安装 ADBKeyboard 时,会尝试从随包 `android-tools/ADBKeyboard.apk` 自动安装到手机。新电脑仍需要在手机上开启开发者选项/USB 调试并允许本机 RSA 授权;部分品牌手机首次 USB 识别还需要 Windows 能正确安装对应 USB 驱动。
|
||||
- 首次启动 PaddleOCR 相关组件可能较慢,杀毒软件也可能扫描 exe。
|
||||
- `config/config.json` 是本地运行配置,默认不随安装包带个人配置;让使用者首次打开后在 GUI 中保存配置。
|
||||
- `config/default_config.json` 会随安装包复制为 `config/config.json`,只放正式默认值,不放个人设备、卡密或运行状态。
|
||||
- 默认 Cython 编译后仍要以 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>` 的结果为准;PASS 才能发给别人。使用 `-NoCythonForDevOnly` 生成的明文包禁止分发。
|
||||
@@ -167,8 +167,14 @@ foreach ($dir in @("css", "js", "partials")) {
|
||||
} | Copy-Item -Destination $dstDir -Force
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force (Join-Path $DistRoot "config") | Out-Null
|
||||
Copy-Item -LiteralPath (Join-Path $Root "config\README.md") -Destination (Join-Path $DistRoot "config\README.md") -Force
|
||||
$ConfigTarget = Join-Path $DistRoot "config"
|
||||
New-Item -ItemType Directory -Force $ConfigTarget | Out-Null
|
||||
Copy-Item -LiteralPath (Join-Path $Root "config\README.md") -Destination (Join-Path $ConfigTarget "README.md") -Force
|
||||
$DefaultConfig = Join-Path $Root "config\default_config.json"
|
||||
if (-not (Test-Path $DefaultConfig)) {
|
||||
throw "Missing default runtime config: config\default_config.json"
|
||||
}
|
||||
Copy-Item -LiteralPath $DefaultConfig -Destination (Join-Path $ConfigTarget "config.json") -Force
|
||||
foreach ($dir in @("logs", "pic", "state")) {
|
||||
$runtimeDir = Join-Path $DistRoot $dir
|
||||
New-Item -ItemType Directory -Force $runtimeDir | Out-Null
|
||||
|
||||
@@ -15,7 +15,7 @@ def test_distribution_manifest_blocks_source_and_debug_artifacts():
|
||||
"README.md",
|
||||
"douyin/core/douyin_fudai.py",
|
||||
"artifacts/debug.png",
|
||||
"config/config.json",
|
||||
"config/private.tmp",
|
||||
"logs/unified.log",
|
||||
"pic/debug_captures/a.png",
|
||||
"license.dat",
|
||||
@@ -31,7 +31,8 @@ def test_distribution_manifest_blocks_source_and_debug_artifacts():
|
||||
|
||||
assert "douyin/core/douyin_fudai.py" in blocked
|
||||
assert "artifacts/debug.png" in blocked
|
||||
assert "config/config.json" in blocked
|
||||
assert "config/config.json" not in blocked
|
||||
assert "config/private.tmp" in blocked
|
||||
assert "logs/unified.log" in blocked
|
||||
assert "pic/debug_captures/a.png" in blocked
|
||||
assert "license.dat" in blocked
|
||||
@@ -65,6 +66,7 @@ def test_distribution_manifest_blocks_project_native_binaries_outside_core_allow
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
@@ -102,6 +104,7 @@ def test_distribution_manifest_allows_expected_runtime_shape():
|
||||
"platform-tools/source.properties",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
@@ -142,6 +145,7 @@ def test_distribution_manifest_can_allow_license_for_local_test_package():
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
@@ -167,6 +171,7 @@ def test_distribution_manifest_requires_python_runtime_dll():
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
@@ -189,6 +194,7 @@ def test_distribution_manifest_requires_bundled_android_runtime():
|
||||
"assets/fudai.png",
|
||||
"webui/index.html",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
@@ -220,6 +226,7 @@ def test_distribution_manifest_cli_passes_clean_tree(tmp_path):
|
||||
"platform-tools/AdbWinUsbApi.dll",
|
||||
"android-tools/ADBKeyboard.apk",
|
||||
"config/README.md",
|
||||
"config/config.json",
|
||||
"logs/.keep",
|
||||
"pic/.keep",
|
||||
"state/.keep",
|
||||
|
||||
@@ -78,34 +78,83 @@ def test_dashboard_gui_runs_update_bootstrap_before_gui_imports():
|
||||
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": ""}
|
||||
calls = {
|
||||
"app_started": False,
|
||||
"monitor_started": False,
|
||||
"required_at_check": "",
|
||||
"initial_page": "",
|
||||
"license_locked": None,
|
||||
}
|
||||
|
||||
class FakeDashboardApp:
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, *, initial_page="数据看板", license_locked=False) -> None:
|
||||
calls["app_started"] = True
|
||||
calls["initial_page"] = initial_page
|
||||
calls["license_locked"] = license_locked
|
||||
|
||||
def _on_runner_line(self, line: str) -> None:
|
||||
pass
|
||||
|
||||
def _start_license_monitor_once(self) -> None:
|
||||
calls["monitor_started"] = True
|
||||
|
||||
def run(self) -> None:
|
||||
calls["run_called"] = True
|
||||
|
||||
class MissingStatus:
|
||||
ok = False
|
||||
|
||||
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, "check_license", lambda: MissingStatus())
|
||||
monkeypatch.setattr(dashboard_app, "DashboardApp", FakeDashboardApp)
|
||||
monkeypatch.setattr(dashboard_app, "require_online_license_or_exit", fake_require_online_license_or_exit)
|
||||
|
||||
dashboard_app.main()
|
||||
|
||||
assert os.environ.get("DOUYIN_LICENSE_REQUIRED") == "1"
|
||||
assert calls["required_at_check"] == ""
|
||||
assert calls["app_started"] is True
|
||||
assert calls["initial_page"] == "授权"
|
||||
assert calls["license_locked"] is True
|
||||
assert calls["monitor_started"] is False
|
||||
assert calls["run_called"] is True
|
||||
|
||||
|
||||
def test_dashboard_gui_main_checks_online_license_when_local_license_exists(monkeypatch):
|
||||
from gui.dashboard_app import app as dashboard_app
|
||||
|
||||
calls = {"required_at_check": "", "monitor_started": False, "initial_page": ""}
|
||||
|
||||
class FakeDashboardApp:
|
||||
def __init__(self, *, initial_page="数据看板", license_locked=False) -> None:
|
||||
calls["initial_page"] = initial_page
|
||||
calls["license_locked"] = license_locked
|
||||
|
||||
def _start_license_monitor_once(self) -> None:
|
||||
calls["monitor_started"] = True
|
||||
|
||||
def run(self) -> None:
|
||||
calls["run_called"] = True
|
||||
|
||||
class OkStatus:
|
||||
ok = True
|
||||
|
||||
def fake_require_online_license_or_exit() -> None:
|
||||
calls["required_at_check"] = os.environ.get("DOUYIN_LICENSE_REQUIRED", "")
|
||||
|
||||
monkeypatch.delenv("DOUYIN_LICENSE_REQUIRED", raising=False)
|
||||
monkeypatch.setattr(dashboard_app, "check_license", lambda: OkStatus())
|
||||
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["initial_page"] == "数据看板"
|
||||
assert calls["license_locked"] is False
|
||||
assert calls["monitor_started"] is True
|
||||
assert calls["run_called"] is True
|
||||
|
||||
|
||||
@@ -60,6 +60,30 @@ class _DummyRunner:
|
||||
|
||||
|
||||
def _post(path: str, body: dict, monkeypatch, csrf: str = "token"):
|
||||
class OkStatus:
|
||||
ok = True
|
||||
|
||||
monkeypatch.setattr(routes, "check_license", lambda: OkStatus())
|
||||
handler = _DummyHandler(body=body, csrf_token=csrf)
|
||||
runner = _DummyRunner()
|
||||
u = SimpleNamespace(path=path, query="")
|
||||
routes.handle_post(handler, u, runner, "token")
|
||||
assert handler.calls, f"{path} should produce a response"
|
||||
return handler.calls[-1]
|
||||
|
||||
|
||||
def _post_without_license(path: str, body: dict, monkeypatch, csrf: str = "token"):
|
||||
class MissingStatus:
|
||||
ok = False
|
||||
reason = "missing"
|
||||
message = "缺少授权文件"
|
||||
|
||||
monkeypatch.setattr(routes, "check_license", lambda: MissingStatus())
|
||||
monkeypatch.setattr(
|
||||
routes,
|
||||
"get_license_status_payload",
|
||||
lambda: {"ok": False, "required": True, "reason": "missing", "message": "缺少授权文件"},
|
||||
)
|
||||
handler = _DummyHandler(body=body, csrf_token=csrf)
|
||||
runner = _DummyRunner()
|
||||
u = SimpleNamespace(path=path, query="")
|
||||
@@ -224,6 +248,26 @@ def test_license_install_route_rejects_empty_code(monkeypatch):
|
||||
assert obj["error"] == "missing license_text"
|
||||
|
||||
|
||||
def test_runtime_actions_require_license_but_license_route_stays_available(monkeypatch):
|
||||
calls = []
|
||||
|
||||
def fake_install(*_args, **_kwargs):
|
||||
calls.append("install")
|
||||
return SimpleNamespace(ok=False, reason="bad", message="bad license")
|
||||
|
||||
monkeypatch.setattr(routes, "install_license_or_activate", fake_install)
|
||||
|
||||
status, obj = _post_without_license("/api/start-run", {}, monkeypatch)
|
||||
assert status == 403
|
||||
assert obj["error"] == "license_required"
|
||||
assert obj["reason"] == "missing"
|
||||
|
||||
status, obj = _post_without_license("/api/license", {"license_text": "DG-DEMO"}, monkeypatch)
|
||||
assert status == 400
|
||||
assert obj["reason"] == "bad"
|
||||
assert calls == ["install"]
|
||||
|
||||
|
||||
def test_config_accepts_fudai_detail_v2_ocr_switches_and_ui_mode(monkeypatch):
|
||||
written = {}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ FORBIDDEN_PREFIXES = (
|
||||
)
|
||||
|
||||
FORBIDDEN_EXACT = {
|
||||
"config/config.json",
|
||||
"douyin_guaji.code-workspace",
|
||||
"license.dat",
|
||||
"pyproject.toml",
|
||||
@@ -95,6 +94,11 @@ ALLOWED_ANDROID_TOOLS_FILES = {
|
||||
"android-tools/adbkeyboard.apk",
|
||||
}
|
||||
|
||||
ALLOWED_CONFIG_FILES = {
|
||||
"config/readme.md",
|
||||
"config/config.json",
|
||||
}
|
||||
|
||||
FORBIDDEN_SUFFIXES = (
|
||||
".py",
|
||||
".pyc",
|
||||
@@ -173,6 +177,8 @@ 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 lower.startswith("config/"):
|
||||
return lower not in ALLOWED_CONFIG_FILES
|
||||
if any(lower.startswith(prefix.lower()) for prefix in FORBIDDEN_PREFIXES):
|
||||
return True
|
||||
return any(lower.endswith(suffix) for suffix in FORBIDDEN_SUFFIXES)
|
||||
|
||||
Reference in new issue
Block a user