dsh-mobile-ios 0.2.8 → 0.2.10

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/lib/client.js CHANGED
@@ -195,6 +195,20 @@ window.__ModuleLoader__.load({
195
195
  .dsh-mios-modal .modal-actions button.primary { border-color:var(--modal-accent);
196
196
  background:rgba(63,178,127,.16); color:var(--modal-accent); }
197
197
  .dsh-mios-modal .modal-actions button:disabled { opacity:.6; cursor:default; }
198
+ /* 复制结果必须看得见:dsh-app:// 页面里剪贴板可能不可用,只改按钮文字容易被无视。
199
+ .modal-toast 常驻在动作条上方,成功/失败都留痕。 */
200
+ .dsh-mios-modal .modal-toast { margin:10px 0 0; padding:7px 10px; border-radius:8px; font-size:11px;
201
+ font-weight:600; line-height:1.5; background:rgba(139,147,163,.14); color:var(--modal-muted); }
202
+ .dsh-mios-modal .modal-toast.success { background:rgba(63,178,127,.16); color:#2f9d70; }
203
+ .dsh-mios-modal .modal-toast.error { background:rgba(217,79,61,.14); color:#d94f3d; }
204
+ /* 复制全线失败时的兜底:给一个已自动全选的输入框,用户 Ctrl/⌘+C 就能拿走 */
205
+ .dsh-mios-modal .modal-pick { width:100%; box-sizing:border-box; margin:10px 0 0; padding:8px 10px;
206
+ border-radius:8px; border:1px solid var(--modal-accent); background:rgba(63,178,127,.10);
207
+ color:var(--modal-fg); font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12px;
208
+ user-select:text; -webkit-user-select:text; }
209
+ .dsh-mios-modal .modal-steps { margin:10px 0 0; padding-left:18px; font-size:11px;
210
+ color:var(--modal-muted); line-height:1.7; }
211
+ .dsh-mios-modal .modal-steps li { margin:2px 0; }
198
212
  .dsh-mios-panel .row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin: 3px 0; }
199
213
  .dsh-mios-panel .row b { color: var(--fg); font-weight: 600; text-align: right; max-width: 170px;
200
214
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -455,13 +469,21 @@ window.__ModuleLoader__.load({
455
469
  // 「域名未生效」必须单列:地址开出来了但公网解析不到,显示「已开通」会误导人去扫码。
456
470
  const tunnel = ok ? summary.tunnel : null;
457
471
  const dnsBroken = tunnel && tunnel.dnsOk === false;
458
- const running = !!(tunnel && tunnel.state === 'running' && !dnsBroken);
472
+ // 解析失败已经归因到 zone 层时,别再用「解析异常」这种症状词:
473
+ // moved 是归属冲突(改 NS 或换账号才能解),重探一万次也不会变。
474
+ const zoneCode = tunnel?.zone?.code || null;
475
+ // 「进程在跑」与「地址可用」是两件事:域名没生效时隧道进程可能已经起来了,
476
+ // 但扫码必然连不上,所以 running 仍然要求 dnsOk 不为 false。
477
+ const processUp = !!(tunnel && tunnel.state === 'running');
478
+ const running = processUp && !dnsBroken;
459
479
  const remoteState = panelEl.querySelector('#dsh-mios-remote-state');
460
480
  if (remoteState) {
461
481
  remoteState.textContent = !tunnel
462
482
  ? '—'
463
483
  : dnsBroken
464
- ? '解析异常 · 未开启'
484
+ ? (zoneCode === 'moved'
485
+ ? '域名归属冲突'
486
+ : processUp ? '已开启 · 域名未生效' : '解析异常 · 未开启')
465
487
  : running
466
488
  ? '已开启'
467
489
  : tunnel.provisioned && tunnel.fixedUrl
@@ -481,12 +503,15 @@ window.__ModuleLoader__.load({
481
503
  // 出码态走绿色主按钮;开启态走灰色次按钮(悬浮变白),视觉上分清两件事
482
504
  mainBtn.className = 'pairbtn' + (running || dnsBroken ? '' : ' tunnelbtn');
483
505
  mainBtn.style.display = tunnel && tunnel.state !== 'disabled' ? '' : 'none';
484
- mainBtn.disabled = tunnelBusy || bannerBusy.remote || dnsBroken;
506
+ // 关键:dnsBroken 不再禁用按钮。
507
+ // 以前 disabled = ... || dnsBroken,而唯一的重探入口就在点击之后 ——
508
+ // 按钮永远点不到,NS 改对了也不恢复,只能删状态文件(自锁死)。
509
+ mainBtn.disabled = tunnelBusy || bannerBusy.remote;
485
510
  const needsInstall = tunnel.executable === 'missing';
486
511
  mainBtn.textContent = needsInstall && tunnel.canAutoInstall
487
512
  ? '安装 cloudflared 并开启远程'
488
513
  : dnsBroken
489
- ? '域名解析异常,暂不可开启'
514
+ ? (zoneCode === 'moved' ? '查看原因(域名被占用)' : '重新检测域名解析')
490
515
  : running
491
516
  ? (bannerBusy.remote ? '生成中…' : '生成配对码(远程)')
492
517
  : tunnel.mode === 'named'
@@ -495,8 +520,9 @@ window.__ModuleLoader__.load({
495
520
  }
496
521
  const stopBtn = panelEl.querySelector('#dsh-mios-remote-stop');
497
522
  if (stopBtn) {
498
- // 停止按钮只在该停的时候出现:没开过/没在跑都没有「停」可言
499
- stopBtn.style.display = running && !tunnelBusy ? '' : 'none';
523
+ // 停止按钮只在该停的时候出现:没开过/没在跑都没有「停」可言。
524
+ // 域名未生效但进程在跑时仍要给「停止」——否则用户无法收尾。
525
+ stopBtn.style.display = processUp && !tunnelBusy ? '' : 'none';
500
526
  stopBtn.disabled = tunnelBusy;
501
527
  }
502
528
  // 远程码跟着可用性走:不是 running 就收起(与「停止即收码」同一语义,
@@ -700,7 +726,7 @@ window.__ModuleLoader__.load({
700
726
  updateModal?.remove();
701
727
  updateModal = null;
702
728
  }
703
- function showUpdateModal({ title, banner, lines, note, actions }) {
729
+ function showUpdateModal({ title, banner, lines, note, steps, actions }) {
704
730
  closeUpdateModal();
705
731
  const mask = document.createElement('div');
706
732
  mask.className = 'dsh-mios-modal-mask';
@@ -743,6 +769,17 @@ window.__ModuleLoader__.load({
743
769
  n.textContent = note;
744
770
  box.append(n);
745
771
  }
772
+ // 排障步骤:域名/NS 这类问题光说「异常」没用,得给出下一步点哪里。
773
+ if (steps?.length) {
774
+ const ol = document.createElement('ol');
775
+ ol.className = 'modal-steps';
776
+ for (const s of steps) {
777
+ const li = document.createElement('li');
778
+ li.textContent = s;
779
+ ol.append(li);
780
+ }
781
+ box.append(ol);
782
+ }
746
783
 
747
784
  const bar = document.createElement('div');
748
785
  bar.className = 'modal-actions';
@@ -760,29 +797,93 @@ window.__ModuleLoader__.load({
760
797
  updateModal = mask;
761
798
  }
762
799
 
763
- /** 复制文本:clipboard API 不可用时回退到 textarea + execCommand。 */
800
+ /**
801
+ * 复制文本。三级降级,任一级成功即返回 true:
802
+ * 1) navigator.clipboard —— 只在安全上下文可用;dsh-app:// 这类自定义协议
803
+ * 通常不算安全上下文,所以这一级大概率直接缺失/抛错;
804
+ * 2) textarea + execCommand('copy') —— 必须真的可见可焦点、并显式框选,
805
+ * 之前用 opacity:0 且未 focus/未 setSelectionRange,在 Electron 里选不中,
806
+ * execCommand 返回 false(这正是「点了复制没反应」的直接原因);
807
+ * 3) 全选 contenteditable 兜底 —— 仍然失败就交给面板给用户可手动复制的输入框。
808
+ */
764
809
  async function copyToClipboard(text) {
810
+ const value = String(text ?? '');
811
+ if (!value) return false;
765
812
  try {
766
813
  if (navigator.clipboard?.writeText) {
767
- await navigator.clipboard.writeText(text);
814
+ await navigator.clipboard.writeText(value);
768
815
  return true;
769
816
  }
770
- } catch { /* 落到下面的回退 */ }
817
+ } catch { /* 落到下一级 */ }
771
818
  try {
772
819
  const ta = document.createElement('textarea');
773
- ta.value = text;
774
- ta.style.position = 'fixed';
775
- ta.style.opacity = '0';
820
+ ta.value = value;
821
+ ta.setAttribute('readonly', '');
822
+ ta.setAttribute('aria-hidden', 'true');
823
+ // 用屏幕外定位而不是 opacity:0:透明元素在部分引擎里无法获得选区
824
+ ta.style.cssText = 'position:fixed;top:0;left:-9999px;width:1px;height:1px;'
825
+ + 'padding:0;border:0;outline:none;box-shadow:none;background:transparent;';
776
826
  document.body.append(ta);
827
+ ta.focus();
777
828
  ta.select();
829
+ ta.setSelectionRange(0, value.length);
778
830
  const ok = document.execCommand('copy');
779
831
  ta.remove();
780
- return ok;
832
+ if (ok) return true;
833
+ } catch { /* 落到下一级 */ }
834
+ try {
835
+ const holder = document.createElement('div');
836
+ holder.contentEditable = 'true';
837
+ holder.textContent = value;
838
+ holder.style.cssText = 'position:fixed;top:0;left:-9999px;white-space:pre;';
839
+ document.body.append(holder);
840
+ const range = document.createRange();
841
+ range.selectNodeContents(holder);
842
+ const sel = window.getSelection();
843
+ sel.removeAllRanges();
844
+ sel.addRange(range);
845
+ const ok = document.execCommand('copy');
846
+ sel.removeAllRanges();
847
+ holder.remove();
848
+ return Boolean(ok);
781
849
  } catch {
782
850
  return false;
783
851
  }
784
852
  }
785
853
 
854
+ /** 弹窗内结果提示:复制/更新这类动作必须有可见反馈,不能只改按钮文字。 */
855
+ function showModalToast(text, tone = 'info') {
856
+ const box = updateModal?.querySelector?.('.dsh-mios-modal');
857
+ if (!box) return;
858
+ let el = box.querySelector('.modal-toast');
859
+ if (!el) {
860
+ el = document.createElement('div');
861
+ box.insertBefore(el, box.querySelector('.modal-actions'));
862
+ }
863
+ el.className = `modal-toast${tone ? ' ' + tone : ''}`;
864
+ el.textContent = text;
865
+ }
866
+
867
+ /**
868
+ * 复制全线失败时的兜底:在弹窗里放一个已全选的输入框。
869
+ * 用户按 Ctrl/⌘+C 就能拿到,不依赖任何剪贴板 API。
870
+ */
871
+ function offerManualCopy(text) {
872
+ const box = updateModal?.querySelector?.('.dsh-mios-modal');
873
+ if (!box) return;
874
+ if (box.querySelector('.modal-pick')) return;
875
+ const input = document.createElement('input');
876
+ input.className = 'modal-pick';
877
+ input.type = 'text';
878
+ input.readOnly = true;
879
+ input.value = text;
880
+ box.insertBefore(input, box.querySelector('.modal-actions'));
881
+ try {
882
+ input.focus();
883
+ input.select();
884
+ } catch { /* 焦点拿不到也让用户能手动点选 */ }
885
+ }
886
+
786
887
  async function checkPluginUpdate() {
787
888
  showUpdateModal({ title: '插件更新', lines: [], note: '正在检查更新…', actions: [] });
788
889
  const current = summary?.version || '未知';
@@ -812,24 +913,12 @@ window.__ModuleLoader__.load({
812
913
  return;
813
914
  }
814
915
  if (compareVersions(latest, current) > 0) {
815
- // 一步更新:宿主提供 pluginManager 时直接安装,无需复制包名手动添加。
916
+ // 一键更新有两条路,面板不再把「复制包名」当主路径:
917
+ // ① 宿主给了 pluginManager.installBundle → 交给 DSH 安装器;
918
+ // ② 没给(老宿主 / 自定义协议页面)→ 网关自己取 npm tarball 覆盖安装。
919
+ // 以前 ② 缺失就只剩复制包名,而这类页面里剪贴板本身也不可用,
920
+ // 结果就是「既不能一键更新、也复制不了」的死角。
816
921
  const canAuto = !!(pluginManager && typeof pluginManager.installBundle === 'function');
817
- const actions = [{ label: '稍后再说', onClick: closeUpdateModal }];
818
- if (canAuto) {
819
- actions.push({
820
- label: `立即更新到 v${latest}`, primary: true,
821
- onClick: () => performUpdate(latest),
822
- });
823
- } else {
824
- // 降级:拿不到宿主安装服务(老宿主 / 非 Desktop),保留复制包名手动安装。
825
- actions.push({
826
- label: `复制 ${PLUGIN_NAME}@${latest}`, primary: true,
827
- onClick: async (btn) => {
828
- const ok = await copyToClipboard(`${PLUGIN_NAME}@${latest}`);
829
- btn.textContent = ok ? '已复制,去插件页粘贴安装' : '复制失败,请手动复制包名';
830
- },
831
- });
832
- }
833
922
  showUpdateModal({
834
923
  title: '新版本更新',
835
924
  banner: { text: `⬆️ 发现新版本 v${latest},可一键更新`, tone: 'info' },
@@ -839,8 +928,14 @@ window.__ModuleLoader__.load({
839
928
  ],
840
929
  note: canAuto
841
930
  ? '点击「立即更新」将由 DSH 安装器一步完成,更新中请勿关闭窗口。是否更新由你决定。'
842
- : '当前宿主未提供一步更新能力,请复制包名到 DSH「插件 → 添加插件」粘贴安装。',
843
- actions,
931
+ : '点击「立即更新」由本机网关直接下载并安装,无需复制包名;完成后重启 DSH 生效。',
932
+ actions: [
933
+ { label: '稍后再说', onClick: closeUpdateModal },
934
+ {
935
+ label: `立即更新到 v${latest}`, primary: true,
936
+ onClick: () => performUpdate(latest),
937
+ },
938
+ ],
844
939
  });
845
940
  } else {
846
941
  showUpdateModal({
@@ -930,25 +1025,10 @@ window.__ModuleLoader__.load({
930
1025
  async function performUpdate(latest) {
931
1026
  // 重复点击保护:更新中直接忽略再次触发
932
1027
  if (updateInFlight) return;
933
- if (!pluginManager || typeof pluginManager.installBundle !== 'function') {
934
- showUpdateModal({
935
- title: '更新不可用',
936
- banner: { text: '⚠️ 宿主未提供一步更新能力', tone: 'warn' },
937
- lines: [],
938
- note: '请复制包名,到 DSH「插件 → 添加插件」粘贴安装。',
939
- actions: [
940
- { label: '知道了', onClick: closeUpdateModal },
941
- { label: `复制 ${PLUGIN_NAME}@${latest}`, primary: true, onClick: async (btn) => {
942
- const ok = await copyToClipboard(`${PLUGIN_NAME}@${latest}`);
943
- btn.textContent = ok ? '已复制' : '复制失败';
944
- } },
945
- ],
946
- });
947
- return;
948
- }
949
1028
  updateInFlight = true;
950
1029
  const current = summary?.version || '未知';
951
1030
  const spec = `${PLUGIN_NAME}@${latest}`;
1031
+ const canHost = !!(pluginManager && typeof pluginManager.installBundle === 'function');
952
1032
  // 先持久化「更新中」,确保 HMR 卸载本模块后新实例能恢复出结果反馈。
953
1033
  writeUpdateState({ status: 'updating', target: String(latest), at: Date.now() });
954
1034
  // 状态:更新中。无取消/关闭动作外的操作按钮,防重复点击。
@@ -959,30 +1039,45 @@ window.__ModuleLoader__.load({
959
1039
  { label: '当前版本', value: `v${current}` },
960
1040
  { label: '目标版本', value: `v${latest}`, highlight: true },
961
1041
  ],
962
- note: '正在通过 DSH 安装器更新,可能需要 1–3 分钟。请勿重复点击或关闭窗口。',
1042
+ note: canHost
1043
+ ? '正在通过 DSH 安装器更新,可能需要 1–3 分钟。请勿重复点击或关闭窗口。'
1044
+ : '正在经本机网关下载并安装(含完整性校验),请勿重复点击或关闭窗口。',
963
1045
  actions: [],
964
1046
  });
965
- let requestId;
966
1047
  try {
967
- requestId = globalThis.crypto?.randomUUID?.();
968
- if (typeof requestId !== 'string') throw new Error('无法生成更新请求 ID');
969
- let result;
970
- try {
971
- result = await withTimeout(
972
- pluginManager.installBundle(spec, { enabled: true, requestId }),
973
- UPDATE_TIMEOUT_MS, '安装',
974
- );
975
- } catch (err) {
976
- // 超时/结果未知:用 requestId 对账,绝不重复提交安装
977
- if (typeof pluginManager.waitForInstall === 'function') {
978
- const recovered = await withTimeout(pluginManager.waitForInstall(requestId), 60000, '结果对账');
979
- if (!recovered) throw err;
980
- result = recovered;
981
- } else throw err;
1048
+ let restart = false;
1049
+ if (canHost) {
1050
+ // ① 宿主安装器:最常见的 Desktop 路径
1051
+ let requestId;
1052
+ requestId = globalThis.crypto?.randomUUID?.();
1053
+ if (typeof requestId !== 'string') throw new Error('无法生成更新请求 ID');
1054
+ let result;
1055
+ try {
1056
+ result = await withTimeout(
1057
+ pluginManager.installBundle(spec, { enabled: true, requestId }),
1058
+ UPDATE_TIMEOUT_MS, '安装',
1059
+ );
1060
+ } catch (err) {
1061
+ // 超时/结果未知:用 requestId 对账,绝不重复提交安装
1062
+ if (typeof pluginManager.waitForInstall === 'function') {
1063
+ const recovered = await withTimeout(pluginManager.waitForInstall(requestId), 60000, '结果对账');
1064
+ if (!recovered) throw err;
1065
+ result = recovered;
1066
+ } else throw err;
1067
+ }
1068
+ const value = unwrapRemote(result);
1069
+ restart = !!(value && (value.restartRequired || value.restart));
1070
+ } else {
1071
+ // ② 网关自更新:宿主没给 installBundle 时的等效能力。
1072
+ // 网关从 npm 取 tarball、按 dist.shasum 校验、备份旧目录后覆盖安装。
1073
+ const res = await fetchJson('/mobile/v1/plugin/self-update', {
1074
+ method: 'POST',
1075
+ headers: { 'content-type': 'application/json' },
1076
+ body: JSON.stringify({ target: latest }),
1077
+ }, 180000);
1078
+ restart = res?.restartRequired !== false;
982
1079
  }
983
- const value = unwrapRemote(result);
984
- const restart = !!(value && (value.restartRequired || value.restart));
985
- clearUpdateState(); // 安装器已返回结果,交由本弹窗反馈,无需跨重载恢复
1080
+ clearUpdateState(); // 安装已返回结果,交由本弹窗反馈,无需跨重载恢复
986
1081
  // 状态:成功
987
1082
  showUpdateModal({
988
1083
  title: '更新完成',
@@ -991,7 +1086,7 @@ window.__ModuleLoader__.load({
991
1086
  { label: '目标版本', value: `v${latest}` },
992
1087
  ],
993
1088
  note: restart
994
- ? '插件已更新,重启 DSH 桌面端后生效。'
1089
+ ? '插件已更新,重启 DSH 桌面端后生效(面板版本号会在重启后变成新版本)。'
995
1090
  : '插件已更新。若面板未刷新,重开面板或重启 DSH 即可。',
996
1091
  actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
997
1092
  });
@@ -1002,10 +1097,24 @@ window.__ModuleLoader__.load({
1002
1097
  title: '更新失败',
1003
1098
  banner: { text: '❌ 更新未成功', tone: 'error' },
1004
1099
  lines: [{ label: '目标版本', value: `v${latest}` }],
1005
- note: `安装失败:${err?.message || String(err)}。可重试,或复制包名到「插件 → 添加插件」手动安装。`,
1100
+ note: `安装失败:${err?.body?.error?.message || err?.message || String(err)}。可重试,也可以复制包名到「插件 → 添加插件」手动安装。`,
1006
1101
  actions: [
1007
1102
  { label: '关闭', onClick: closeUpdateModal },
1008
1103
  { label: '重试更新', primary: true, onClick: () => performUpdate(latest) },
1104
+ {
1105
+ label: '复制包名',
1106
+ onClick: async (btn) => {
1107
+ const ok = await copyToClipboard(spec);
1108
+ if (ok) {
1109
+ btn.textContent = '已复制';
1110
+ showModalToast(`已复制 ${spec},去「插件 → 添加插件」粘贴安装`, 'success');
1111
+ } else {
1112
+ btn.textContent = '请手动复制';
1113
+ showModalToast('本机剪贴板不可用,请在下方框内全选复制', 'error');
1114
+ offerManualCopy(spec);
1115
+ }
1116
+ },
1117
+ },
1009
1118
  ],
1010
1119
  });
1011
1120
  } finally {
@@ -1125,15 +1234,177 @@ window.__ModuleLoader__.load({
1125
1234
  }
1126
1235
  }
1127
1236
 
1237
+ /** 记住最近一次触发远程动作的 banner:弹窗里的「重新检测」要能继续同一条链。 */
1238
+ let lastRemoteBanner = null;
1239
+
1240
+ /**
1241
+ * 域名未生效时的排障弹窗。
1242
+ *
1243
+ * 关键是把「异常」翻译成用户能做的三件事,并带上公网当前 NS 让他去注册商对照:
1244
+ * 用户不需要理解 zone/pending,只要看名字对不对得上。
1245
+ */
1246
+ function showDnsHelpModal(res = {}) {
1247
+ const ns = Array.isArray(res.publicNs) ? res.publicNs : [];
1248
+ const zone = res.zone && typeof res.zone === 'object' ? res.zone : null;
1249
+ const expectedNs = Array.isArray(zone?.expectedNs) ? zone.expectedNs : [];
1250
+ const host = stripUrl(summary?.tunnel?.fixedUrl || summary?.tunnel?.hostname || '');
1251
+ const tampered = Boolean(res.tampered);
1252
+ // 归因码决定「修法」:moved(域名被另一个账号接管)/ pending(NS 没指过来)/
1253
+ // ns-mismatch(NS 与账号不匹配)/ unresolved(已生效但还没查到)绝不共用一套话术。
1254
+ const code = tampered ? 'tampered' : (zone?.code || 'unknown');
1255
+ const nsLine = expectedNs.length ? { label: '本账号 NS', value: expectedNs.join(' / ') } : null;
1256
+ const accountLine = zone?.accountName ? { label: '本账号', value: zone.accountName } : null;
1257
+
1258
+ const bodies = {
1259
+ tampered: {
1260
+ title: '固定域名被改指',
1261
+ banner: '⚠️ CNAME 已不指向本机隧道',
1262
+ note: '这条 CNAME 现在指向别处,扫码会把指令发给未知服务器,网关已拒绝下发该地址。',
1263
+ steps: [
1264
+ '到 Cloudflare 该域名的 DNS 页面,检查上面这条 CNAME 指向哪里。',
1265
+ '把它改回本机隧道(或直接删除这条记录)。',
1266
+ '回到面板点「重新检测」,通过后重新生成配对码。',
1267
+ ],
1268
+ },
1269
+ moved: {
1270
+ title: '域名已被另一个账号接管',
1271
+ banner: '⚠️ 这个域名不再归本机登录的 Cloudflare 账号',
1272
+ note: 'Cloudflare 把这个域名判成了「已迁移(zone moved)」:公网解析走的是另一个 Cloudflare 账号的那份 zone。'
1273
+ + '本机写进自己账号的记录一条都不会下发,所以地址永远解析不到——重装插件、重开隧道都没用。',
1274
+ steps: [
1275
+ '先确认两台电脑登录的是不是同一个 Cloudflare 账号:每台都跑一次 cloudflared tunnel login,选到不同账号就会形成「同一域名两份 zone、互相抢」。',
1276
+ expectedNs.length
1277
+ ? `在域名注册商处把 NS 改回本账号这一对:${expectedNs.join(' / ')}(当前公网是 ${ns.join(' / ') || '未知'})。隧道与 DNS 记录都在这边,改回即全部恢复。`
1278
+ : '在域名注册商处把 NS 改回本机这个账号分配的一对(Cloudflare 后台该域名页可查)。',
1279
+ '若决定改用现在接管的那份 zone:在那台设备上用对应账号重新授权并重新「开启远程」,本机会重建隧道与新地址。',
1280
+ '两种做法都只能二选一,别在两边同时改;改完等几分钟回到面板点「重新检测」。',
1281
+ ],
1282
+ },
1283
+ pending: {
1284
+ title: '域名在本账号未生效',
1285
+ banner: '⚠️ 公网 NS 还没指向本账号',
1286
+ note: '域名已经加进本账号,但注册商处的 NS 还没指向本账号分配的那一对,Cloudflare 因此不下发这里的记录。',
1287
+ steps: [
1288
+ expectedNs.length
1289
+ ? `到域名注册商把 NS 改成:${expectedNs.join(' / ')}(当前公网是 ${ns.join(' / ') || '未知'})。`
1290
+ : '到域名注册商把 NS 改成 Cloudflare 给本账号分配的那一对(后台域名页可查)。',
1291
+ '若域名其实已在另一个 Cloudflare 账号里生效,先在那个账号删掉它,否则两边会一直互抢。',
1292
+ 'NS 生效通常几分钟到几小时;生效后回到面板点「重新检测」,无需重装插件。',
1293
+ ],
1294
+ },
1295
+ 'ns-mismatch': {
1296
+ title: 'NS 与本账号不一致',
1297
+ banner: '⚠️ 公网 NS 和本账号分配的对不上',
1298
+ note: '本账号里这个域名显示已生效,但公网解析到的 NS 是另一对,说明注册商那边只改了一半或改错了。',
1299
+ steps: [
1300
+ expectedNs.length ? `确认注册商处的两个 NS 都是:${expectedNs.join(' / ')}。` : '确认注册商处的 NS 与 Cloudflare 后台显示的一致。',
1301
+ `当前公网解析到的是:${ns.join(' / ') || '未知'}。`,
1302
+ '改完后等几分钟,回到面板点「重新检测」。',
1303
+ ],
1304
+ },
1305
+ unresolved: {
1306
+ title: '记录还没生效',
1307
+ banner: '⚠️ 域名正常,但查不到这条记录',
1308
+ note: '域名在本账号已生效、NS 也对,只是公网还没查到这台主机的记录:多半是刚写入还在传播,或记录被删了。',
1309
+ steps: [
1310
+ '等 1–2 分钟后点「重新检测」。',
1311
+ '仍不行就点「开启远程」重建记录(会写回本机隧道)。',
1312
+ '如果这个地址刚在另一台电脑上开通过,先确认那台是否把记录改指到了它自己的隧道。',
1313
+ ],
1314
+ },
1315
+ };
1316
+ const body = bodies[code] || {
1317
+ title: '域名暂未生效',
1318
+ banner: '⚠️ 公网解析不到这个地址',
1319
+ note: '记录已经写进 Cloudflare,但公网解析不到它。通常是这个域名在当前登录的账号里还没生效。',
1320
+ steps: [
1321
+ '到 Cloudflare 后台看该域名状态是否为「活动 / Active」。',
1322
+ `把域名注册商处的 NS 改成该账号分配的 nameserver${ns.length ? `(当前公网是 ${ns.join('、')})` : ''}。`,
1323
+ 'NS 生效后回到面板点「重新检测」即可,无需重装插件。',
1324
+ ],
1325
+ };
1326
+
1327
+ showUpdateModal({
1328
+ title: body.title,
1329
+ banner: { text: body.banner, tone: 'warn' },
1330
+ lines: [
1331
+ { label: '固定域名', value: host || '—' },
1332
+ ...(zone?.status ? [{ label: '本账号 zone', value: zone.status }] : []),
1333
+ ...(nsLine ? [nsLine] : []),
1334
+ ...(ns.length ? [{ label: '公网 NS', value: ns.join(' / ') }] : []),
1335
+ ...(accountLine ? [accountLine] : []),
1336
+ ],
1337
+ note: body.note,
1338
+ steps: body.steps,
1339
+ actions: [
1340
+ { label: '关闭', onClick: closeUpdateModal },
1341
+ {
1342
+ label: '重新检测', primary: true,
1343
+ onClick: () => { closeUpdateModal(); recheckDnsAction(lastRemoteBanner); },
1344
+ },
1345
+ ],
1346
+ });
1347
+ }
1348
+
1349
+ /**
1350
+ * 域名解析异常时的主按钮出路:强制重探一次。
1351
+ * 通过 → 直接继续「开启 + 出码」,用户不用再点第二次;不通过 → 给排障步骤。
1352
+ */
1353
+ async function recheckDnsAction(banner) {
1354
+ if (tunnelBusy) return;
1355
+ lastRemoteBanner = banner || lastRemoteBanner;
1356
+ tunnelBusy = true;
1357
+ const mainBtn = panelEl?.querySelector('#dsh-mios-remote-main');
1358
+ if (mainBtn) {
1359
+ mainBtn.disabled = true;
1360
+ mainBtn.textContent = '检测中…';
1361
+ }
1362
+ try {
1363
+ const res = await fetchJson('/mobile/v1/tunnel/recheck-dns', { method: 'POST' }, 25000);
1364
+ await probe();
1365
+ renderSummary();
1366
+ if (res?.ok) {
1367
+ // 解析恢复:把动作链接回去(此时 tunnelBusy 必须释放,否则 remoteMainAction 会直接返回)
1368
+ tunnelBusy = false;
1369
+ if (mainBtn) mainBtn.disabled = false;
1370
+ await remoteMainAction(lastRemoteBanner);
1371
+ return;
1372
+ }
1373
+ showDnsHelpModal(res || {});
1374
+ } catch (err) {
1375
+ showDnsHelpModal({
1376
+ ok: false,
1377
+ warning: err?.body?.error?.message || err?.message || String(err),
1378
+ });
1379
+ } finally {
1380
+ tunnelBusy = false;
1381
+ if (mainBtn) mainBtn.disabled = false;
1382
+ renderSummary();
1383
+ }
1384
+ }
1385
+
1128
1386
  /** 远程主按钮:一条动作链走完「确保在跑 → 出码」。一次点击出码,绝不让人点两下。 */
1129
1387
  async function remoteMainAction(banner) {
1130
1388
  if (tunnelBusy || bannerBusy.remote || installBusy) return;
1389
+ lastRemoteBanner = banner || lastRemoteBanner;
1131
1390
  const mainBtn = panelEl?.querySelector('#dsh-mios-remote-main');
1132
1391
  // 缺依赖且平台可自动装:先走安装确认,装完再继续开启(避免点了必然失败的 start)
1133
1392
  if (summary?.tunnel?.executable === 'missing' && summary?.tunnel?.canAutoInstall) {
1134
1393
  installCloudflaredAction(banner);
1135
1394
  return;
1136
1395
  }
1396
+ // 域名解析异常:先重检,别把人堵在「暂不可开启」上(那就是原来的死锁)
1397
+ if (summary?.tunnel?.dnsOk === false) {
1398
+ // 已经确诊「域名被另一个 Cloudflare 账号接管」:重探改变不了归属,
1399
+ // 直接把原因和两条修法摆出来(弹窗里仍有「重新检测」供改完 NS 后收口)。
1400
+ const zone = summary?.tunnel?.zone;
1401
+ if (zone?.code === 'moved') {
1402
+ showDnsHelpModal({ ok: false, zone, publicNs: zone.publicNs || [] });
1403
+ return;
1404
+ }
1405
+ await recheckDnsAction(banner);
1406
+ return;
1407
+ }
1137
1408
  const running = summary?.tunnel?.state === 'running' && summary?.tunnel?.dnsOk !== false;
1138
1409
  try {
1139
1410
  if (!running) {
@@ -1282,8 +1553,11 @@ window.__ModuleLoader__.load({
1282
1553
  exports.__test = {
1283
1554
  PORT_CANDIDATES, STATUS_OK, STATUS_DOWN,
1284
1555
  showUpdateModal, closeUpdateModal, copyToClipboard,
1556
+ showModalToast, offerManualCopy, showDnsHelpModal, recheckDnsAction,
1285
1557
  performUpdate, checkPluginUpdate, compareVersions, unwrapRemote,
1286
1558
  setPluginManager: (m) => { pluginManager = m; },
1559
+ probe, remoteMainAction, renderSummary,
1560
+ getSummary: () => summary,
1287
1561
  setUpdateTimeout: (ms) => { UPDATE_TIMEOUT_MS = ms; },
1288
1562
  isUpdateInFlight: () => updateInFlight,
1289
1563
  restorePendingUpdate, readUpdateState, writeUpdateState, clearUpdateState,