首次启动弹免责声明,同意后才复制config并继续,不同意则退出

This commit is contained in:
2026-05-15 17:48:44 +08:00
parent bdea40ecca
commit f5eb578d38
4 changed files with 63 additions and 4 deletions
+1
View File
@@ -68,6 +68,7 @@ uv run pyinstaller ^
--add-data "config.json;." ^ --add-data "config.json;." ^
--add-data "pickup.ico;." ^ --add-data "pickup.ico;." ^
--add-data "token_bridge;token_bridge" ^ --add-data "token_bridge;token_bridge" ^
--add-data "免责声明.txt;." ^
--hidden-import=openpyxl ^ --hidden-import=openpyxl ^
--hidden-import=requests ^ --hidden-import=requests ^
main.py main.py
+1
View File
@@ -36,6 +36,7 @@ uv run pyinstaller \
--add-data "config.json:." \ --add-data "config.json:." \
--add-data "pickup.ico:." \ --add-data "pickup.ico:." \
--add-data "token_bridge:token_bridge" \ --add-data "token_bridge:token_bridge" \
--add-data "免责声明.txt:." \
--hidden-import=openpyxl \ --hidden-import=openpyxl \
--hidden-import=requests \ --hidden-import=requests \
main.py main.py
+54 -4
View File
@@ -282,16 +282,66 @@ class App:
# ─── 配置管理 ─────────────────────────────────────────── # ─── 配置管理 ───────────────────────────────────────────
def _load_config(self): def _load_config(self):
"""加载配置文件。首次运行时从 _MEIPASS 复制到 exe 目录。""" """加载配置文件。首次运行时弹出免责声明,同意后从 _MEIPASS 复制到 exe 目录。"""
try: try:
self._loading_config = True self._loading_config = True
config_path = _get_config_path() config_path = _get_config_path()
# 打包模式首次运行:从 _MEIPASS 复制 config.json 到可写目录
if getattr(sys, 'frozen', False) and not os.path.exists(config_path): # 首次运行:config.json 不存在,显示免责声明
bundled = os.path.join(sys._MEIPASS, "config.json") if not os.path.exists(config_path):
disclaimer_path = _resource_path("免责声明.txt")
try:
with open(disclaimer_path, "r", encoding="utf-8") as f:
disclaimer_text = f.read()
except Exception:
disclaimer_text = "免责声明文件未找到。使用本软件即表示您同意承担相关责任。"
agreed = [False]
def on_agree():
agreed[0] = True
win.destroy()
def on_disagree():
win.destroy()
win = Toplevel(self.root)
win.title("免责声明")
win.geometry("500x420")
win.transient(self.root)
win.grab_set()
win.resizable(False, False)
Label(win, text="首次启动 — 请阅读免责声明", font=("", 11, "bold"), pady=10).pack()
text_frame = Frame(win)
text_frame.pack(fill="both", expand=True, padx=15, pady=5)
text = Text(text_frame, wrap="word", font=("", 10), state=DISABLED)
text.pack(side="left", fill="both", expand=True)
text.configure(state=NORMAL)
text.insert("1.0", disclaimer_text)
text.configure(state=DISABLED)
btn_frame = Frame(win)
btn_frame.pack(pady=12)
Button(btn_frame, text="同意", command=on_agree, bg="#4CAF50", fg="white",
width=10, height=1).pack(side="left", padx=10)
Button(btn_frame, text="不同意", command=on_disagree, bg="red", fg="white",
width=10).pack(side="left", padx=10)
win.protocol("WM_DELETE_WINDOW", on_disagree)
win.wait_window()
if not agreed[0]:
self.root.destroy()
sys.exit(0)
# 复制默认 config 到可写目录
bundled = _resource_path("config.json")
if os.path.exists(bundled): if os.path.exists(bundled):
import shutil import shutil
shutil.copy2(bundled, config_path) shutil.copy2(bundled, config_path)
self.config = load_config(config_path) self.config = load_config(config_path)
timing = get_timing_config(self.config) timing = get_timing_config(self.config)
delay_ms = timing.get("delay_between_rows_ms", 500) delay_ms = timing.get("delay_between_rows_ms", 500)
+7
View File
@@ -0,0 +1,7 @@
【免责声明】
本软件由个人开发者(以下简称“开发者”)开发,并按“现状”(AS IS)提供。
开发者不承担任何明示或默示的担保,包括但不限于对适销性、特定用途适用性及不侵权的默示担保。
在任何情况下,开发者均不对因使用或无法使用本软件所产生的任何直接、间接、附带、特殊或后果性损失或损害(包括但不限于业务中断、数据丢失、利润损失等)承担责任,即使开发者已被告知发生此类损害的可能性。
用户使用本软件即视为已阅读并同意本声明,并自行承担全部使用风险。
点击"同意"即表示您已阅读并接受以上条款。