Files
ykxmz/_build/patch_watch_ui.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

171 lines
6.6 KiB
Python

# -*- coding: utf-8 -*-
"""手表端加两个入口:
1. 「回退」按钮(系统页最上面)—— 对应电脑端的 undo_last
2. 「中转地址」设置 —— 跨网络用,填了就走中转,留空走局域网
中转地址存 SharedPreferences,连不上时界面能提示是没配中转。
"""
from __future__ import annotations
import sys
from pathlib import Path
MAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\android\src"
r"\com\lanremote\watch\MainActivity.java")
# ---------------- 1. 系统页加回退按钮 ----------------
SYSTEM_OLD = ''' new TabDef("系统", new Act[]{
act("锁屏", new Runnable() {'''
SYSTEM_NEW = ''' new TabDef("系统", new Act[]{
act("回退上一步", new Runnable() {
public void run() {
runFeature("undo_last", Json.obj(), "回退上一步");
}
}),
act("回退全部", new Runnable() {
public void run() {
runFeature("undo_all", Json.obj(), "回退全部");
}
}),
act("看能回退什么", new Runnable() {
public void run() {
runFeature("undo_list", Json.obj(), "可回退的操作");
}
}),
act("锁屏", new Runnable() {'''
# ---------------- 2. 中转地址设置项 ----------------
RELAY_FIELD_ANCHOR = " private static final String PREF_TARGET = "
RELAY_HELPERS = ''' /** 中转服务器地址(跨网络用)。空 = 只走局域网。 */
private String relayUrl() {
return getSharedPreferences("lanremote", MODE_PRIVATE)
.getString("relay_url", "");
}
private void setRelayUrl(String url) {
getSharedPreferences("lanremote", MODE_PRIVATE).edit()
.putString("relay_url", url == null ? "" : url.trim())
.apply();
}
/** 让用户填中转地址。填了就能跨网络控制。 */
private void promptRelayUrl() {
final EditText input = new EditText(this);
input.setHint("https://relay.你的域名");
input.setText(relayUrl());
input.setTextColor(C_FG);
input.setHintTextColor(C_DIM);
input.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
input.setSingleLine(true);
input.setBackground(rounded(C_CARD, 7));
input.setPadding(dp(10), dp(10), dp(10), dp(10));
LinearLayout box = new LinearLayout(this);
box.setOrientation(LinearLayout.VERTICAL);
box.setPadding(dp(14), dp(8), dp(14), dp(4));
TextView hint = new TextView(this);
hint.setText("填了就走中转服务器,能在任意网络下控制电脑。\\n"
+ "留空则只在同一个局域网内可用。");
hint.setTextColor(C_DIM);
hint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
hint.setPadding(0, 0, 0, dp(8));
box.addView(hint);
box.addView(input, new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
new AlertDialog.Builder(this)
.setTitle("中转服务器地址")
.setView(box)
.setPositiveButton("保存", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(android.content.DialogInterface dialog, int which) {
String url = input.getText().toString().trim();
setRelayUrl(url);
if (url.isEmpty()) {
toast("已清空:以后只走局域网");
} else {
toast("已保存中转地址");
appendLog("中转地址:" + url);
}
}
})
.setNeutralButton("清空", new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(android.content.DialogInterface dialog, int which) {
setRelayUrl("");
toast("已清空");
}
})
.setNegativeButton("取消", null)
.show();
}
'''
# 首页加一个"中转设置"按钮
HOME_OLD = ''' Button selfCheck = bigButton("连不上?点这里诊断", C_WARN, 15);'''
HOME_NEW = ''' // 中转地址:跨网络用。放首页是因为这是"连不上"的常见原因之一。
Button relayButton = bigButton(
"中转设置(跨网络用)", C_ACCENT, 14);
relayButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
promptRelayUrl();
}
});
panel.addView(relayButton, bigParams());
Button selfCheck = bigButton("连不上?点这里诊断", C_WARN, 15);'''
def main() -> int:
text = MAIN.read_text(encoding="utf-8")
ok = True
if "回退上一步" in text:
print(" 系统页已经加过回退按钮")
elif SYSTEM_OLD in text:
text = text.replace(SYSTEM_OLD, SYSTEM_NEW, 1)
print(" 系统页加了 3 个回退按钮")
else:
print(" [失败] 系统页锚点没找到")
ok = False
if "promptRelayUrl" in text:
print(" 已经加过中转设置")
else:
if RELAY_FIELD_ANCHOR in text:
text = text.replace(RELAY_FIELD_ANCHOR,
RELAY_HELPERS + RELAY_FIELD_ANCHOR, 1)
print(" 中转地址读写 + 设置对话框已加")
else:
# 退而求其次:放在类里第一个方法之前
anchor = " private static final int REQ_"
if anchor in text:
text = text.replace(anchor, RELAY_HELPERS + anchor, 1)
print(" 中转地址读写 + 设置对话框已加(备用锚点)")
else:
print(" [失败] 找不到插入位置")
ok = False
if HOME_OLD in text:
text = text.replace(HOME_OLD, HOME_NEW, 1)
print(" 首页加了「中转设置」按钮")
else:
print(" [跳过] 首页锚点没找到")
MAIN.write_text(text, encoding="utf-8")
return 0 if ok else 1
if __name__ == "__main__":
sys.exit(main())