dsh-mobile-ios 0.2.3 → 0.2.4

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 +151 -25
  2. package/package.json +2 -2
package/lib/client.js CHANGED
@@ -162,8 +162,32 @@ window.__ModuleLoader__.load({
162
162
  .dsh-mios-upd { margin-left: auto; background: none; border: 1px solid var(--border); border-radius: 7px;
163
163
  color: var(--muted); font: 500 11px/1.4 inherit, sans-serif; cursor: pointer; padding: 3px 8px; }
164
164
  .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; }
165
+ .dsh-mios-modal-mask { --modal-bg:#1c2230; --modal-fg:#e8eaf0; --modal-muted:#8b93a3;
166
+ --modal-border:#3a4560; --modal-btn:rgba(139,147,163,.12); --modal-accent:#3fb27f; --modal-shadow:rgba(0,0,0,.6);
167
+ position:fixed; inset:0; z-index:100000; background:var(--modal-shadow);
168
+ display:flex; align-items:center; justify-content:center; padding:20px;
169
+ font-family:-apple-system, "PingFang SC", sans-serif; font-size:13px; line-height:1.6; }
170
+ .dsh-mios-modal-mask.light { --modal-bg:#ffffff; --modal-fg:#1f2430; --modal-muted:#6b7280;
171
+ --modal-border:#d9dee8; --modal-btn:rgba(107,114,128,.1); --modal-accent:#2f9d70; --modal-shadow:rgba(31,36,48,.35); }
172
+ .dsh-mios-modal { width:100%; max-width:340px; box-sizing:border-box; background:var(--modal-bg);
173
+ color:var(--modal-fg); border:1px solid var(--modal-border); border-radius:14px; padding:18px;
174
+ box-shadow:0 18px 60px var(--modal-shadow); }
175
+ .dsh-mios-modal h4 { margin:0 0 12px; font-size:15px; display:flex; align-items:center; gap:8px; }
176
+ .dsh-mios-modal .modal-x { margin-left:auto; background:none; border:none; color:var(--modal-muted);
177
+ font-size:16px; cursor:pointer; line-height:1; padding:2px 4px; }
178
+ .dsh-mios-modal .modal-line { display:flex; justify-content:space-between; gap:10px;
179
+ font-size:12px; color:var(--modal-muted); margin:6px 0; }
180
+ .dsh-mios-modal .modal-line b { color:var(--modal-fg); font-weight:600; max-width:200px;
181
+ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
182
+ .dsh-mios-modal .modal-line b.new { color:var(--modal-accent); }
183
+ .dsh-mios-modal .modal-note { margin:12px 0 4px; font-size:11px; color:var(--modal-muted); line-height:1.6; }
184
+ .dsh-mios-modal .modal-actions { display:flex; gap:8px; margin-top:14px; }
185
+ .dsh-mios-modal .modal-actions button { flex:1; padding:8px 0; border-radius:8px; cursor:pointer;
186
+ font-family:inherit; font-size:12px; font-weight:600; line-height:1.4;
187
+ border:1px solid var(--modal-border); background:var(--modal-btn); color:var(--modal-fg); }
188
+ .dsh-mios-modal .modal-actions button.primary { border-color:var(--modal-accent);
189
+ background:rgba(63,178,127,.16); color:var(--modal-accent); }
190
+ .dsh-mios-modal .modal-actions button:disabled { opacity:.6; cursor:default; }
167
191
  .dsh-mios-panel .row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin: 3px 0; }
168
192
  .dsh-mios-panel .row b { color: var(--fg); font-weight: 600; text-align: right; max-width: 170px;
169
193
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -271,6 +295,7 @@ window.__ModuleLoader__.load({
271
295
  function removePanel() {
272
296
  panelEl?.remove();
273
297
  panelEl = null;
298
+ closeUpdateModal();
274
299
  if (summaryPollTimer) {
275
300
  clearInterval(summaryPollTimer);
276
301
  summaryPollTimer = null;
@@ -558,7 +583,7 @@ window.__ModuleLoader__.load({
558
583
  dot.className = 'dsh-mios-dot down';
559
584
  const title = document.createElement('span');
560
585
  title.textContent = PANEL_TITLE;
561
- // 插件更新:放在关闭按钮左边,点开内联结果,不弹窗不跳页
586
+ // 插件更新:放在关闭按钮左边,点击弹出更新对话框(版本对比 + 更新与否由用户选)
562
587
  const updBtn = document.createElement('button');
563
588
  updBtn.className = 'dsh-mios-upd';
564
589
  updBtn.textContent = '插件更新';
@@ -569,9 +594,6 @@ window.__ModuleLoader__.load({
569
594
  close.setAttribute('aria-label', '关闭面板');
570
595
  close.addEventListener('click', removePanel);
571
596
  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
597
 
576
598
  const body = document.createElement('div');
577
599
  body.append(
@@ -618,7 +640,7 @@ window.__ModuleLoader__.load({
618
640
  const footer = document.createElement('footer');
619
641
  footer.textContent = 'iPhone/iPad App → 连接 → 扫码(约 2 分钟有效)';
620
642
 
621
- panelEl.append(header, updResult, body, lanBanner, remoteBanner, hint, footer);
643
+ panelEl.append(header, body, lanBanner, remoteBanner, hint, footer);
622
644
  document.body.append(panelEl);
623
645
  applyPanelTheme();
624
646
  placePanelAboveTrigger();
@@ -649,13 +671,90 @@ window.__ModuleLoader__.load({
649
671
 
650
672
  /** 更新检查:与「添加插件」同源,读 npm registry 的 latest 比对当前版本。
651
673
  * 404 = 包未发布(本地开发版);网络失败 = 如实报不可达,二者不混为一谈。 */
674
+ /** 更新对话框:显示版本对比,更新与否由用户选;随面板销毁清理。 */
675
+ let updateModal = null;
676
+ function closeUpdateModal() {
677
+ updateModal?.remove();
678
+ updateModal = null;
679
+ }
680
+ function showUpdateModal({ title, lines, note, actions }) {
681
+ closeUpdateModal();
682
+ const mask = document.createElement('div');
683
+ mask.className = 'dsh-mios-modal-mask';
684
+ if (detectHostTheme() === 'light') mask.classList.add('light');
685
+ const box = document.createElement('div');
686
+ box.className = 'dsh-mios-modal';
687
+
688
+ const h = document.createElement('h4');
689
+ h.textContent = title;
690
+ const x = document.createElement('button');
691
+ x.className = 'modal-x';
692
+ x.textContent = '✕';
693
+ x.setAttribute('aria-label', '关闭');
694
+ x.addEventListener('click', closeUpdateModal);
695
+ h.append(x);
696
+ box.append(h);
697
+
698
+ for (const line of lines || []) {
699
+ const row = document.createElement('div');
700
+ row.className = 'modal-line';
701
+ const label = document.createElement('span');
702
+ label.textContent = line.label;
703
+ const value = document.createElement('b');
704
+ value.textContent = line.value;
705
+ if (line.highlight) value.className = 'new';
706
+ row.append(label, value);
707
+ box.append(row);
708
+ }
709
+ if (note) {
710
+ const n = document.createElement('div');
711
+ n.className = 'modal-note';
712
+ n.textContent = note;
713
+ box.append(n);
714
+ }
715
+
716
+ const bar = document.createElement('div');
717
+ bar.className = 'modal-actions';
718
+ for (const action of actions || []) {
719
+ const btn = document.createElement('button');
720
+ btn.textContent = action.label;
721
+ if (action.primary) btn.className = 'primary';
722
+ btn.addEventListener('click', () => action.onClick?.(btn));
723
+ bar.append(btn);
724
+ }
725
+ box.append(bar);
726
+ mask.append(box);
727
+ mask.addEventListener('click', (e) => { if (e.target === mask) closeUpdateModal(); });
728
+ document.body.append(mask);
729
+ updateModal = mask;
730
+ }
731
+
732
+ /** 复制文本:clipboard API 不可用时回退到 textarea + execCommand。 */
733
+ async function copyToClipboard(text) {
734
+ try {
735
+ if (navigator.clipboard?.writeText) {
736
+ await navigator.clipboard.writeText(text);
737
+ return true;
738
+ }
739
+ } catch { /* 落到下面的回退 */ }
740
+ try {
741
+ const ta = document.createElement('textarea');
742
+ ta.value = text;
743
+ ta.style.position = 'fixed';
744
+ ta.style.opacity = '0';
745
+ document.body.append(ta);
746
+ ta.select();
747
+ const ok = document.execCommand('copy');
748
+ ta.remove();
749
+ return ok;
750
+ } catch {
751
+ return false;
752
+ }
753
+ }
754
+
652
755
  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 || '';
756
+ showUpdateModal({ title: '插件更新', lines: [], note: '正在检查更新…', actions: [] });
757
+ const current = summary?.version || '未知';
659
758
  let latest = '';
660
759
  let sawNotFound = false;
661
760
  let lastError = null;
@@ -671,21 +770,45 @@ window.__ModuleLoader__.load({
671
770
  }
672
771
  }
673
772
  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
- }
773
+ showUpdateModal({
774
+ title: '插件更新',
775
+ lines: [{ label: '当前版本', value: `v${current}` }],
776
+ note: sawNotFound
777
+ ? '插件尚未发布到 npm,当前为本地开发版。更新方式:拉取仓库最新代码后重启 DSH 桌面端,插件会随源码热重载。'
778
+ : `更新源暂不可达${lastError ? `(${lastError.message})` : ''},无法确认是否有新版本。`,
779
+ actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
780
+ });
681
781
  return;
682
782
  }
683
783
  if (compareVersions(latest, current) > 0) {
684
- box.className = 'upd-result has-update';
685
- box.textContent = `发现新版 v${latest}(当前 v${current}):到 DSH 插件页卸载本插件后重新安装,或输包名 ${PLUGIN_NAME}@${latest} 更新。`;
784
+ showUpdateModal({
785
+ title: '发现新版本',
786
+ lines: [
787
+ { label: '当前版本', value: `v${current}` },
788
+ { label: '最新版本', value: `v${latest}`, highlight: true },
789
+ ],
790
+ note: '更新方式:复制下方包名,到 DSH「插件 → 添加插件」粘贴即可覆盖安装。是否更新由你决定。',
791
+ actions: [
792
+ { label: '稍后再说', onClick: closeUpdateModal },
793
+ {
794
+ label: `复制 ${PLUGIN_NAME}@${latest}`, primary: true,
795
+ onClick: async (btn) => {
796
+ const ok = await copyToClipboard(`${PLUGIN_NAME}@${latest}`);
797
+ btn.textContent = ok ? '已复制,去插件页粘贴安装' : '复制失败,请手动复制包名';
798
+ },
799
+ },
800
+ ],
801
+ });
686
802
  } else {
687
- box.className = 'upd-result';
688
- box.textContent = `已是最新版本 v${current}(npm v${latest})。`;
803
+ showUpdateModal({
804
+ title: '已是最新版本',
805
+ lines: [
806
+ { label: '当前版本', value: `v${current}` },
807
+ { label: 'npm 最新', value: `v${latest}` },
808
+ ],
809
+ note: '当前版本已是最新,无需更新。',
810
+ actions: [{ label: '知道了', primary: true, onClick: closeUpdateModal }],
811
+ });
689
812
  }
690
813
  }
691
814
 
@@ -846,7 +969,10 @@ window.__ModuleLoader__.load({
846
969
  const inject = ['slots'];
847
970
  exports.apply = apply;
848
971
  exports.inject = inject;
849
- exports.__test = { PORT_CANDIDATES, STATUS_OK, STATUS_DOWN };
972
+ exports.__test = {
973
+ PORT_CANDIDATES, STATUS_OK, STATUS_DOWN,
974
+ showUpdateModal, closeUpdateModal, copyToClipboard,
975
+ };
850
976
 
851
977
  return module.exports;
852
978
  },
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.4",
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": {