Files
ykxmz/_build/patch_bake_defaults.py
T
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

140 lines
5.7 KiB
Python
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.
# -*- coding: utf-8 -*-
"""开箱即用:把中转地址内置进两端,用户不用配任何地址。
用户的要求:
"所有东西做完以后,你先给我连接我的那个随身 WiFi,
然后帮我把所有东西配置好,这样子到时候你给我三端的所有东西,
我只需要在手表上安装完控制软件,然后在不同电脑上运行电脑端代码就可以进行了"
也就是:
电脑上双击 exe -> 自动连上随身 WiFi 上的中转
手表上装完 apk -> 自动连上同一个中转
用户一个地址都不用填。
做法:
被控端:relay_url 没设过时,用一个内置默认值:
192.168.2.156:8080;https://relay.xxmxxs.top
局域网优先(快、稳、地址不变),不在同一网络时自动走隧道。
手表端:中转地址默认填 https://relay.xxmxxs.top
注意:**只是默认值**,用户照样能在设置里改。不是写死。
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
SERVER = ROOT / "windows" / "lanremote" / "server.py"
RUN = ROOT / "windows" / "run_agent.py"
MAIN = ROOT / "android" / "src" / "com" / "lanremote" / "watch" / "MainActivity.java"
DEFAULT_RELAY = "192.168.2.156:8080;https://relay.xxmxxs.top"
TUNNEL_ONLY = "https://relay.xxmxxs.top"
# ---------- 被控端:server.py 里给默认值 ----------
SRV_OLD = ''' target = (url or "").strip() or str(self.store.get("relay_url") or "")
if not target.strip():
return False'''
SRV_NEW = ''' target = (url or "").strip() or str(self.store.get("relay_url") or "")
if not target.strip():
# 没配过就用内置默认值 —— 开箱即用,用户不用填地址。
# 局域网优先(快、稳、地址不会变),不在同一网络时自动走隧道。
# (只是默认值,用户随时能在设置里改成别的。)
target = DEFAULT_RELAY_URL
self._log(f"没配过中转地址,用内置默认值:{target}")'''
SRV_CONST_ANCHOR = '''# 跨网络中转链路(配了 relay_url 才会启用)'''
SRV_CONST = '''# 内置的中转地址。没配过就用它,这样电脑端跑起来就能连,
# 用户一个地址都不用填。
#
# 为什么是两个并用分号隔开:
# 随身 WiFi 和电脑经常在同一个局域网 -> 走第一个(局域网直连,
# 几十毫秒,而且地址永远不变)
# 电脑在外面 -> 第一个连不上,自动切第二个(Cloudflare 隧道,
# 600 毫秒左右,地址固定 relay.xxmxxs.top)
DEFAULT_RELAY_URL = "192.168.2.156:8080;https://relay.xxmxxs.top"
# 跨网络中转链路(配了 relay_url 才会启用)'''
# ---------- 被控端:run_agent.py 的状态输出里显示用的是哪个 ----------
RUN_OLD = ''' url = str(store.get("relay_url") or "")'''
RUN_NEW = ''' url = str(store.get("relay_url") or "") or "192.168.2.156:8080;https://relay.xxmxxs.top"'''
# ---------- 手表端:默认中转地址 ----------
WATCH_OLD = ''' private String relayUrl() {'''
WATCH_NEW = ''' /**
* 内置的默认中转地址。
*
* 服务器端已经架在随身 WiFi 上并用 Cloudflare 隧道暴露成
* relay.xxmxxs.top,所以手表装完不用填任何地址就能连。
* 用户在「中转设置」里随时能改。
*/
private static final String DEFAULT_RELAY_URL = "https://relay.xxmxxs.top";
private String relayUrl() {'''
def patch(path: Path, pairs, label: str) -> bool:
text = path.read_text(encoding="utf-8")
ok = True
for old, new, tag in pairs:
if old not in text:
print(f" [{label}] [跳过] {tag} —— 锚点没找到")
ok = False
continue
text = text.replace(old, new, 1)
print(f" [{label}] {tag}")
path.write_text(text, encoding="utf-8", newline="\n")
return ok
def main() -> int:
ok = True
ok &= patch(SERVER, [(SRV_CONST_ANCHOR, SRV_CONST, "加 DEFAULT_RELAY_URL 常量"),
(SRV_OLD, SRV_NEW, "没配过就用默认值")], "被控端")
ok &= patch(RUN, [(RUN_OLD, RUN_NEW, "status 显示默认值")], "CLI")
ok &= patch(MAIN, [(WATCH_OLD, WATCH_NEW, "加 DEFAULT_RELAY_URL 常量")],
"手表")
# 手表:relayUrl() 里读不到就用默认
text = MAIN.read_text(encoding="utf-8")
import re
match = re.search(r" private String relayUrl\(\) \{\n(.{0,400}?)\n \}",
text, re.S)
if match:
body = match.group(1)
if "DEFAULT_RELAY_URL" not in body:
new_body = body.replace(
'prefs.getString("relay_url", "")',
'prefs.getString("relay_url", DEFAULT_RELAY_URL)')
if new_body == body:
# 可能用的是别的 key / 写法
new_body = re.sub(r'prefs\.getString\("relay_url",\s*[^)]*\)',
'prefs.getString("relay_url", DEFAULT_RELAY_URL)',
body)
if new_body != body:
text = text.replace(body, new_body, 1)
MAIN.write_text(text, encoding="utf-8", newline="\n")
print(" [手表] relayUrl() 用上了默认值")
else:
print(" [手表] [需要手工看] relayUrl() 里的写法没匹配上")
print(" " + body.strip().splitlines()[0][:70])
else:
print(" [手表] relayUrl() 已经有默认值")
else:
print(" [手表] [失败] 找不到 relayUrl() 方法体")
ok = False
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())