Fix activation dialog: pin confirm buttons at bottom so they stay visible.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-17 19:56:47 +08:00
parent accdab9499
commit 90232cfaa3
2 changed files with 43 additions and 29 deletions
+40 -26
View File
@@ -11,14 +11,13 @@ from device_store import load_device, machine_fingerprint
def _bring_front(win: tk.Misc) -> None: def _bring_front(win: tk.Misc) -> None:
"""确保对话框在 Windows 上可见(避免挂在 withdraw 根窗后不显示)。"""
try: try:
win.update_idletasks() win.update_idletasks()
win.deiconify() win.deiconify()
win.lift() win.lift()
win.focus_force() win.focus_force()
win.attributes("-topmost", True) win.attributes("-topmost", True)
win.after(200, lambda: win.attributes("-topmost", False)) win.after(250, lambda: win.attributes("-topmost", False))
except Exception: except Exception:
pass pass
@@ -27,15 +26,10 @@ def ensure_activated(parent: Optional[tk.Misc] = None) -> bool:
"""已激活且能 ping 通则通过;否则弹出激活窗。返回是否可继续。""" """已激活且能 ping 通则通过;否则弹出激活窗。返回是否可继续。"""
device = load_device() device = load_device()
owns_root = False owns_root = False
root: tk.Misc
if parent is not None: if parent is not None:
root = parent root = parent
else: else:
root = tk.Tk() root = tk.Tk()
root.title("黄金市价辅助")
root.geometry("360x80")
ttk.Label(root, text="正在启动…").pack(expand=True, padx=16, pady=16)
root.update()
owns_root = True owns_root = True
try: try:
@@ -50,31 +44,46 @@ def ensure_activated(parent: Optional[tk.Misc] = None) -> bool:
): ):
return True return True
# 单独可见窗口,避免「正在启动」残窗 + 按钮被裁切
if owns_root:
win = root
else:
win = tk.Toplevel(root) win = tk.Toplevel(root)
win.title("激活黄金辅助") win.title("激活黄金辅助")
win.geometry("480x300") win.minsize(520, 420)
win.resizable(False, False) win.geometry("520x420")
# 不要 transient 到已隐藏的父窗,否则 Windows 上常不显示 win.resizable(True, True)
result = {"ok": False} result = {"ok": False}
frm = ttk.Frame(win, padding=16) # 底部按钮区先占位,保证高 DPI 下仍可见
frm.pack(fill=tk.BOTH, expand=True) btn_bar = ttk.Frame(win, padding=(16, 10, 16, 16))
btn_bar.pack(side=tk.BOTTOM, fill=tk.X)
ttk.Label(frm, text="首次使用请输入中控地址与激活码(网页下载中心生成)").pack(anchor="w") body = ttk.Frame(win, padding=16)
ttk.Label(frm, text="服务器地址(例:http://192.168.1.10:5800)").pack(anchor="w", pady=(12, 4)) body.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
ttk.Label(
body,
text="首次使用请输入中控地址与激活码(网页下载中心生成)",
wraplength=470,
).pack(anchor="w")
ttk.Label(body, text="服务器地址(例:http://192.168.1.10:5800)").pack(
anchor="w", pady=(14, 4)
)
var_server = tk.StringVar(value=device.get("server") or "http://127.0.0.1:5800") var_server = tk.StringVar(value=device.get("server") or "http://127.0.0.1:5800")
ttk.Entry(frm, textvariable=var_server, width=48).pack(fill=tk.X) ttk.Entry(body, textvariable=var_server).pack(fill=tk.X, ipady=3)
ttk.Label(frm, text="激活码").pack(anchor="w", pady=(12, 4)) ttk.Label(body, text="激活码").pack(anchor="w", pady=(12, 4))
var_code = tk.StringVar() var_code = tk.StringVar()
ttk.Entry(frm, textvariable=var_code, width=48).pack(fill=tk.X) ttk.Entry(body, textvariable=var_code).pack(fill=tk.X, ipady=3)
ttk.Label(frm, text="本机名称(可改)").pack(anchor="w", pady=(12, 4)) ttk.Label(body, text="本机名称(可改)").pack(anchor="w", pady=(12, 4))
var_name = tk.StringVar(value=device.get("machine_name") or "") var_name = tk.StringVar(value=device.get("machine_name") or "")
ttk.Entry(frm, textvariable=var_name, width=48).pack(fill=tk.X) ttk.Entry(body, textvariable=var_name).pack(fill=tk.X, ipady=3)
status = ttk.Label(frm, text="", foreground="#888") status = ttk.Label(body, text="", foreground="#888")
status.pack(anchor="w", pady=(10, 0)) status.pack(anchor="w", pady=(14, 0))
def do_skip(): def do_skip():
result["ok"] = True result["ok"] = True
@@ -86,6 +95,8 @@ def ensure_activated(parent: Optional[tk.Misc] = None) -> bool:
if not server or not code: if not server or not code:
status.configure(text="请填写服务器与激活码", foreground="#f6465d") status.configure(text="请填写服务器与激活码", foreground="#f6465d")
return return
status.configure(text="正在激活…", foreground="#888")
win.update_idletasks()
try: try:
hub_client.activate( hub_client.activate(
server, code, machine_fingerprint(), var_name.get().strip() or "PC" server, code, machine_fingerprint(), var_name.get().strip() or "PC"
@@ -98,19 +109,22 @@ def ensure_activated(parent: Optional[tk.Misc] = None) -> bool:
except hub_client.HubError as exc: except hub_client.HubError as exc:
status.configure(text=str(exc), foreground="#f6465d") status.configure(text=str(exc), foreground="#f6465d")
btns = ttk.Frame(frm) ttk.Button(btn_bar, text="离线使用", command=do_skip).pack(side=tk.LEFT, ipadx=8, ipady=4)
btns.pack(fill=tk.X, pady=(16, 0)) ttk.Button(btn_bar, text="确认激活", command=do_ok).pack(side=tk.RIGHT, ipadx=12, ipady=4)
ttk.Button(btns, text="离线使用", command=do_skip).pack(side=tk.LEFT) win.bind("<Return>", lambda _e: do_ok())
ttk.Button(btns, text="激活", command=do_ok).pack(side=tk.RIGHT)
win.protocol("WM_DELETE_WINDOW", do_skip) win.protocol("WM_DELETE_WINDOW", do_skip)
_bring_front(win) _bring_front(win)
try:
win.grab_set() win.grab_set()
root.wait_window(win) except Exception:
pass
win.wait_window()
return result["ok"] return result["ok"]
finally: finally:
if owns_root: if owns_root:
try: try:
if root.winfo_exists():
root.destroy() root.destroy()
except Exception: except Exception:
pass pass
Binary file not shown.