dsh-remote-web 0.7.6-beta.4 → 0.7.6-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-remote-web",
3
- "version": "0.7.6-beta.4",
3
+ "version": "0.7.6-beta.6",
4
4
  "description": "公网远程控制 DeepSeek Harness(dsh web):安装即得专属加密地址,人在外面也能用手机访问电脑上的 dsh——无需同一局域网/WiFi、无需公网 IP 与内网穿透,全程加密;手机端 100% 还原电脑体验(对话/工具/审批/设置)。技术用户可选自建服务,流量走自己的服务器。Remote control DeepSeek Harness (dsh web) from anywhere over the public internet — install, get an encrypted URL, use it from your phone on any network (dual-half cordis plugin: Settings panel + same-origin /dsh-remote routes). (2026-09 由 dsh-remote-ui 更名 / renamed from dsh-remote-ui; dsh-remote 的 dsh web 插件半,不是纯 UI/皮肤插件)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -1223,6 +1223,18 @@ async function upstreamReachable(url = upstreamUrl(), timeoutMs = 1200) {
1223
1223
  */
1224
1224
  async function isDshWebUp(timeoutMs = 1200) {
1225
1225
  if (await upstreamReachable(upstreamUrl(), timeoutMs)) return true;
1226
+ // 🔴 2026-10-25(设备掉线实测):Electron 每次启动可能换端口。端口文件由 dsh web 内的插件
1227
+ // 在每次启动时重写,比进程内的 discoveredUpstream 缓存新 —— 先直接试文件,别被旧缓存挡住。
1228
+ try {
1229
+ const fromFile = String(fs.readFileSync(path.join(CONFIG_DIR, UPSTREAM_FILE), "utf8")).trim();
1230
+ if (/^https?:\/\/[^\s]+$/i.test(fromFile)) {
1231
+ const normalized = fromFile.replace(/\/+$/, "");
1232
+ if (normalized !== upstreamUrl() && (await upstreamReachable(normalized, timeoutMs))) {
1233
+ discoveredUpstream = normalized;
1234
+ return true;
1235
+ }
1236
+ }
1237
+ } catch { /* 没有端口文件:继续走动态发现 */ }
1226
1238
  const before = upstreamUrl();
1227
1239
  const after = await refreshUpstreamDiscovery(true);
1228
1240
  if (after === before) return false;
@@ -1859,6 +1871,9 @@ async function runBridge() {
1859
1871
  const alive = await checkUpstream();
1860
1872
  if (alive && childStopped(bridgeProc)) {
1861
1873
  starting = true;
1874
+ // dsh 重启可能换端口(Electron 每次启动端口可能变):拉起前**强制重新发现**,
1875
+ // 否则 discoveredUpstream 缓存旧端口 → bridge 连不上上游 → 设备掉线(2026-10-25 实测)。
1876
+ await refreshUpstreamDiscovery(true);
1862
1877
  console.log("[dsh-remote] dsh web 在线,启动 bridge...");
1863
1878
  // 清除代理环境变量(bridge 需直连 relay,不受本机代理影响)
1864
1879
  const childEnv = {
@@ -1900,6 +1915,17 @@ async function runBridge() {
1900
1915
  // 另一个 bridge 把本连接顶掉)后会以"重复实例"退出码优雅退出(见 dsh-bridge.mjs)。
1901
1916
  // 这种退出**绝不能**照常 10s 重拉:本机已经有另一个实例在跑,重拉只会继续乒乓互踢。
1902
1917
  if (code === DUPLICATE_INSTANCE_EXIT_CODE) {
1918
+ // 🔴 2026-10-25:升级/重启后常见「上一代 bridge 变成孤儿继续占着单实例锁」,
1919
+ // 新 bridge 因此退出 code=4。旧逻辑一律暂停 5 分钟 → 设备在线要等 5 分钟(用户实测掉线)。
1920
+ // 现在先**清扫同运行时的孤儿 bridge**;扫到了说明冲突已解除,3 秒后立即重试;
1921
+ // 扫不到(多半真有另一个 watcher 的活实例)才按 5 分钟退避,避免乒乓互踢。
1922
+ let swept = [];
1923
+ try { swept = sweepStrayBridges(); } catch { /* 清扫失败不致命 */ }
1924
+ if (swept.length > 0) {
1925
+ duplicateBridgeBackoffUntil = Date.now() + 3000;
1926
+ console.log(`[dsh-remote] bridge 因同实例冲突退出(code=${code}),已清扫 ${swept.length} 个孤儿 bridge(pid ${swept.join(", ")})→ 3 秒后重试。`);
1927
+ return;
1928
+ }
1903
1929
  duplicateBridgeBackoffUntil = Date.now() + DUPLICATE_BRIDGE_BACKOFF_MS;
1904
1930
  console.log(`[dsh-remote] bridge 检测到同 deviceId 的另一个实例并退出(code=${code})——本守护暂停 ${Math.round(DUPLICATE_BRIDGE_BACKOFF_MS / 60000)} 分钟后再试,避免两个实例反复互踢。`);
1905
1931
  return;
@@ -1913,6 +1939,8 @@ async function runBridge() {
1913
1939
  setTimeout(() => { starting = false; }, 5000);
1914
1940
  } else if (!alive && bridgeProc && bridgeProc.exitCode === null) {
1915
1941
  console.log("[dsh-remote] dsh web 离线,停止 bridge...");
1942
+ // dsh 重启后端口可能变化:清掉进程内缓存,下一轮优先用插件新写的端口文件探测
1943
+ discoveredUpstream = "";
1916
1944
  await stopChildGracefully(bridgeProc); // 同上:Windows 上 kill() 跑不到退出钩子
1917
1945
  }
1918
1946
  };