首次启动弹免责声明,同意后才复制config并继续,不同意则退出
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user