dsh-mobile-ios 0.2.3 → 0.2.5

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.
Binary file
package/lib/client.js CHANGED
@@ -160,10 +160,35 @@ window.__ModuleLoader__.load({
160
160
  padding: 14px; }
161
161
  .dsh-mios-panel h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
162
162
  .dsh-mios-upd { margin-left: auto; background: none; border: 1px solid var(--border); border-radius: 7px;
163
- color: var(--muted); font: 500 11px/1.4 inherit, sans-serif; cursor: pointer; padding: 3px 8px; }
163
+ color: var(--muted); font-family: inherit; font-size: 11px; font-weight: 500; line-height: 1.4;
164
+ cursor: pointer; padding: 3px 8px; }
164
165
  .dsh-mios-upd:hover { color: var(--fg); border-color: var(--border-hover); }
165
- .upd-result { margin: -4px 0 10px; font-size: 11px; color: var(--muted); line-height: 1.5; }
166
- .upd-result.has-update { color: #3fb27f; }
166
+ .dsh-mios-modal-mask { --modal-bg:#1c2230; --modal-fg:#e8eaf0; --modal-muted:#8b93a3;
167
+ --modal-border:#3a4560; --modal-btn:rgba(139,147,163,.12); --modal-accent:#3fb27f; --modal-shadow:rgba(0,0,0,.6);
168
+ position:fixed; inset:0; z-index:2147483000; background:var(--modal-shadow);
169
+ display:flex; align-items:center; justify-content:center; padding:20px;
170
+ font-family:-apple-system, "PingFang SC", sans-serif; font-size:13px; line-height:1.6; }
171
+ .dsh-mios-modal-mask.light { --modal-bg:#ffffff; --modal-fg:#1f2430; --modal-muted:#6b7280;
172
+ --modal-border:#d9dee8; --modal-btn:rgba(107,114,128,.1); --modal-accent:#2f9d70; --modal-shadow:rgba(31,36,48,.35); }
173
+ .dsh-mios-modal { width:100%; max-width:340px; box-sizing:border-box; background:var(--modal-bg);
174
+ color:var(--modal-fg); border:1px solid var(--modal-border); border-radius:14px; padding:18px;
175
+ box-shadow:0 18px 60px var(--modal-shadow); }
176
+ .dsh-mios-modal h4 { margin:0 0 12px; font-size:15px; display:flex; align-items:center; gap:8px; }
177
+ .dsh-mios-modal .modal-x { margin-left:auto; background:none; border:none; color:var(--modal-muted);
178
+ font-size:16px; cursor:pointer; line-height:1; padding:2px 4px; }
179
+ .dsh-mios-modal .modal-line { display:flex; justify-content:space-between; gap:10px;
180
+ font-size:12px; color:var(--modal-muted); margin:6px 0; }
181
+ .dsh-mios-modal .modal-line b { color:var(--modal-fg); font-weight:600; max-width:200px;
182
+ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
183
+ .dsh-mios-modal .modal-line b.new { color:var(--modal-accent); }
184
+ .dsh-mios-modal .modal-note { margin:12px 0 4px; font-size:11px; color:var(--modal-muted); line-height:1.6; }
185
+ .dsh-mios-modal .modal-actions { display:flex; gap:8px; margin-top:14px; }
186
+ .dsh-mios-modal .modal-actions button { flex:1; padding:8px 0; border-radius:8px; cursor:pointer;
187
+ font-family:inherit; font-size:12px; font-weight:600; line-height:1.4;
188
+ border:1px solid var(--modal-border); background:var(--modal-btn); color:var(--modal-fg); }
189
+ .dsh-mios-modal .modal-actions button.primary { border-color:var(--modal-accent);
190
+ background:rgba(63,178,127,.16); color:var(--modal-accent); }
191
+ .dsh-mios-modal .modal-actions button:disabled { opacity:.6; cursor:default; }
167
192
  .dsh-mios-panel .row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin: 3px 0; }
168
193
  .dsh-mios-panel .row b { color: var(--fg); font-weight: 600; text-align: right; max-width: 170px;
169
194
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -271,6 +296,7 @@ window.__ModuleLoader__.load({
271
296
  function removePanel() {
272
297
  panelEl?.remove();
273
298
  panelEl = null;
299
+ closeUpdateModal();
274
300
  if (summaryPollTimer) {
275
301
  clearInterval(summaryPollTimer);
276
302
  summaryPollTimer = null;
@@ -558,20 +584,23 @@ window.__ModuleLoader__.load({
558
584
  dot.className = 'dsh-mios-dot down';
559
585
  const title = document.createElement('span');
560
586
  title.textContent = PANEL_TITLE;
561
- // 插件更新:放在关闭按钮左边,点开内联结果,不弹窗不跳页
587
+ // 插件更新:放在关闭按钮左边,点击弹出更新对话框(版本对比 + 更新与否由用户选)
562
588
  const updBtn = document.createElement('button');
563
589
  updBtn.className = 'dsh-mios-upd';
564
590
  updBtn.textContent = '插件更新';
565
- updBtn.addEventListener('click', () => checkPluginUpdate());
591
+ updBtn.addEventListener('click', () => {
592
+ // 点击务必先有可见反馈再联网,避免「无反应」错觉(缓存旧模块时旧逻辑写已移除的内联元素)。
593
+ try { checkPluginUpdate(); } catch (e) {
594
+ console.error('[dsh-mobile-ios] checkPluginUpdate failed:', e);
595
+ showUpdateModal({ title: '插件更新', lines: [], note: `打开更新检查失败:${e?.message || e}`, actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }] });
596
+ }
597
+ });
566
598
  const close = document.createElement('button');
567
599
  close.className = 'dsh-mios-close';
568
600
  close.textContent = '✕';
569
601
  close.setAttribute('aria-label', '关闭面板');
570
602
  close.addEventListener('click', removePanel);
571
603
  header.append(dot, title, updBtn, close);
572
- const updResult = document.createElement('div');
573
- updResult.id = 'dsh-mios-upd-result';
574
- updResult.style.display = 'none';
575
604
 
576
605
  const body = document.createElement('div');
577
606
  body.append(
@@ -618,7 +647,7 @@ window.__ModuleLoader__.load({
618
647
  const footer = document.createElement('footer');
619
648
  footer.textContent = 'iPhone/iPad App → 连接 → 扫码(约 2 分钟有效)';
620
649
 
621
- panelEl.append(header, updResult, body, lanBanner, remoteBanner, hint, footer);
650
+ panelEl.append(header, body, lanBanner, remoteBanner, hint, footer);
622
651
  document.body.append(panelEl);
623
652
  applyPanelTheme();
624
653
  placePanelAboveTrigger();
@@ -649,13 +678,90 @@ window.__ModuleLoader__.load({
649
678
 
650
679
  /** 更新检查:与「添加插件」同源,读 npm registry 的 latest 比对当前版本。
651
680
  * 404 = 包未发布(本地开发版);网络失败 = 如实报不可达,二者不混为一谈。 */
681
+ /** 更新对话框:显示版本对比,更新与否由用户选;随面板销毁清理。 */
682
+ let updateModal = null;
683
+ function closeUpdateModal() {
684
+ updateModal?.remove();
685
+ updateModal = null;
686
+ }
687
+ function showUpdateModal({ title, lines, note, actions }) {
688
+ closeUpdateModal();
689
+ const mask = document.createElement('div');
690
+ mask.className = 'dsh-mios-modal-mask';
691
+ if (detectHostTheme() === 'light') mask.classList.add('light');
692
+ const box = document.createElement('div');
693
+ box.className = 'dsh-mios-modal';
694
+
695
+ const h = document.createElement('h4');
696
+ h.textContent = title;
697
+ const x = document.createElement('button');
698
+ x.className = 'modal-x';
699
+ x.textContent = '✕';
700
+ x.setAttribute('aria-label', '关闭');
701
+ x.addEventListener('click', closeUpdateModal);
702
+ h.append(x);
703
+ box.append(h);
704
+
705
+ for (const line of lines || []) {
706
+ const row = document.createElement('div');
707
+ row.className = 'modal-line';
708
+ const label = document.createElement('span');
709
+ label.textContent = line.label;
710
+ const value = document.createElement('b');
711
+ value.textContent = line.value;
712
+ if (line.highlight) value.className = 'new';
713
+ row.append(label, value);
714
+ box.append(row);
715
+ }
716
+ if (note) {
717
+ const n = document.createElement('div');
718
+ n.className = 'modal-note';
719
+ n.textContent = note;
720
+ box.append(n);
721
+ }
722
+
723
+ const bar = document.createElement('div');
724
+ bar.className = 'modal-actions';
725
+ for (const action of actions || []) {
726
+ const btn = document.createElement('button');
727
+ btn.textContent = action.label;
728
+ if (action.primary) btn.className = 'primary';
729
+ btn.addEventListener('click', () => action.onClick?.(btn));
730
+ bar.append(btn);
731
+ }
732
+ box.append(bar);
733
+ mask.append(box);
734
+ mask.addEventListener('click', (e) => { if (e.target === mask) closeUpdateModal(); });
735
+ document.body.append(mask);
736
+ updateModal = mask;
737
+ }
738
+
739
+ /** 复制文本:clipboard API 不可用时回退到 textarea + execCommand。 */
740
+ async function copyToClipboard(text) {
741
+ try {
742
+ if (navigator.clipboard?.writeText) {
743
+ await navigator.clipboard.writeText(text);
744
+ return true;
745
+ }
746
+ } catch { /* 落到下面的回退 */ }
747
+ try {
748
+ const ta = document.createElement('textarea');
749
+ ta.value = text;
750
+ ta.style.position = 'fixed';
751
+ ta.style.opacity = '0';
752
+ document.body.append(ta);
753
+ ta.select();
754
+ const ok = document.execCommand('copy');
755
+ ta.remove();
756
+ return ok;
757
+ } catch {
758
+ return false;
759
+ }
760
+ }
761
+
652
762
  async function checkPluginUpdate() {
653
- const box = panelEl?.querySelector('#dsh-mios-upd-result');
654
- if (!box) return;
655
- box.style.display = '';
656
- box.textContent = '正在检查更新…';
657
- box.className = 'upd-result';
658
- const current = summary?.version || '';
763
+ showUpdateModal({ title: '插件更新', lines: [], note: '正在检查更新…', actions: [] });
764
+ const current = summary?.version || '未知';
659
765
  let latest = '';
660
766
  let sawNotFound = false;
661
767
  let lastError = null;
@@ -671,21 +777,45 @@ window.__ModuleLoader__.load({
671
777
  }
672
778
  }
673
779
  if (!latest) {
674
- box.className = 'upd-result';
675
- if (sawNotFound) {
676
- box.textContent = '插件尚未发布到 npm,当前为本地开发版。'
677
- + '更新方式:拉取仓库最新代码后重启 DSH 桌面端,插件会随源码热重载。';
678
- } else {
679
- box.textContent = `更新源暂不可达${lastError ? `(${lastError.message})` : ''},无法确认是否有新版本。`;
680
- }
780
+ showUpdateModal({
781
+ title: '插件更新',
782
+ lines: [{ label: '当前版本', value: `v${current}` }],
783
+ note: sawNotFound
784
+ ? '插件尚未发布到 npm,当前为本地开发版。更新方式:拉取仓库最新代码后重启 DSH 桌面端,插件会随源码热重载。'
785
+ : `更新源暂不可达${lastError ? `(${lastError.message})` : ''},无法确认是否有新版本。`,
786
+ actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
787
+ });
681
788
  return;
682
789
  }
683
790
  if (compareVersions(latest, current) > 0) {
684
- box.className = 'upd-result has-update';
685
- box.textContent = `发现新版 v${latest}(当前 v${current}):到 DSH 插件页卸载本插件后重新安装,或输包名 ${PLUGIN_NAME}@${latest} 更新。`;
791
+ showUpdateModal({
792
+ title: '发现新版本',
793
+ lines: [
794
+ { label: '当前版本', value: `v${current}` },
795
+ { label: '最新版本', value: `v${latest}`, highlight: true },
796
+ ],
797
+ note: '更新方式:复制下方包名,到 DSH「插件 → 添加插件」粘贴即可覆盖安装。是否更新由你决定。',
798
+ actions: [
799
+ { label: '稍后再说', onClick: closeUpdateModal },
800
+ {
801
+ label: `复制 ${PLUGIN_NAME}@${latest}`, primary: true,
802
+ onClick: async (btn) => {
803
+ const ok = await copyToClipboard(`${PLUGIN_NAME}@${latest}`);
804
+ btn.textContent = ok ? '已复制,去插件页粘贴安装' : '复制失败,请手动复制包名';
805
+ },
806
+ },
807
+ ],
808
+ });
686
809
  } else {
687
- box.className = 'upd-result';
688
- box.textContent = `已是最新版本 v${current}(npm v${latest})。`;
810
+ showUpdateModal({
811
+ title: '已是最新版本',
812
+ lines: [
813
+ { label: '当前版本', value: `v${current}` },
814
+ { label: 'npm 最新', value: `v${latest}` },
815
+ ],
816
+ note: '当前版本已是最新,无需更新。',
817
+ actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
818
+ });
689
819
  }
690
820
  }
691
821
 
@@ -846,7 +976,10 @@ window.__ModuleLoader__.load({
846
976
  const inject = ['slots'];
847
977
  exports.apply = apply;
848
978
  exports.inject = inject;
849
- exports.__test = { PORT_CANDIDATES, STATUS_OK, STATUS_DOWN };
979
+ exports.__test = {
980
+ PORT_CANDIDATES, STATUS_OK, STATUS_DOWN,
981
+ showUpdateModal, closeUpdateModal, copyToClipboard,
982
+ };
850
983
 
851
984
  return module.exports;
852
985
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mobile-ios",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "description": "DSH iOS移动伴侣:iPhone/iPad 扫码连接 DSH 桌面端,局域网直连 + Cloudflare Tunnel 固定域名远程两种通道",
6
6
  "main": "entries/plugin.mjs",
@@ -30,7 +30,7 @@
30
30
  "start": "node entries/sidecar.mjs --host=mock --dev",
31
31
  "start:lan": "node entries/sidecar.mjs --host=mock --dev --lan=true",
32
32
  "probe": "node spike0/probe.mjs",
33
- "test": "node test/selftest.mjs && node test/version.mjs && node test/ops.mjs && node test/resilience.mjs && node test/borrowed.mjs && node test/mux-table.mjs && node test/live-frames.mjs && node test/artifacts.mjs && node test/attachments.mjs && node test/session-actions.mjs && node test/enhance.mjs && node test/tunnel-named.mjs"
33
+ "test": "node test/selftest.mjs && node test/version.mjs && node test/update-dialog.mjs && node test/ops.mjs && node test/resilience.mjs && node test/borrowed.mjs && node test/mux-table.mjs && node test/live-frames.mjs && node test/artifacts.mjs && node test/attachments.mjs && node test/session-actions.mjs && node test/enhance.mjs && node test/tunnel-named.mjs"
34
34
  },
35
35
  "dsh": {
36
36
  "bundle": {