dsh-mobile-ios 0.2.15 → 0.2.16

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.
Files changed (2) hide show
  1. package/lib/client.js +77 -24
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -913,29 +913,54 @@ window.__ModuleLoader__.load({
913
913
  return;
914
914
  }
915
915
  if (compareVersions(latest, current) > 0) {
916
- // 一键更新有两条路,面板不再把「复制包名」当主路径:
917
- // ① 宿主给了 pluginManager.installBundle → 交给 DSH 安装器;
918
- // ② 没给(老宿主 / 自定义协议页面)→ 网关自己取 npm tarball 覆盖安装。
919
- // 以前 ② 缺失就只剩复制包名,而这类页面里剪贴板本身也不可用,
920
- // 结果就是「既不能一键更新、也复制不了」的死角。
921
- const canAuto = !!(pluginManager && typeof pluginManager.installBundle === 'function');
916
+ // 更新能力分三档,面板按宿主实际给了什么决定按钮,绝不摆一个按了没反应的按钮:
917
+ // ① updateBundle —— 宿主插件管理器自己的升级入口(与「插件」页那个
918
+ // 「更新到 vX」完全同一条代码路径:先移除旧包再装新包并热加载)。
919
+ // 已安装的包只能走这条,installBundle 会被宿主判为「该插件已安装」。
920
+ // ② installBundle —— 老宿主没有 updateBundle 时的等效能力。
921
+ // ③ 都没有 —— 只给图文指引:去「插件」页点右上角刷新,交给宿主安装。
922
+ const hostUpdate = !!(pluginManager && typeof pluginManager.updateBundle === 'function');
923
+ const hostInstall = !!(pluginManager && typeof pluginManager.installBundle === 'function');
924
+ const canAuto = hostUpdate || hostInstall;
922
925
  showUpdateModal({
923
926
  title: '新版本更新',
924
- banner: { text: `⬆️ 发现新版本 v${latest},可一键更新`, tone: 'info' },
927
+ banner: { text: `⬆️ 发现新版本 v${latest}`, tone: 'info' },
925
928
  lines: [
926
929
  { label: '当前版本', value: `v${current}` },
927
930
  { label: '最新版本', value: `v${latest}`, highlight: true },
928
931
  ],
929
932
  note: canAuto
930
- ? '点击「立即更新」将由 DSH 安装器一步完成,更新中请勿关闭窗口。是否更新由你决定。'
931
- : '点击「立即更新」由本机网关直接下载并安装,无需复制包名;完成后重启 DSH 生效。',
932
- actions: [
933
- { label: '稍后再说', onClick: closeUpdateModal },
934
- {
935
- label: `立即更新到 v${latest}`, primary: true,
936
- onClick: () => performUpdate(latest),
937
- },
933
+ ? '点「立即更新」由 DSH 插件管理器安装并切换到新版本,完成后重启 DSH 生效。也可以到「插件」页点右上角「刷新」手动更新。'
934
+ : '本面板没拿到 DSH 插件管理器接口,请按下面步骤在「插件」页更新,由 DSH 自带的插件更新机制安装。',
935
+ // 没有宿主接口时,把「点哪里」写清楚:只报「可更新」不给路径等于没帮上忙。
936
+ steps: canAuto ? undefined : [
937
+ '在 DSH 左侧点「插件」',
938
+ '点右上角「刷新」',
939
+ `在列表里点 dsh-mobile-ios 的「更新到 v${latest}」`,
940
+ '重启 DSH 桌面端,让新版本生效',
938
941
  ],
942
+ actions: canAuto
943
+ ? [
944
+ { label: '稍后再说', onClick: closeUpdateModal },
945
+ { label: `立即更新到 v${latest}`, primary: true, onClick: () => performUpdate(latest) },
946
+ ]
947
+ : [
948
+ {
949
+ label: '复制包名',
950
+ onClick: async (btn) => {
951
+ const ok = await copyToClipboard(PLUGIN_NAME);
952
+ if (ok) {
953
+ btn.textContent = '已复制';
954
+ showModalToast(`已复制 ${PLUGIN_NAME},可在「插件 → 添加插件」粘贴`, 'success');
955
+ } else {
956
+ btn.textContent = '请手动复制';
957
+ showModalToast('本机剪贴板不可用,请在下方框内全选复制', 'error');
958
+ offerManualCopy(PLUGIN_NAME);
959
+ }
960
+ },
961
+ },
962
+ { label: '知道了', primary: true, onClick: closeUpdateModal },
963
+ ],
939
964
  });
940
965
  } else {
941
966
  showUpdateModal({
@@ -1028,7 +1053,8 @@ window.__ModuleLoader__.load({
1028
1053
  updateInFlight = true;
1029
1054
  const current = summary?.version || '未知';
1030
1055
  const spec = `${PLUGIN_NAME}@${latest}`;
1031
- const canHost = !!(pluginManager && typeof pluginManager.installBundle === 'function');
1056
+ const canHost = !!(pluginManager
1057
+ && (typeof pluginManager.updateBundle === 'function' || typeof pluginManager.installBundle === 'function'));
1032
1058
  // 先持久化「更新中」,确保 HMR 卸载本模块后新实例能恢复出结果反馈。
1033
1059
  writeUpdateState({ status: 'updating', target: String(latest), at: Date.now() });
1034
1060
  // 状态:更新中。无取消/关闭动作外的操作按钮,防重复点击。
@@ -1040,14 +1066,33 @@ window.__ModuleLoader__.load({
1040
1066
  { label: '目标版本', value: `v${latest}`, highlight: true },
1041
1067
  ],
1042
1068
  note: canHost
1043
- ? '正在通过 DSH 安装器更新,可能需要 1–3 分钟。请勿重复点击或关闭窗口。'
1069
+ ? '正在通过 DSH 插件管理器更新(先卸旧版再装新版),约 1–3 分钟。请勿重复点击或关闭窗口。'
1044
1070
  : '正在经本机网关下载并安装(含完整性校验),请勿重复点击或关闭窗口。',
1045
1071
  actions: [],
1046
1072
  });
1047
1073
  try {
1048
1074
  let restart = false;
1049
- if (canHost) {
1050
- // ① 宿主安装器:最常见的 Desktop 路径
1075
+ const canHostUpdate = !!(pluginManager && typeof pluginManager.updateBundle === 'function');
1076
+ if (canHostUpdate) {
1077
+ // ⓪ 宿主插件管理器的升级入口:与「插件」页「更新到 vX」同一条路径
1078
+ // (内部先 removeBundle 再 installBundle,并触发 HMR 热切换)。
1079
+ // 已安装的包只能走这条 —— installBundle 会被判「该插件已安装」。
1080
+ let requestId = globalThis.crypto?.randomUUID?.();
1081
+ if (typeof requestId !== 'string') throw new Error('无法生成更新请求 ID');
1082
+ const settled = await withTimeout(
1083
+ pluginManager.updateBundle(String(PLUGIN_NAME), String(latest), { requestId }),
1084
+ UPDATE_TIMEOUT_MS, '更新',
1085
+ );
1086
+ const out = unwrapRemote(settled) || {};
1087
+ const result = out.result || {};
1088
+ // 宿主用 application:'failed' + error 表达拒绝/失败,不能当成功吞掉
1089
+ if (result.application === 'failed' || result.error) {
1090
+ const why = result.error?.diagnostic || result.error?.code || out.step || '宿主未说明原因';
1091
+ throw new Error(`DSH 插件管理器更新失败:${why}`);
1092
+ }
1093
+ restart = true;
1094
+ } else if (typeof pluginManager?.installBundle === 'function') {
1095
+ // ① 老宿主安装器:最常见的 Desktop 路径
1051
1096
  let requestId;
1052
1097
  requestId = globalThis.crypto?.randomUUID?.();
1053
1098
  if (typeof requestId !== 'string') throw new Error('无法生成更新请求 ID');
@@ -1068,7 +1113,7 @@ window.__ModuleLoader__.load({
1068
1113
  const value = unwrapRemote(result);
1069
1114
  restart = !!(value && (value.restartRequired || value.restart));
1070
1115
  } else {
1071
- // ② 网关自更新:宿主没给 installBundle 时的等效能力。
1116
+ // ② 网关自更新:宿主没给任何插件管理接口时的等效能力。
1072
1117
  // 网关从 npm 取 tarball、按 dist.shasum 校验、备份旧目录后覆盖安装。
1073
1118
  const res = await fetchJson('/mobile/v1/plugin/self-update', {
1074
1119
  method: 'POST',
@@ -1091,16 +1136,23 @@ window.__ModuleLoader__.load({
1091
1136
  actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
1092
1137
  });
1093
1138
  } catch (err) {
1094
- // 状态:失败(保留重试入口;重试会重新走一遍锁与状态机)
1139
+ // 状态:失败。不能只报错就完 —— 顺手把「插件页刷新」这条路指出来,
1140
+ // 宿主自己的安装器通常能成功(它走的是 pnpm + 本机 registry 镜像)。
1095
1141
  clearUpdateState();
1096
1142
  showUpdateModal({
1097
1143
  title: '更新失败',
1098
- banner: { text: '❌ 更新未成功', tone: 'error' },
1144
+ banner: { text: '❌ 面板内更新未成功', tone: 'error' },
1099
1145
  lines: [{ label: '目标版本', value: `v${latest}` }],
1100
- note: `安装失败:${err?.body?.error?.message || err?.message || String(err)}。可重试,也可以复制包名到「插件 → 添加插件」手动安装。`,
1146
+ note: `失败原因:${err?.body?.error?.message || err?.message || String(err)}。可重试;更稳的办法是到「插件」页刷新,由 DSH 自己安装。`,
1147
+ steps: [
1148
+ '在 DSH 左侧点「插件」',
1149
+ '点右上角「刷新」',
1150
+ `在列表里点 dsh-mobile-ios 的「更新到 v${latest}」`,
1151
+ '重启 DSH 桌面端,让新版本生效',
1152
+ ],
1101
1153
  actions: [
1102
1154
  { label: '关闭', onClick: closeUpdateModal },
1103
- { label: '重试更新', primary: true, onClick: () => performUpdate(latest) },
1155
+ { label: '重试更新', onClick: () => performUpdate(latest) },
1104
1156
  {
1105
1157
  label: '复制包名',
1106
1158
  onClick: async (btn) => {
@@ -1115,6 +1167,7 @@ window.__ModuleLoader__.load({
1115
1167
  }
1116
1168
  },
1117
1169
  },
1170
+ { label: '知道了', primary: true, onClick: closeUpdateModal },
1118
1171
  ],
1119
1172
  });
1120
1173
  } finally {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-ios",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "type": "module",
5
5
  "description": "DSH iOS移动伴侣:iPhone/iPad 扫码连接 DSH 桌面端,局域网直连 + Cloudflare Tunnel 固定域名远程两种通道",
6
6
  "main": "entries/plugin.mjs",