mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-19 08:20:44 +00:00
修用户报的三个问题 + 揪出我自己检查工具的盲区
用户报:
1. 官网 502
2. 局域网连接:输入配对码提示连上了但没反应,得推出去点设备才能连
3. 被控端安装时要能设中转服务器;之后双击 exe 也该能改配对码 /
开关新设备 / 中转地址 —— 但现在双击没反应
────────────────────────────────────────
问题 1:502(暂态,已恢复)
────────────────────────────────────────
你截图是 21:24:56,隧道日志显示 21:22:51 和 21:26:44 各重启了一次
—— 502 就发生在那个空窗里。现在三个服务都 active、10 条连接、
本机 200(3ms)、公网 200(2.6s)。
(重启是谁触发的还没查清,watchdog 的嫌疑最大,下一轮跟进。)
────────────────────────────────────────
问题 2:局域网连上后没反应(真 bug,已修)
────────────────────────────────────────
手表上有**四个**面板,靠手工 setVisibility 切换:
connectPanel 首页
controlPanel 控制面板
mirrorPanel 投屏
lanPanel 局域网连接页 <- 后加的
而 showControlPanel() 只藏了前两个:
connectPanel.setVisibility(GONE);
controlPanel.setVisibility(VISIBLE);
if (mirrorPanel != null) mirrorPanel.setVisibility(GONE);
// lanPanel 没藏!
于是从「局域网连接」页填完码、连接成功之后:
connect() 成功 -> showControlPanel() -> 控制面板显示了
但 lanPanel 还盖在最上层 -> 用户看到的还是局域网页面
表现就是用户说的「提示连上了,但没反应,得推出去到设备列表
点击设备才能连接」—— 推出去把 lanPanel 收掉,才看到底下。
**根子在于"每处切换都手写一串 setVisibility"**,加第四个面板时
必然漏。改成统一入口:
private void showOnly(View keep) // 藏掉所有面板,只留一个
6 个切换点全部走它。以后加面板只要在 showOnly 里加一行。
────────────────────────────────────────
问题 3:双击 exe 没反应(功能缺失,已补)
────────────────────────────────────────
原来是两件事叠在一起:
**3a. 装完之后双击永远静默**(main() 最后几行)
if not store.get("setup_done", False):
return run_setup(store)
return run_silent(store, None) # <- 什么都不弹
改成:没参数 + 已设置过 -> **打开设置窗口**。
后台运行走显式 --silent(开机自启和安装包都用它,不受影响)。
**3b. 设置窗口里没有中转服务器**
SetupWindow 原来只有 配对码 / 开机自启 / 放行防火墙。
现在加了:
* 中转服务器地址(可不填;只在一个 WiFi 里用就不需要)
* 允许新设备接入(开关,只在"设置"模式给)
并且给 SetupWindow 加了 mode:
"first" 第一次设置(防火墙 + 自启 + 转静默,老行为不变)
"settings" 已装好,只改配置
**3c. 顺带修了一个会静默失败的东西**
改完发现打包出来的 exe 一跑就 ModuleNotFoundError:
No module named 'lanremote.ui' —— **PyInstaller 的 --hidden-import
里没有 ui**。它是 tkinter 那套设置窗口的实现,而静默那条路
不需要它,静态分析就找不到。源码跑得好好的,只有 exe 会崩。
已加 --hidden-import "lanremote.ui",并写了
_tests/test_double_click_window.py 针对**打包好的 exe** 验:
✅ 进程没崩 / 窗口弹出来了 / 标题是「ykxmz · 设置」
────────────────────────────────────────
额外揪出来的:我的检查工具一直在骗我
────────────────────────────────────────
反复被同一个问题咬了三次:补丁脚本为了加 import os / import re,
把它插到了 `from __future__` 前面,整个文件语法错。
而**我前面几次说的「全仓语法检查 0 个问题」是假绿**:
ast.parse(src) -> 通过(只解析,不做编译期检查)
compile(src, ...) -> SyntaxError: from __future__ imports
must occur at the beginning of the file
`__future__` 的位置是**编译期**检查,ast.parse 根本不管。
所以改成用 compile(),并写成
_tests/check_python_syntax.py(回归阶段 3a7),
它还会专门把"ast.parse 会放过、compile 会拦"的文件标出来。
实测:全仓 533 个文件,用 compile() 扫出 1 个坏的(ui.py),
而它正是让"双击没反应"的最后一个原因。
────────────────────────────────────────
还有一个重要发现
────────────────────────────────────────
**你一直在跑的是 10-06 的旧 exe**:
C:\Users\shu\Desktop\ykxmz\ykxmz.exe 10-06 17:43 <- 你双击的这个
LanRemote\dist_exe\ykxmz\ykxmz.exe 10-07 21:5x <- 修复都在这
它的 silent.log 正在反复报:
[21:15:59] 连接断了,重开一次再试(The read operation timed out)
[21:16:42] 中转连接出问题:RelayError: 请求失败: ...
[21:18:34] 已登记到中转:配对码 111111
这就是我修的那个 126 秒长轮询问题 —— 旧版超时太短反复掉线。
新版把客户端超时改成 180 秒了。
**所以这三个修复要装上新版才生效。**
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
r'''全仓语法检查 —— 必须用 compile(),不能用 ast.parse()。
|
||||
|
||||
== 为什么这个文件存在 ==
|
||||
|
||||
我这一轮反复被同一个问题咬:
|
||||
|
||||
Python 要求 `from __future__ import ...` 是文件里第一条语句。
|
||||
我的补丁脚本为了加 `import os` / `import re`,把它插到了
|
||||
`from __future__` **前面**,整个文件就废了。
|
||||
|
||||
而更糟的是**我的检查工具查不出来**:
|
||||
|
||||
ast.parse(src) -> 通过(它只解析,不做编译期检查)
|
||||
compile(src, ...) -> SyntaxError: from __future__ imports
|
||||
must occur at the beginning of the file
|
||||
|
||||
我前面几次"全仓语法检查 0 个问题"就是这么来的假绿。
|
||||
真正的症状是:
|
||||
|
||||
* 源码直接跑 -> 启动就崩
|
||||
* 打包成 exe -> 走到那个模块才崩,用户看到"双击没反应"
|
||||
|
||||
所以这个脚本用 **compile()** 扫全仓,并且专门把
|
||||
"只被 ast.parse 放过、但 compile 会拦" 的文件标出来。
|
||||
|
||||
进回归套件之后,任何脚本再犯一次,全量回归立刻红。
|
||||
'''
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
PATTERNS = ["_tests/*.py", "_build/*.py", "relay/*.py", "windows/*.py",
|
||||
"windows/lanremote/*.py", "installer/*.py"]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
files = []
|
||||
for pat in PATTERNS:
|
||||
files += sorted(ROOT.glob(pat))
|
||||
|
||||
bad = []
|
||||
sneaky = [] # ast.parse 放过、compile 拦下的(就是这次的坑)
|
||||
n = 0
|
||||
for f in files:
|
||||
if not f.is_file():
|
||||
continue
|
||||
n += 1
|
||||
try:
|
||||
src = f.read_text(encoding="utf-8")
|
||||
except Exception: # noqa: BLE001
|
||||
continue
|
||||
try:
|
||||
compile(src, str(f), "exec")
|
||||
except SyntaxError as exc:
|
||||
bad.append((f.relative_to(ROOT), exc.lineno, exc.msg))
|
||||
# 看看 ast.parse 是不是会放过它
|
||||
try:
|
||||
ast.parse(src)
|
||||
sneaky.append(f.relative_to(ROOT))
|
||||
except SyntaxError:
|
||||
pass
|
||||
|
||||
print(" 用 compile() 检查 %d 个文件" % n)
|
||||
if not bad:
|
||||
print(" ✓ 全部通过")
|
||||
return 0
|
||||
|
||||
print(" ✗ %d 个文件有语法错:" % len(bad))
|
||||
for rel, ln, msg in bad:
|
||||
print(" %s: 第 %s 行 %s" % (rel, ln, msg))
|
||||
if sneaky:
|
||||
print()
|
||||
print(" ⚠ 下面这些 **ast.parse 会放过**(所以以前的检查是假绿):")
|
||||
for rel in sneaky:
|
||||
print(" %s" % rel)
|
||||
print(" -> 以后一律用 compile(),别再用 ast.parse() 当语法检查。")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,130 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
r'''验证「双击 exe 会打开设置窗口」。
|
||||
|
||||
== 为什么要专门测这个 ==
|
||||
|
||||
这条路上踩了两个坑,而且**都是静默失败**(用户只看到"双击没反应"):
|
||||
|
||||
1. run_agent.py 的 main() 里,装完之后无参数直接 run_silent
|
||||
-> 什么都不弹(代码层面的行为问题)
|
||||
2. 改成弹窗口之后,PyInstaller 的 --hidden-import 里没有 lanremote.ui
|
||||
-> exe 里根本没有 tkinter 那套代码,一跑就
|
||||
ModuleNotFoundError,进程立刻退出(打包层面的问题)
|
||||
|
||||
第 2 个尤其阴:**源码跑得好好的,只有打包出来的 exe 才会崩**。
|
||||
所以这个测试必须针对**打包好的 exe** 跑,不能只跑源码。
|
||||
'''
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
EXE = ROOT / "dist_exe" / "ykxmz" / "ykxmz.exe"
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
|
||||
|
||||
def check(name, ok, detail=""):
|
||||
global passed, failed
|
||||
if ok:
|
||||
passed += 1
|
||||
print(" [PASS] " + name)
|
||||
else:
|
||||
failed += 1
|
||||
print(" [FAIL] " + name + ((" —— " + str(detail)) if detail else ""))
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print("=" * 58)
|
||||
print(" 双击 exe 要能弹出设置窗口")
|
||||
print("=" * 58)
|
||||
|
||||
check("打包好的 exe 存在", EXE.is_file(), EXE)
|
||||
if not EXE.is_file():
|
||||
return 1
|
||||
|
||||
work = Path(tempfile.mkdtemp(prefix="uiwin_"))
|
||||
data = work / "data"
|
||||
data.mkdir(parents=True, exist_ok=True)
|
||||
# 造一个"已经装好"的配置 —— 这正是用户双击时的状态
|
||||
(data / "settings.json").write_text(json.dumps({
|
||||
"port": 8765, "server_name": "TEST-PC", "setup_done": True,
|
||||
"allow_new_pairing": True, "pairing_code": "123456",
|
||||
"pairing_created": 0, "relay_url": "",
|
||||
}, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
import os
|
||||
env = dict(os.environ)
|
||||
env["YKXMZ_DATA"] = str(data)
|
||||
env["YKXMZ_LOCK_PORT"] = "19931" # 避开用户自己的实例
|
||||
|
||||
print(" ── 启动 exe(无参数)──")
|
||||
out = open(work / "out.txt", "wb")
|
||||
proc = subprocess.Popen([str(EXE)], env=env, cwd=str(EXE.parent),
|
||||
stdout=out, stderr=subprocess.STDOUT)
|
||||
time.sleep(12)
|
||||
|
||||
if proc.poll() is not None:
|
||||
out.close()
|
||||
text = (work / "out.txt").read_text(encoding="utf-8", errors="replace")
|
||||
check("进程没有立刻退出", False,
|
||||
"退出码 %s;输出:%s" % (proc.returncode, text[-400:]))
|
||||
# 特别指出 hiddenimports 这个坑
|
||||
if "lanremote.ui" in text or "No module named" in text:
|
||||
print(" ↑ 这就是 --hidden-import 漏了 lanremote.ui 的典型症状")
|
||||
return 1
|
||||
|
||||
check("进程活着(没崩)", True)
|
||||
|
||||
# 有没有窗口:让 PowerShell 把标题**写进文件**再读。
|
||||
# ⚠ 不能直接读 stdout —— Windows 控制台默认不是 UTF-8,
|
||||
# 中文标题会变成乱码(实测 "ykxmz · 设置" 读成 "ykxmz �� ����"),
|
||||
# 于是"标题里带设置"这条会假失败。
|
||||
try:
|
||||
title_file = work / "title.txt"
|
||||
subprocess.run(
|
||||
["powershell", "-NoProfile", "-Command",
|
||||
"[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; "
|
||||
"(Get-Process -Id %d).MainWindowTitle | "
|
||||
"Set-Content -Encoding UTF8 -Path '%s'"
|
||||
% (proc.pid, str(title_file).replace("'", "''"))],
|
||||
capture_output=True, timeout=20)
|
||||
title = ""
|
||||
if title_file.is_file():
|
||||
title = title_file.read_text(encoding="utf-8-sig").strip()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
title = ""
|
||||
print(" (读窗口标题失败:%s)" % exc)
|
||||
|
||||
print(" 窗口标题: %r" % title)
|
||||
check("弹出了窗口(MainWindowTitle 非空)", bool(title),
|
||||
"标题是空的 —— 窗口没弹出来")
|
||||
|
||||
if title:
|
||||
check("标题里带「设置」", "设置" in title, title)
|
||||
|
||||
# 收尾
|
||||
try:
|
||||
proc.terminate()
|
||||
proc.wait(timeout=6)
|
||||
except Exception: # noqa: BLE001
|
||||
try:
|
||||
proc.kill()
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
out.close()
|
||||
|
||||
print()
|
||||
print("=" * 58)
|
||||
print(" 通过 %d 项,失败 %d 项" % (passed, failed))
|
||||
return 0 if failed == 0 else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -404,6 +404,15 @@ $stageOut = & python (Join-Path $root "_tests\check_encoding.py") 2>&1
|
||||
Show-Fails $stageOut
|
||||
Record "编码与换行" ($LASTEXITCODE -eq 0)
|
||||
|
||||
# ---------------------------------------------------------------- 3a7
|
||||
Banner "3a7/7 Python 语法(必须用 compile,不能用 ast.parse)"
|
||||
# 这一轮被同一件事咬了三次:补丁脚本把 import 插到 from __future__
|
||||
# 前面,整个文件就废了。而更糟的是 ast.parse 查不出来(它只解析,
|
||||
# 不做编译期检查)—— 前几次「全仓语法检查 0 问题」都是假绿。
|
||||
= & python (Join-Path "_tests\check_python_syntax.py") 2>&1
|
||||
Show-Fails
|
||||
Record "Python 语法检查" ( -eq 0)
|
||||
|
||||
# ---------------------------------------------------------------- 3a5
|
||||
Banner "3a5/7 局域网/中转对比基准(防测试自己骗人)"
|
||||
# 这个基准一度是红的,而且报告里写着「这是中转链路的产品 bug」——
|
||||
|
||||
Reference in New Issue
Block a user