mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 16:00:43 +00:00
按用户定的版本规矩,这一轮既有新内容又有重构,所以升第二位: 1.9.0 -> 2.0.0(最后一位清 0)。 == 一、安装时就能设中转服务器(用户要求)== 安装向导那一页现在是两个输入框:配对码 + 中转服务器。 装的时候是"第一次设置",最该一次把地址填好,不然装完还得去 双击 exe 找设置窗口,很容易漏。 只填域名就行(自动补 https://),留空 = 只走局域网。 批量静默部署同样支持: ykxmz-setup-2.0.0.exe /VERYSILENT /CODE=246810 /RELAY=relay.你的域名 为此新增了一个 --relay-url 参数: --relay 连接一次、打印状态、然后退出(人工排查用) --relay-url 只写进配置,不连接、不退出(安装流程用) 用错那个的话,安装包的命令链会在中间就 return,后面的 --silent 根本跑不到 —— 所以必须分开。 == 二、手表端新增「设置」页(用户要求)== 用户原话:"安卓端加一个设置,各种设置就在这里面调"。 以前设置散在首页(只有一个"中转设置"按钮),现在统一收进设置页: * 中转服务器(填写 / 一键清空) * 记住的配对码(显示 / 清除) * 已配对的电脑(看数量 / 清空,带二次确认) * 关于(版本号从 APK 读,不会和代码对不上) == 三、中转地址默认留空 + 一次性迁移(用户报的问题)== 用户原话:"安卓端为什么还是默认填的我的中转站,以后改成手动填"。 代码里的默认值早就是空的了,但用户看到的还是那个地址 —— 因为**老版本 1.5.0 把作者的域名硬编码成了默认值**,第一次运行就 存进了 SharedPreferences。装新 APK 不会清偏好,所以那个值一直留着。 用户其实从来没"选"过这个地址,是程序硬塞的。 所以加了 migrateLegacyRelay():存的值如果正好等于当时内置的域名, 就当成没设过、清掉。只清完全相等的,用户手填的不会动。 == 四、两个测试自身的毛病 == * test_lan_optimize 那条"没有把旧公网域名当默认值"太粗 —— 它查的是源码里任何位置,于是迁移注释里引用那行老代码就把它判红了。 改成先剥掉注释再查(断言要测的是"有没有把它当默认值")。 * test_image_modes 偶发红:它开真实 Tk 全屏窗口,在全量套件里跑 偶尔起不来(单独跑 19/19 全过)。加了有界重试。 偶发红的测试会让"全量通过"失去意义。 == 五、新增防复发断言 == _tests/test_relay_default_blank.py(15 项,回归阶段 3a3b): * 默认值必须是空串 * 除了迁移清单,源码里不许有写死的中转域名 * 迁移必须真的被调用(不是只定义) * 迁移必须是 remove,不能换成另一个硬编码值 * Windows 端的默认也得是空 理由:用户说过"这个中转站我就自己用,不对外" —— 值得用断言钉死。 == 六、顺手修的 == * release_all.py 崩在 Gitee 那一步:Gitee 的 GET /releases/tags/{tag} 在"标签存在、但还没发行版"时返回的是 **HTTP 200 + JSON null**(不是 404),于是 .get("id") 直接 AttributeError。发 1.9.0 时踩到,已改成容忍 None。 * installer/build_installer.py 里 license-combined.txt 是从 docs/ 三份文档重新生成的,所以光改生成物没用(下次构建又变回去)。 改成在 build_license() 里统一注入当前版本。 * ExE 文件属性里的版本(version_info.txt)从 1.7.1 起就一直没跟上。 全量回归 43 个阶段全部通过。
148 lines
4.9 KiB
Java
148 lines
4.9 KiB
Java
package com.lanremote.watch;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* 设备与连接信息持久化。
|
|
*
|
|
* 配对成功后保存令牌,下次打开直接从设备列表一键连接,无需再输配对码。
|
|
*/
|
|
public class DeviceStore {
|
|
|
|
private static final String PREFS = "lanremote";
|
|
private static final String KEY_DEVICES = "devices";
|
|
private static final String KEY_DEVICE_ID = "device_id";
|
|
private static final String KEY_DEVICE_NAME = "device_name";
|
|
private static final String KEY_LAST_HOST = "last_host";
|
|
private static final String KEY_LAST_PORT = "last_port";
|
|
|
|
private final SharedPreferences prefs;
|
|
|
|
public DeviceStore(Context context) {
|
|
this.prefs = context.getApplicationContext()
|
|
.getSharedPreferences(PREFS, Context.MODE_PRIVATE);
|
|
}
|
|
|
|
// ---------------- 本机标识 ----------------
|
|
|
|
public String deviceId() {
|
|
String id = prefs.getString(KEY_DEVICE_ID, "");
|
|
if (id == null || id.isEmpty()) {
|
|
id = "watch-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
|
prefs.edit().putString(KEY_DEVICE_ID, id).apply();
|
|
}
|
|
return id;
|
|
}
|
|
|
|
public String deviceName() {
|
|
String name = prefs.getString(KEY_DEVICE_NAME, "");
|
|
if (name == null || name.isEmpty()) {
|
|
name = android.os.Build.MODEL;
|
|
if (name == null || name.trim().isEmpty()) {
|
|
name = "手表";
|
|
}
|
|
prefs.edit().putString(KEY_DEVICE_NAME, name).apply();
|
|
}
|
|
return name;
|
|
}
|
|
|
|
public void setDeviceName(String name) {
|
|
prefs.edit().putString(KEY_DEVICE_NAME, name == null ? "手表" : name.trim()).apply();
|
|
}
|
|
|
|
// ---------------- 上次连接 ----------------
|
|
|
|
public String lastHost() {
|
|
return prefs.getString(KEY_LAST_HOST, "");
|
|
}
|
|
|
|
public int lastPort() {
|
|
return prefs.getInt(KEY_LAST_PORT, RemoteClient.DEFAULT_PORT);
|
|
}
|
|
|
|
public void setLastEndpoint(String host, int port) {
|
|
prefs.edit().putString(KEY_LAST_HOST, host).putInt(KEY_LAST_PORT, port).apply();
|
|
}
|
|
|
|
// ---------------- 已配对设备 ----------------
|
|
|
|
public List<Map<String, Object>> devices() {
|
|
return readDevices();
|
|
}
|
|
|
|
private List<Map<String, Object>> readDevices() {
|
|
String raw = prefs.getString(KEY_DEVICES, "");
|
|
if (raw == null || raw.isEmpty()) {
|
|
return new ArrayList<Map<String, Object>>();
|
|
}
|
|
try {
|
|
Object parsed = Json.parse(raw);
|
|
if (parsed instanceof List) {
|
|
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
|
for (Object item : (List<?>) parsed) {
|
|
Map<String, Object> map = Json.asMap(item);
|
|
if (map != null) {
|
|
result.add(map);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
} catch (RuntimeException ignored) {
|
|
// 存储损坏时当作空列表,不崩溃
|
|
}
|
|
return new ArrayList<Map<String, Object>>();
|
|
}
|
|
|
|
private void writeDevices(List<Map<String, Object>> devices) {
|
|
prefs.edit().putString(KEY_DEVICES, Json.write(devices)).apply();
|
|
}
|
|
|
|
/** 保存或更新一台设备(按 key = 地址:端口:设备ID 去重)。 */
|
|
public void saveDevice(String key, String label, String host, int port, String token) {
|
|
List<Map<String, Object>> devices = readDevices();
|
|
List<Map<String, Object>> updated = new ArrayList<Map<String, Object>>();
|
|
for (Map<String, Object> device : devices) {
|
|
if (!key.equals(Json.str(device, "key", ""))) {
|
|
updated.add(device);
|
|
}
|
|
}
|
|
updated.add(0, Json.obj(
|
|
"key", key,
|
|
"label", label,
|
|
"host", host,
|
|
"port", port,
|
|
"token", token,
|
|
"savedAt", System.currentTimeMillis()));
|
|
while (updated.size() > 12) {
|
|
updated.remove(updated.size() - 1);
|
|
}
|
|
writeDevices(updated);
|
|
}
|
|
|
|
public void removeDevice(String key) {
|
|
List<Map<String, Object>> devices = readDevices();
|
|
List<Map<String, Object>> updated = new ArrayList<Map<String, Object>>();
|
|
for (Map<String, Object> device : devices) {
|
|
if (!key.equals(Json.str(device, "key", ""))) {
|
|
updated.add(device);
|
|
}
|
|
}
|
|
writeDevices(updated);
|
|
}
|
|
|
|
/** 清空所有已配对设备(设置页的清空用)。 */
|
|
public void clearDevices() {
|
|
prefs.edit().remove(KEY_DEVICES).apply();
|
|
}
|
|
|
|
public static String deviceKey(String host, int port, String deviceId) {
|
|
return host + ":" + port + ":" + deviceId;
|
|
}
|
|
}
|