Files
ykxmz/windows/build_exe.ps1
T
xmz7891 b76014709e 修用户报的三个问题 + 揪出我自己检查工具的盲区
用户报:
  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 秒了。

**所以这三个修复要装上新版才生效。**
2026-10-07 21:38:22 +08:00

59 lines
2.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 把 Windows 被控端打包成「多文件 EXE」(PyInstaller --onedir)
# 用法: powershell -ExecutionPolicy Bypass -File windows\build_exe.ps1
#
# 产物: dist_exe\ykxmz\
# ├─ ykxmz.exe <- 双击运行
# └─ _internal\ <- 依赖
#
# 刻意使用 --onedir 而不是 --onefile:
# * 启动不解压临时文件,秒开(双击就弹窗口)
# * 依赖可见、可查杀、可替换,方便做安装包
#
# 注意:本版本**不再使用系统托盘**(pystray 已移除),
# 关窗后进程继续运行,靠单实例机制再次双击找回窗口。
$ErrorActionPreference = "Continue"
$windows = $PSScriptRoot # LanRemote/windows
$root = Split-Path -Parent $windows # LanRemote
Write-Host "=== 1/3 生成图标 ===" -ForegroundColor Cyan
& python (Join-Path $root "_build\make_ico.py")
if ($LASTEXITCODE -ne 0) { throw "生成图标失败" }
$ico = Join-Path $windows "app.ico"
Write-Host "`n=== 2/3 PyInstaller 打包(--onedir 多文件)===" -ForegroundColor Cyan
# ⚠ lanremote.ui 必须显式 --hidden-import(见下面那行)。
# 它是"设置窗口"(tkinter)的实现,而静默那条路不需要它,
# PyInstaller 静态分析就找不到 —— 于是双击 exe 想弹设置窗口时
# 会 ModuleNotFoundError: No module named 'lanremote.ui',
# 进程直接退出,用户看到的就是"双击没反应"。
# (PS 的续行符 ` 后面不能再跟 # 注释,所以说明写在这里。)
& python -m PyInstaller --noconfirm --clean --onedir --windowed `
--name "ykxmz" `
--icon "$ico" `
--paths "$windows" `
--hidden-import "PIL._tkinter_finder" `
--hidden-import "lanremote.netcheck" `
--hidden-import "lanremote.features" `
--hidden-import "lanremote.headless" `
--hidden-import "lanremote.ui" `
--version-file (Join-Path $windows "version_info.txt") `
--noupx `
--exclude-module "pystray" `
--exclude-module "numpy" `
--exclude-module "psutil" `
--distpath (Join-Path $root "dist_exe") `
--workpath (Join-Path $root "_build\pyinstaller_work") `
--specpath (Join-Path $root "_build") `
(Join-Path $windows "run_agent.py") 2>&1 | Select-Object -Last 4
$target = Join-Path $root "dist_exe\ykxmz\ykxmz.exe"
if (-not (Test-Path $target)) { throw "打包失败:未生成 $target" }
Write-Host "`n=== 3/3 产物 ===" -ForegroundColor Cyan
Write-Host "目录: $(Split-Path -Parent $target)"
Write-Host ("exe : {0:N1} MB" -f ((Get-Item $target).Length / 1MB))
$all = Get-ChildItem (Split-Path -Parent $target) -Recurse -File
Write-Host ("总计: {0} 个文件, {1:N1} MB" -f $all.Count, (($all | Measure-Object Length -Sum).Sum / 1MB))
Write-Host "`n完成" -ForegroundColor Green