mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-19 08:20:44 +00:00
1.7.0:常规发布
- 版本号 1.7.0 -> 1.7.0 - 重建三端并打包 - 关键测试全过
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
--status 打印状态后退出
|
||||
--port 9000 指定端口
|
||||
--new-code 换一组配对码
|
||||
--code 123456 把配对码设成指定值(安装包用)
|
||||
--name "三年二班" 设置电脑在手表上显示的名字
|
||||
--reset-devices 清空已配对设备
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -45,6 +47,12 @@ def parse_args(argv=None):
|
||||
prog="lanremote-agent", description=f"{APP_NAME} v{__version__}")
|
||||
parser.add_argument("--port", type=int, help="监听端口(默认 8765)")
|
||||
parser.add_argument("--new-code", action="store_true", help="换一组配对码")
|
||||
parser.add_argument("--code", default=None, metavar="6位数字",
|
||||
help="把配对码设成指定值(必须是 6 位数字)。"
|
||||
"安装包用这个把用户在安装向导里填的码写进去。")
|
||||
parser.add_argument("--name", default=None, metavar="名字",
|
||||
help="设置这台电脑在手表上显示的名字"
|
||||
"(默认用 Windows 的计算机名)")
|
||||
parser.add_argument("--reset-devices", action="store_true", help="清空已配对设备")
|
||||
parser.add_argument("--silent", action="store_true",
|
||||
help="全静默运行:没有任何窗口,也没有终端")
|
||||
@@ -602,6 +610,42 @@ def main(argv=None) -> int:
|
||||
|
||||
args = parse_args(argv)
|
||||
|
||||
# --code / --name 要**最先**处理 —— 它们会改配置,
|
||||
# 而 --status / --autostart 这些是"看一眼就退出"的命令。
|
||||
# 安装包的调用链是:
|
||||
# ykxmz.exe --code 789113 --name 三年二班 --autostart on --silent
|
||||
# 如果先把 --autostart 处理掉就 return 了,配对码根本写不进去。
|
||||
if args.code is not None or args.name:
|
||||
store = Store(data_dir())
|
||||
wrote = False
|
||||
if args.code is not None:
|
||||
digits = "".join(ch for ch in str(args.code) if ch.isdigit())
|
||||
if len(digits) != 6:
|
||||
print(f"配对码要 6 位数字,收到的是 {args.code!r}")
|
||||
return 2
|
||||
try:
|
||||
store.set_pairing_code(digits)
|
||||
except ValueError as exc:
|
||||
print(f"设置配对码失败:{exc}")
|
||||
return 2
|
||||
# 装完就算"设置好了",不要再弹设置窗口
|
||||
store.set("setup_done", True)
|
||||
store.set("allow_new_pairing", True)
|
||||
print(f"配对码已设为 {digits}")
|
||||
wrote = True
|
||||
if args.name:
|
||||
store.set("name", str(args.name).strip()[:32])
|
||||
print(f"电脑名已设为 {store.get('name')}")
|
||||
wrote = True
|
||||
|
||||
# 只写了配置就结束 —— 这是一次性命令。
|
||||
# 不加这个 return 的话会继续走到 run_silent(),
|
||||
# 变成常驻进程永不返回,调用方(安装程序)会一直等下去。
|
||||
# 想顺便启动服务,显式加 --silent。
|
||||
if wrote and not (args.silent or args.add_device is not None
|
||||
or args.setup):
|
||||
return 0
|
||||
|
||||
if args.autostart:
|
||||
return cli_autostart(args.autostart)
|
||||
if args.status:
|
||||
@@ -629,6 +673,28 @@ def main(argv=None) -> int:
|
||||
if args.reset_devices:
|
||||
store.devices = {}
|
||||
store.save_devices()
|
||||
|
||||
# --code:把配对码设成安装向导里填的那个。
|
||||
# 严格要 6 位数字 —— 和设置窗口里的规则一致,
|
||||
# 免得用户装了之后发现手表上少输一位连不上。
|
||||
if args.code is not None:
|
||||
digits = "".join(ch for ch in str(args.code) if ch.isdigit())
|
||||
if len(digits) != 6:
|
||||
print(f"配对码要 6 位数字,收到的是 {args.code!r}")
|
||||
return 2
|
||||
try:
|
||||
store.set_pairing_code(digits)
|
||||
except ValueError as exc:
|
||||
print(f"设置配对码失败:{exc}")
|
||||
return 2
|
||||
# 装完就是"设置好了",不要再弹设置窗口
|
||||
store.set("setup_done", True)
|
||||
store.set("allow_new_pairing", True)
|
||||
print(f"配对码已设为 {digits}")
|
||||
|
||||
if args.name:
|
||||
store.set("name", str(args.name).strip()[:32])
|
||||
|
||||
if args.new_code or not store.pairing_code():
|
||||
store.new_pairing_code()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user