@restregular/dsh-powerup 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -30,7 +30,9 @@ Right-click empty space in the ledger:
30
30
  - **Open the Power-Up page** — the sidebar control panel.
31
31
 
32
32
  The sidebar **Power-Up** page turns the menu on or off and lists the available
33
- actions. The setting is stored in the browser.
33
+ actions. The setting is stored in the browser. It also holds the defaults for
34
+ **one-click update** (auto-enable and auto-restart), which the plugin updater
35
+ uses.
34
36
 
35
37
  ### Stop a background job with a reason
36
38
 
@@ -64,14 +66,25 @@ update dialog:
64
66
  2. Type a version or pick one from the floating version list. The current
65
67
  installed version is tagged **Current**; the newest is tagged **latest**, and
66
68
  a version that is both uses one **Current · latest** tag.
67
- 3. Confirming removes the installed copy, checks the new spec the way **Add
68
- plugin** does, and installs the selected version without enabling it.
69
- 4. The dialog then asks whether to enable the new version.
70
- 5. After enabling, it asks whether to restart DSH. On the desktop app the
69
+ 3. **One-click update** installs the newest version and skips both questions:
70
+ by default the new copy is enabled and DSH restarts automatically. The
71
+ Power-Up page can turn either default off. With auto-enable off, the new
72
+ version is left disabled and nothing restarts. With auto-restart off (or when
73
+ the current runtime cannot restart itself), the completion panel closes
74
+ itself after a few seconds instead of staying on screen. Power-Up's own
75
+ update keeps its background handoff and does not offer one-click.
76
+ 4. Otherwise, confirming removes the installed copy, checks the new spec the
77
+ way **Add plugin** does, and installs the selected version without enabling
78
+ it. Because the old copy is already gone at that point, a refused check or a
79
+ failed install automatically re-installs the removed version with its
80
+ previous enabled state; the dialog reports both the failure and the rollback
81
+ result.
82
+ 5. The dialog then asks whether to enable the new version.
83
+ 6. After enabling, it asks whether to restart DSH. On the desktop app the
71
84
  `lib/restart-helper.cjs` helper relaunches the exact executable after the old
72
85
  Host exits; under `dsh web` the dialog explains that the terminal owns the
73
86
  process.
74
- 6. A management call that reports `restart-required` keeps a **Restart needed**
87
+ 7. A management call that reports `restart-required` keeps a **Restart needed**
75
88
  tag on the card and adds the plugin to the count beside the **Installed
76
89
  plugins** heading. The heading bar is always present — with **No plugins need
77
90
  a restart** and the restart button when nothing is pending — and a **Restart
@@ -80,11 +93,11 @@ update dialog:
80
93
  the built-in **Add plugin** / **Update** UI, or before this page loaded, are
81
94
  marked too.
82
95
 
83
- Power-Up updates itself through the same dialog. Because removing the plugin
84
- unloads this panel, the Host answers first and then hands `removeBundle` →
85
- `inspect` → `installBundle(enabled: true)` to the built-in manager service,
86
- which keeps running after the Power-Up Host fiber is unloaded. The panel closes;
87
- refresh the page when the install finishes.
96
+ Power-Up updates itself through the same dialog (the one-click action is hidden
97
+ for itself). Because removing the plugin unloads this panel, the Host answers
98
+ first and then hands `removeBundle` → `inspect` → `installBundle(enabled: true)`
99
+ to the built-in manager service, which keeps running after the Power-Up Host
100
+ fiber is unloaded. The panel closes; refresh the page when the install finishes.
88
101
 
89
102
  ## Design notes
90
103
 
@@ -124,7 +137,17 @@ refresh the page when the install finishes.
124
137
  through the built-in manager service. Removing the bundle unloads Power-Up's
125
138
  own Host fiber, but the manager service and the pending promise stay in the
126
139
  Host process, so the reinstall finishes; failures are appended to
127
- `~/.dsh/powerup/self-update.log`.
140
+ `~/.dsh/powerup/self-update.log`. The Host captures the version it was loaded
141
+ from before removal and re-installs that version if the check or install
142
+ fails, so a failed self-update does not leave Power-Up missing.
143
+ - **One-click update is a client-side decision.** The newest version and both
144
+ defaults live in the shared settings store (`dsh-powerup:settings:v1`), so the
145
+ Power-Up page and an open dialog agree without a reload. A one-click run
146
+ installs disabled — the same shape as **Add plugin** — then enables through
147
+ `setBundleEnabled`, and posts the restart only when the defaults allow it. With
148
+ auto-enable off the new copy stays disabled and nothing restarts. When no
149
+ restart happens the completion panel closes on a timer; install, enable, and
150
+ restart failures stay on screen with their reason instead.
128
151
  - **Restart status lives in this browser session.** A management result that
129
152
  says `restart-required` is written to `sessionStorage`; the card gets a
130
153
  **Restart needed** tag and the group heading gets a count plus a restart
package/client.js CHANGED
@@ -44,9 +44,11 @@
44
44
 
45
45
  const NS = 'dsh-powerup';
46
46
  const SETTINGS_KEY = 'dsh-powerup:settings:v1';
47
- const VERSION = '0.4.0';
47
+ const VERSION = '0.5.0';
48
48
  const MENU_GAP = 8;
49
49
  const MENU_WIDTH = 248;
50
+ /** How long a one-click update's completion panel stays open when nothing restarts. */
51
+ const ONE_CLICK_AUTO_CLOSE_MS = 4000;
50
52
 
51
53
  // ------------------------------------------------------------------
52
54
  // Dictionaries
@@ -66,8 +68,14 @@
66
68
  'page.how2': '在记录行上右键;在空白处右键可执行会话级操作。',
67
69
  'page.how3': '菜单支持 ↑ / ↓ 选择、Enter 执行、Esc 关闭。',
68
70
  'page.updateTitle': '插件自更新',
69
- 'page.updateDesc': '在插件页为每个第三方已安装插件提供更新入口:从安装源选版本、卸载旧版、按「添加插件」流程重装,并可立即启用与重启 DSH。',
70
- 'page.updateHow': '打开侧边栏的「插件」页,在「已安装插件」分组中点击卡片右侧的更新图标。',
71
+ 'page.updateDesc': '在插件页为每个第三方已安装插件提供更新入口:从安装源选版本、卸载旧版、按「添加插件」流程重装,并可立即启用与重启 DSH;也可以一键更新到最新版。',
72
+ 'page.updateHow': '打开侧边栏的「插件」页,在「已安装插件」分组中点击卡片右侧的更新图标;在更新面板里点「一键更新」即可安装最新版,并按下面的默认行为处理。',
73
+ 'page.oneClickTitle': '一键更新',
74
+ 'page.oneClickDesc': '在更新面板里点「一键更新」时,直接安装最新版本,跳过「是否启用」和「是否重启」的询问。',
75
+ 'page.oneClickEnable': '自动启用新版本',
76
+ 'page.oneClickEnableHint': '关闭后,一键更新只安装新版本,保持停用,也不自动重启。',
77
+ 'page.oneClickRestart': '自动重启 DSH',
78
+ 'page.oneClickRestartHint': '关闭后,更新完成的提示会自动关闭。',
71
79
  'page.jobStopTitle': '后台任务停止原因',
72
80
  'page.jobStopDesc': '在会话顶部的后台任务面板里点停止按钮时,可以顺手填写停止原因;原因会附加在任务结束后注入会话的提示里。',
73
81
  'page.jobStopHow': '打开任意会话,点顶部的「后台任务」面板,在运行中的任务右侧点停止,填写原因(可留空)后确认。',
@@ -151,6 +159,7 @@
151
159
  'update.step.checking': '正在校验版本…',
152
160
  'update.step.removing': '正在卸载旧版…',
153
161
  'update.step.installing': '正在安装 {version}…',
162
+ 'update.step.rollback': '正在恢复旧版本 {version}…',
154
163
  'update.step.enabling': '正在启用…',
155
164
  'update.log': '安装输出',
156
165
  'update.enableTitle': '安装完成,是否立即启用?',
@@ -185,8 +194,24 @@
185
194
  'update.doneDisabled': '{name} 已安装 {version},尚未启用。',
186
195
  'update.doneEnabled': '新版本已启用。',
187
196
  'update.doneRestart': '部分更改需要重启 DSH 后生效。',
197
+ 'update.doneAutoClose': '完成面板将在 {seconds} 秒后自动关闭。',
188
198
  'update.doneButton': '完成',
199
+ 'update.oneClick': '一键更新',
200
+ 'update.oneClickTitle': '一键更新',
201
+ 'update.oneClickHint': '安装最新版本 {version},跳过「是否启用」和「是否重启」的询问。',
202
+ 'update.oneClickDefaults': '自动启用:{enable} · 自动重启:{restart}。可在侧边栏 Power-Up 页面修改。',
203
+ 'update.on': '开',
204
+ 'update.off': '关',
205
+ 'update.oneClickNoLatest': '暂时读不到最新版本,请重试或手动选择版本。',
206
+ 'update.oneClickUpToDate': '已经是最新版本,无需更新。',
207
+ 'update.oneClickEnableFailed': '新版本已安装,但自动启用失败。请到「插件」页手动启用。',
208
+ 'update.oneClickSkippedEnable': '已按设置保持停用;需要时到「插件」页启用。',
189
209
  'update.errorTitle': '更新失败',
210
+ 'update.rollbackOkTitle': '已恢复旧版本',
211
+ 'update.rollbackOkDesc': '更新失败,{name} 已自动回滚到 {version},仍可继续使用。',
212
+ 'update.rollbackFailedTitle': '旧版本恢复失败',
213
+ 'update.rollbackFailedDesc': '自动回滚失败:{message}。请到「插件」页用「添加插件」重新安装。',
214
+ 'update.rollbackUnavailable': '无法确定旧版本号,未能自动回滚。请到「插件」页重新安装。',
190
215
  'update.selfTitle': '请用「添加插件」更新 Power-Up 自身',
191
216
  'update.selfDesc': '更新 Power-Up 会先卸载本插件,更新流程会随之中断。',
192
217
  'update.notRemovable': '该插件受 DSH 管理,不能在这里更新。',
@@ -214,8 +239,14 @@
214
239
  'page.how2': 'Right-click a record row; right-click empty space for session actions.',
215
240
  'page.how3': 'Use ↑ / ↓ to move, Enter to run, Esc to close.',
216
241
  'page.updateTitle': 'Update plugins',
217
- 'page.updateDesc': 'Every third-party plugin on the Plugins page gains an update entry: pick a version from a registry, remove the old copy, reinstall through the Add plugin path, then enable and restart DSH.',
218
- 'page.updateHow': 'Open Plugins in the sidebar and click the update icon at the right of a card under Installed plugins.',
242
+ 'page.updateDesc': 'Every third-party plugin on the Plugins page gains an update entry: pick a version from a registry, remove the old copy, reinstall through the Add plugin path, then enable and restart DSH — or update to the newest version in one click.',
243
+ 'page.updateHow': 'Open Plugins in the sidebar and click the update icon at the right of a card under Installed plugins; in the update panel, One-click update installs the newest version using the defaults below.',
244
+ 'page.oneClickTitle': 'One-click update',
245
+ 'page.oneClickDesc': 'One-click update installs the newest version and skips both the enable and the restart questions.',
246
+ 'page.oneClickEnable': 'Enable the new version automatically',
247
+ 'page.oneClickEnableHint': 'When off, one-click update only installs it, leaves it disabled, and does not restart.',
248
+ 'page.oneClickRestart': 'Restart DSH automatically',
249
+ 'page.oneClickRestartHint': 'When off, the completion panel closes itself.',
219
250
  'page.jobStopTitle': 'Background job stop reason',
220
251
  'page.jobStopDesc': 'When you stop a running job from the background jobs panel in the session header, you can leave a reason; the reason is appended to the notice injected into the session when the job settles.',
221
252
  'page.jobStopHow': 'Open a session, expand the background jobs panel, press stop on a running job, type a reason (optional), then confirm.',
@@ -299,6 +330,7 @@
299
330
  'update.step.checking': 'Checking the version…',
300
331
  'update.step.removing': 'Removing the old version…',
301
332
  'update.step.installing': 'Installing {version}…',
333
+ 'update.step.rollback': 'Restoring {version}…',
302
334
  'update.step.enabling': 'Enabling…',
303
335
  'update.log': 'Install output',
304
336
  'update.enableTitle': 'Installed. Enable it now?',
@@ -333,8 +365,24 @@
333
365
  'update.doneDisabled': '{name} {version} is installed but not enabled.',
334
366
  'update.doneEnabled': 'The new version is enabled.',
335
367
  'update.doneRestart': 'Some changes apply only after DSH restarts.',
368
+ 'update.doneAutoClose': 'This panel closes itself in {seconds} seconds.',
336
369
  'update.doneButton': 'Done',
370
+ 'update.oneClick': 'One-click update',
371
+ 'update.oneClickTitle': 'One-click update',
372
+ 'update.oneClickHint': 'Installs the newest version ({version}) and skips the enable and restart questions.',
373
+ 'update.oneClickDefaults': 'Auto-enable: {enable} · Auto-restart: {restart}. Change these on the Power-Up page.',
374
+ 'update.on': 'on',
375
+ 'update.off': 'off',
376
+ 'update.oneClickNoLatest': 'The newest version is not available yet. Retry or pick a version manually.',
377
+ 'update.oneClickUpToDate': 'Already up to date.',
378
+ 'update.oneClickEnableFailed': 'The new version is installed but could not be enabled. Enable it on the Plugins page.',
379
+ 'update.oneClickSkippedEnable': 'Left disabled as configured; enable it on the Plugins page when ready.',
337
380
  'update.errorTitle': 'Update failed',
381
+ 'update.rollbackOkTitle': 'Previous version restored',
382
+ 'update.rollbackOkDesc': 'The update failed, so {name} was rolled back to {version} and is ready to use.',
383
+ 'update.rollbackFailedTitle': 'Could not restore the previous version',
384
+ 'update.rollbackFailedDesc': 'Automatic rollback failed: {message}. Reinstall it from the Plugins page with “Add plugin”.',
385
+ 'update.rollbackUnavailable': 'The previous version is unknown, so no automatic rollback was possible. Reinstall it from the Plugins page.',
338
386
  'update.selfTitle': 'Update Power-Up with Add plugin',
339
387
  'update.selfDesc': 'Updating Power-Up removes this plugin first, which interrupts this flow.',
340
388
  'update.notRemovable': 'DSH manages this plugin; it cannot be updated here.',
@@ -376,16 +424,23 @@
376
424
  // ------------------------------------------------------------------
377
425
  // Settings store (localStorage, per browser)
378
426
  // ------------------------------------------------------------------
427
+ /** One-click update defaults: enable and restart unless the user turned one off. */
428
+ const DEFAULT_SETTINGS = { enabled: true, oneClickEnable: true, oneClickRestart: true };
429
+
379
430
  function readSettings() {
380
431
  try {
381
432
  const parsed = JSON.parse(localStorage.getItem(SETTINGS_KEY) || 'null');
382
433
  if (parsed !== null && typeof parsed === 'object') {
383
- return { enabled: parsed.enabled !== false };
434
+ return {
435
+ enabled: parsed.enabled !== false,
436
+ oneClickEnable: parsed.oneClickEnable !== false,
437
+ oneClickRestart: parsed.oneClickRestart !== false,
438
+ };
384
439
  }
385
440
  } catch {
386
441
  /* Private mode or a corrupted value: use the default. */
387
442
  }
388
- return { enabled: true };
443
+ return { ...DEFAULT_SETTINGS };
389
444
  }
390
445
 
391
446
  let settingsValue = readSettings();
@@ -629,6 +684,16 @@
629
684
  );
630
685
  }
631
686
 
687
+ /** A lightning bolt: the one-click update action. */
688
+ function QuickIcon({ size = 16 }) {
689
+ return h(Icon, { size },
690
+ h('path', {
691
+ d: 'M9.1 1.9 3.9 8.7h3.1L6.9 14l5.2-6.8H9L9.1 1.9Z',
692
+ fill: 'currentColor',
693
+ }),
694
+ );
695
+ }
696
+
632
697
  function StopIcon({ size = 16 }) {
633
698
  return h(Icon, { size },
634
699
  h('rect', {
@@ -707,6 +772,13 @@
707
772
  .dsh-powerup-switch[aria-checked=true] .dsh-powerup-switch-track{background:var(--dsw-alias-brand-primary)}
708
773
  .dsh-powerup-switch[aria-checked=true] .dsh-powerup-switch-thumb{background:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-bg-layer-1));transform:translateX(15px)}
709
774
  .dsh-powerup-section-title{margin:0 0 10px;color:var(--dsw-alias-label-tertiary);font-size:11px;font-weight:600;letter-spacing:.04em;text-transform:uppercase}
775
+ .dsh-powerup-settings{display:flex;flex-direction:column;gap:0;margin-top:12px}
776
+ .dsh-powerup-setting{display:flex;align-items:center;gap:14px;padding:9px 0;border-top:.5px solid var(--dsw-alias-border-l1)}
777
+ .dsh-powerup-setting:first-child{border-top:0;padding-top:4px}
778
+ .dsh-powerup-setting-copy{display:flex;flex:1 1 auto;flex-direction:column;gap:1px;min-width:0}
779
+ .dsh-powerup-setting-label{color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:18px}
780
+ .dsh-powerup-setting-hint{color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:15px}
781
+ .dsh-powerup-setting .dsh-powerup-switch{margin-left:auto}
710
782
  .dsh-powerup-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;margin:0;padding:0;list-style:none}
711
783
  .dsh-powerup-action{display:flex;align-items:flex-start;gap:8px;min-width:0;padding:7px 8px;border-radius:8px}
712
784
  .dsh-powerup-action-icon{flex:none;display:flex;align-items:center;justify-content:center;width:20px;height:20px;margin-top:1px;color:var(--dsw-alias-label-tertiary)}
@@ -847,14 +919,20 @@
847
919
  .dsh-powerup-update-option-title{color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:18px}
848
920
  .dsh-powerup-update-option-host{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px;overflow-wrap:anywhere}
849
921
  .dsh-powerup-update-option .dsh-powerup-update-check{flex:none;margin-top:2px}
850
- .dsh-powerup-update-foot{display:flex;align-items:center;justify-content:flex-end;gap:8px;padding:16px 24px 22px;border-top:.5px solid var(--dsw-alias-border-l1)}
922
+ .dsh-powerup-update-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:8px;padding:16px 24px 22px;border-top:.5px solid var(--dsw-alias-border-l1)}
851
923
  .dsh-powerup-update-primary{height:36px;padding:0 14px;border:0;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-button-primary-fill,var(--dsw-alias-brand-primary));color:var(--dsw-alias-label-primary-foreground);font:inherit;font-size:14px;line-height:22px;cursor:pointer;transition:background .14s ease}
852
924
  .dsh-powerup-update-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,var(--dsw-alias-brand-primary))}
853
925
  .dsh-powerup-update-primary:disabled{opacity:.4;cursor:not-allowed}
854
926
  .dsh-powerup-update-ghost{height:36px;padding:0 14px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:14px;line-height:22px;cursor:pointer}
855
927
  .dsh-powerup-update-ghost:hover{background:var(--dsw-alias-interactive-bg-hover)}
856
928
  .dsh-powerup-update-ghost:active{background:var(--dsw-alias-interactive-bg-active)}
857
- .dsh-powerup-update-close:focus-visible,.dsh-powerup-update-toggle:focus-visible,.dsh-powerup-update-version:focus-visible,.dsh-powerup-update-select-trigger:focus-visible,.dsh-powerup-update-option:focus-visible,.dsh-powerup-update-primary:focus-visible,.dsh-powerup-update-ghost:focus-visible,.dsh-powerup-update-button:focus-visible,.dsh-powerup-restart-action:focus-visible,.dsh-powerup-update-default:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
929
+ .dsh-powerup-update-quick{display:inline-flex;align-items:center;gap:6px;height:36px;padding:0 13px;border:.5px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary) 38%,transparent);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-state-warn-tertiary);color:var(--dsw-alias-state-warn-label);font:inherit;font-size:13.5px;line-height:20px;white-space:nowrap;cursor:pointer;transition:background .14s ease,border-color .14s ease}
930
+ .dsh-powerup-update-quick:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 16%,transparent)}
931
+ .dsh-powerup-update-quick:disabled{opacity:.45;cursor:not-allowed}
932
+ .dsh-powerup-update-quick-note{display:flex;flex-direction:column;gap:4px;padding:10px 12px;border:.5px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary) 26%,transparent);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-state-warn-tertiary)}
933
+ .dsh-powerup-update-quick-note-title{display:flex;align-items:center;gap:6px;color:var(--dsw-alias-state-warn-label);font-size:12px;line-height:17px;font-weight:500}
934
+ .dsh-powerup-update-quick-note .dsh-powerup-update-note{color:var(--dsw-alias-label-secondary)}
935
+ .dsh-powerup-update-close:focus-visible,.dsh-powerup-update-toggle:focus-visible,.dsh-powerup-update-version:focus-visible,.dsh-powerup-update-select-trigger:focus-visible,.dsh-powerup-update-option:focus-visible,.dsh-powerup-update-primary:focus-visible,.dsh-powerup-update-ghost:focus-visible,.dsh-powerup-update-quick:focus-visible,.dsh-powerup-update-button:focus-visible,.dsh-powerup-restart-action:focus-visible,.dsh-powerup-update-default:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
858
936
  @media (max-width:680px){.dsh-powerup-page{padding:20px 16px 42px}.dsh-powerup-actions{grid-template-columns:minmax(0,1fr)}.dsh-powerup-hero-art{width:54px;height:54px}.dsh-powerup-hero h1{font-size:19px}.dsh-powerup-card-head{flex-wrap:wrap}.dsh-powerup-switch{margin-left:auto}.dsh-powerup-update-mask{padding:12px}.dsh-powerup-update-dialog{max-height:calc(100dvh - 24px)}.dsh-powerup-update-head{padding:18px 12px 10px 18px}.dsh-powerup-update-body{padding:0 18px 4px}.dsh-powerup-update-foot{padding:14px 18px 18px}}
859
937
  `;
860
938
 
@@ -1614,6 +1692,33 @@
1614
1692
  return /^\d+(?:\.\d+)*(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(text) ? text : '';
1615
1693
  }
1616
1694
 
1695
+ /**
1696
+ * The version a one-click update targets: the registry's `latest` tag,
1697
+ * falling back to the first row of the already sorted version list.
1698
+ * @param {{ latest?: unknown, versions?: unknown }} view
1699
+ * @returns {string} a concrete version, or '' when none is known yet.
1700
+ */
1701
+ function oneClickVersion(view) {
1702
+ const declared = normalizeVersionInput(view?.latest);
1703
+ if (declared !== '') return declared;
1704
+ const first = Array.isArray(view?.versions) ? view.versions[0] : null;
1705
+ return normalizeVersionInput(first);
1706
+ }
1707
+
1708
+ /**
1709
+ * Whether a target version is strictly newer than the installed one.
1710
+ * @param {unknown} target
1711
+ * @param {unknown} current
1712
+ * @returns {boolean}
1713
+ */
1714
+ function isUpdateAvailable(target, current) {
1715
+ const version = normalizeVersionInput(target);
1716
+ if (version === '') return false;
1717
+ const installed = normalizeVersionInput(current);
1718
+ if (installed === '') return true;
1719
+ return compareVersionsDesc(version, installed) < 0;
1720
+ }
1721
+
1617
1722
  /** A display title for a bundle, following the page's locale fallback. */
1618
1723
  function packageDisplayTitle(pkg) {
1619
1724
  const title = pkg?.meta?.title;
@@ -1661,6 +1766,134 @@
1661
1766
  return `powerup-${Date.now()}-${Math.random().toString(16).slice(2)}`;
1662
1767
  }
1663
1768
 
1769
+ /**
1770
+ * Reinstall the version an update removed. The update removes the old
1771
+ * copy before the new spec is inspected, so a refused inspection or a
1772
+ * failed install leaves the plugin missing; this puts the old version
1773
+ * back with the enabled state it had before the update.
1774
+ * @param {{ installBundle: Function }} manager
1775
+ * @param {{ name: string, version: string | null | undefined, enabled?: boolean, registry?: string | null }} target
1776
+ * @param {(key: string, params?: object) => string} t
1777
+ * @returns {Promise<{ version: string }>}
1778
+ */
1779
+ async function restorePreviousBundle(manager, target, t) {
1780
+ const version = typeof target.version === 'string' ? target.version.trim() : '';
1781
+ if (version === '') throw new Error(t('update.rollbackUnavailable'));
1782
+ const installed = await manager.installBundle(`${target.name}@${version}`, {
1783
+ enabled: target.enabled !== false,
1784
+ requestId: newRequestId(),
1785
+ registry: target.registry ?? null,
1786
+ });
1787
+ if (!installed.ok) throw new Error(installed.error?.message ?? t('update.unknown'));
1788
+ const value = installed.value ?? {};
1789
+ if (value.error !== undefined || value.application === 'failed') throw new Error(operationReason(value, t));
1790
+ if (value.application === 'cancelled') throw new Error(t('update.cancelled'));
1791
+ return {
1792
+ version: typeof value.version === 'string' && value.version !== '' ? value.version : version,
1793
+ restartRequired: value.application === 'restart-required',
1794
+ restartReason: typeof value.restartReason === 'string' ? value.restartReason : '',
1795
+ };
1796
+ }
1797
+
1798
+ /**
1799
+ * Apply a one-click update's post-install defaults: enable the new copy,
1800
+ * then restart, without asking. A skipped restart (setting off or an
1801
+ * unsupported runtime) ends in `done` with `autoClose`, so the dialog can
1802
+ * dismiss itself; enable/restart failures end in `done` without
1803
+ * `autoClose` and carry their reason.
1804
+ * @param {{
1805
+ * manager: { setBundleEnabled: Function },
1806
+ * name: string,
1807
+ * installedVersion: string,
1808
+ * restartRequired: boolean,
1809
+ * settings: { oneClickEnable?: boolean, oneClickRestart?: boolean },
1810
+ * apply: (patch: object) => void,
1811
+ * isCurrent: () => boolean,
1812
+ * recordPending: (entry: { name: string, version: string, reason: string }) => void,
1813
+ * readRestartCapability: () => Promise<{ supported: boolean, reason: string }>,
1814
+ * requestRestart: () => Promise<void>,
1815
+ * t: (key: string, params?: object) => string,
1816
+ * }} input
1817
+ * @returns {Promise<void>}
1818
+ */
1819
+ async function runOneClickUpdate(input) {
1820
+ const {
1821
+ manager, name, installedVersion, restartRequired, settings,
1822
+ apply, isCurrent, recordPending, readRestartCapability, requestRestart, t,
1823
+ } = input;
1824
+ if (settings.oneClickEnable === false) {
1825
+ apply({
1826
+ phase: 'done',
1827
+ step: null,
1828
+ installedVersion,
1829
+ enabled: false,
1830
+ restartRequired,
1831
+ restartSkipped: true,
1832
+ skippedEnable: true,
1833
+ autoClose: true,
1834
+ });
1835
+ return;
1836
+ }
1837
+ apply({ phase: 'working', step: 'enabling', installedVersion, restartRequired });
1838
+ let enabledValue;
1839
+ try {
1840
+ const enabled = await manager.setBundleEnabled(name, true);
1841
+ if (!isCurrent()) return;
1842
+ if (!enabled.ok) throw new Error(enabled.error?.message ?? t('update.unknown'));
1843
+ enabledValue = enabled.value ?? {};
1844
+ if (enabledValue.error !== undefined || enabledValue.application === 'failed') throw new Error(operationReason(enabledValue, t));
1845
+ if (enabledValue.application === 'cancelled') throw new Error(t('update.cancelled'));
1846
+ } catch (error) {
1847
+ apply({
1848
+ phase: 'done',
1849
+ step: null,
1850
+ installedVersion,
1851
+ enabled: false,
1852
+ enableError: errorText(error) || t('update.unknown'),
1853
+ autoClose: false,
1854
+ });
1855
+ return;
1856
+ }
1857
+ if (restartRequired || enabledValue.application === 'restart-required') {
1858
+ recordPending({
1859
+ name,
1860
+ version: installedVersion,
1861
+ reason: enabledValue.restartReason ?? '',
1862
+ });
1863
+ }
1864
+ if (settings.oneClickRestart === false) {
1865
+ apply({ phase: 'done', step: null, installedVersion, enabled: true, restartSkipped: true, autoClose: true });
1866
+ return;
1867
+ }
1868
+ const restart = await readRestartCapability();
1869
+ if (!isCurrent()) return;
1870
+ if (restart.supported !== true) {
1871
+ apply({
1872
+ phase: 'done',
1873
+ step: null,
1874
+ installedVersion,
1875
+ enabled: true,
1876
+ restartSkipped: true,
1877
+ restartUnsupported: restart.reason,
1878
+ autoClose: true,
1879
+ });
1880
+ return;
1881
+ }
1882
+ apply({ phase: 'restarting', step: null, installedVersion, enabled: true, restarting: true });
1883
+ try {
1884
+ await requestRestart();
1885
+ } catch (error) {
1886
+ apply({
1887
+ phase: 'done',
1888
+ step: null,
1889
+ installedVersion,
1890
+ enabled: true,
1891
+ restartError: errorText(error) || t('update.unknown'),
1892
+ autoClose: false,
1893
+ });
1894
+ }
1895
+ }
1896
+
1664
1897
  /**
1665
1898
  * The package name of a registry install spec. Git, tarball, and local
1666
1899
  * paths return null; their installed name comes from the Host result.
@@ -2290,7 +2523,7 @@
2290
2523
  const seq = versionSeq.current + 1;
2291
2524
  versionSeq.current = seq;
2292
2525
  const current = () => versionSeq.current === seq && tokenRef.current === token;
2293
- patch(token, { versionsState: 'loading', versionsError: null, versionsRegistry: null, ...(resetVersion === true ? { versions: [], version: '' } : {}) });
2526
+ patch(token, { versionsState: 'loading', versionsError: null, versionsRegistry: null, ...(resetVersion === true ? { versions: [], version: '', latest: null } : {}) });
2294
2527
  let lastError = null;
2295
2528
  for (const candidate of lookupRegistries(choices, choice)) {
2296
2529
  if (!current()) return;
@@ -2379,6 +2612,7 @@
2379
2612
  title: packageDisplayTitle(pkg),
2380
2613
  currentVersion: pkg.version ?? null,
2381
2614
  installed: pkg.installed === true,
2615
+ enabled: pkg.enabled !== false,
2382
2616
  phase: 'choose',
2383
2617
  choices,
2384
2618
  registryKey: choice.key,
@@ -2533,6 +2767,26 @@
2533
2767
  return () => document.removeEventListener('keydown', onKeyDown, true);
2534
2768
  }, [restartAsk, restartBusy]);
2535
2769
 
2770
+ // A one-click update that does not restart leaves a completion panel;
2771
+ // close it on its own so it never lingers over the Plugins page.
2772
+ useEffect(() => {
2773
+ if (view === null || view.phase !== 'done' || view.autoClose !== true) return undefined;
2774
+ const timer = window.setTimeout(() => {
2775
+ setView((current) => {
2776
+ if (current === null || current.phase !== 'done' || current.autoClose !== true) return current;
2777
+ tokenRef.current = null;
2778
+ try {
2779
+ abortRef.current?.abort?.();
2780
+ } catch {
2781
+ /* ignore */
2782
+ }
2783
+ abortRef.current = null;
2784
+ return null;
2785
+ });
2786
+ }, ONE_CLICK_AUTO_CLOSE_MS);
2787
+ return () => window.clearTimeout(timer);
2788
+ }, [view === null ? null : view.phase, view === null ? null : view.autoClose]);
2789
+
2536
2790
  const chooseVersion = (version) => {
2537
2791
  if (tokenRef.current === null) return;
2538
2792
  setView((current) => current === null ? current : { ...current, version, listOpen: false, listPopover: null, formError: null });
@@ -2600,21 +2854,46 @@
2600
2854
  });
2601
2855
  };
2602
2856
 
2603
- const startUpdate = async () => {
2857
+ const startUpdate = async (options = {}) => {
2604
2858
  const token = tokenRef.current;
2605
2859
  const current = view;
2606
2860
  if (token === null || current === null || current.phase !== 'choose') return;
2607
2861
  const t = tRef.current;
2608
- const version = normalizeVersionInput(current.version);
2862
+ const oneClick = options?.oneClick === true;
2863
+ // One-click installs the registry's newest version; the manual path
2864
+ // uses what the user typed or picked.
2865
+ const version = oneClick ? oneClickVersion(current) : normalizeVersionInput(current.version);
2609
2866
  if (version === '') {
2610
- setView((state) => state === null ? state : { ...state, formError: t('update.invalidVersion') });
2867
+ setView((state) => state === null ? state : {
2868
+ ...state,
2869
+ formError: t(oneClick ? 'update.oneClickNoLatest' : 'update.invalidVersion'),
2870
+ });
2871
+ return;
2872
+ }
2873
+ if (oneClick && isUpdateAvailable(version, current.currentVersion) !== true) {
2874
+ setView((state) => state === null ? state : { ...state, formError: t('update.oneClickUpToDate') });
2611
2875
  return;
2612
2876
  }
2613
2877
  const choice = current.choices.find((item) => item.key === current.registryKey) ?? current.choices[0];
2614
2878
  const registry = registryValue(choice);
2615
2879
  const spec = `${current.name}@${version}`;
2616
2880
  const requestId = newRequestId();
2617
- patch(token, { phase: 'working', step: current.self === true ? 'installing' : 'removing', error: null, formError: null, log: '', logLabel: spec });
2881
+ const previousVersion = typeof current.currentVersion === 'string' && current.currentVersion !== '' ? current.currentVersion : null;
2882
+ const previousEnabled = current.enabled !== false;
2883
+ let removedOld = false;
2884
+ patch(token, {
2885
+ phase: 'working',
2886
+ step: current.self === true ? 'installing' : 'removing',
2887
+ error: null,
2888
+ formError: null,
2889
+ log: '',
2890
+ logLabel: spec,
2891
+ oneClick,
2892
+ listOpen: false,
2893
+ listPopover: null,
2894
+ registryOpen: false,
2895
+ registryPopover: null,
2896
+ });
2618
2897
  if (current.self === true) {
2619
2898
  // Power-Up cannot reinstall itself from its own client: removing
2620
2899
  // the bundle unloads this dialog. The Host route receives the
@@ -2645,7 +2924,9 @@
2645
2924
  const removed = await manager.removeBundle(current.name);
2646
2925
  if (tokenRef.current !== token) return;
2647
2926
  if (!removed.ok) throw new Error(removed.error?.message ?? t('update.unknown'));
2648
- if (removed.value.error !== undefined) throw new Error(operationReason(removed.value, t));
2927
+ if (removed.value.error !== undefined || removed.value.application === 'failed') throw new Error(operationReason(removed.value, t));
2928
+ if (removed.value.application === 'cancelled') throw new Error(t('update.cancelled'));
2929
+ removedOld = true;
2649
2930
  patch(token, { step: 'checking' });
2650
2931
  const checked = await manager.inspect(spec, { registry });
2651
2932
  if (tokenRef.current !== token) return;
@@ -2667,6 +2948,23 @@
2667
2948
  reason: value.restartReason ?? '',
2668
2949
  });
2669
2950
  }
2951
+ if (oneClick) {
2952
+ // No enable/restart questions: apply the stored defaults.
2953
+ await runOneClickUpdate({
2954
+ manager,
2955
+ name: current.name,
2956
+ installedVersion: value.version ?? version,
2957
+ restartRequired,
2958
+ settings: getSettings(),
2959
+ apply: (delta) => patch(token, delta),
2960
+ isCurrent: () => tokenRef.current === token,
2961
+ recordPending,
2962
+ readRestartCapability,
2963
+ requestRestart: requestAppRestart,
2964
+ t,
2965
+ });
2966
+ return;
2967
+ }
2670
2968
  patch(token, {
2671
2969
  phase: 'enable',
2672
2970
  step: null,
@@ -2675,7 +2973,40 @@
2675
2973
  enabling: false,
2676
2974
  });
2677
2975
  } catch (error) {
2678
- patch(token, { phase: 'error', step: null, error: errorText(error) || t('update.unknown') });
2976
+ const original = errorText(error) || t('update.unknown');
2977
+ // Before the first successful step the old copy is still installed;
2978
+ // after it, a failed inspect/install must put the old version back.
2979
+ if (!removedOld) {
2980
+ patch(token, { phase: 'error', step: null, error: original });
2981
+ return;
2982
+ }
2983
+ if (previousVersion === null) {
2984
+ patch(token, { phase: 'error', step: null, error: original, rollbackUnavailable: true });
2985
+ return;
2986
+ }
2987
+ patch(token, { phase: 'working', step: 'rollback', rollbackVersion: previousVersion, error: null, formError: null });
2988
+ try {
2989
+ const restored = await restorePreviousBundle(manager, {
2990
+ name: current.name,
2991
+ version: previousVersion,
2992
+ enabled: previousEnabled,
2993
+ registry,
2994
+ }, t);
2995
+ if (tokenRef.current !== token) return;
2996
+ if (restored.restartRequired === true) {
2997
+ recordPending({ name: current.name, version: restored.version, reason: restored.restartReason });
2998
+ }
2999
+ patch(token, { phase: 'error', step: null, error: original, rolledBack: true, rollbackVersion: restored.version });
3000
+ } catch (rollbackFailure) {
3001
+ if (tokenRef.current !== token) return;
3002
+ patch(token, {
3003
+ phase: 'error',
3004
+ step: null,
3005
+ error: original,
3006
+ rollbackVersion: previousVersion,
3007
+ rollbackError: errorText(rollbackFailure) || t('update.unknown'),
3008
+ });
3009
+ }
2679
3010
  }
2680
3011
  };
2681
3012
 
@@ -2693,6 +3024,17 @@
2693
3024
  }
2694
3025
  };
2695
3026
 
3027
+ /** POST the restart command; throws when the Host refuses. */
3028
+ const requestAppRestart = async () => {
3029
+ const response = await fetch(UPDATE_API, {
3030
+ method: 'POST',
3031
+ headers: { 'content-type': 'application/json' },
3032
+ body: JSON.stringify({ action: 'restart' }),
3033
+ });
3034
+ const data = await response.json().catch(() => null);
3035
+ if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? `HTTP ${response.status}`);
3036
+ };
3037
+
2696
3038
  /** Open the list-header restart confirmation and read the capability. */
2697
3039
  const openRestart = () => {
2698
3040
  setRestartAsk(true);
@@ -2709,13 +3051,7 @@
2709
3051
  setRestartBusy(true);
2710
3052
  setRestartError(null);
2711
3053
  try {
2712
- const response = await fetch(UPDATE_API, {
2713
- method: 'POST',
2714
- headers: { 'content-type': 'application/json' },
2715
- body: JSON.stringify({ action: 'restart' }),
2716
- });
2717
- const data = await response.json().catch(() => null);
2718
- if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? `HTTP ${response.status}`);
3054
+ await requestAppRestart();
2719
3055
  } catch (error) {
2720
3056
  setRestartBusy(false);
2721
3057
  setRestartError(errorText(error) || tRef.current('update.unknown'));
@@ -2765,13 +3101,7 @@
2765
3101
  const t = tRef.current;
2766
3102
  patch(token, { restarting: true, restartError: null });
2767
3103
  try {
2768
- const response = await fetch(UPDATE_API, {
2769
- method: 'POST',
2770
- headers: { 'content-type': 'application/json' },
2771
- body: JSON.stringify({ action: 'restart' }),
2772
- });
2773
- const data = await response.json().catch(() => null);
2774
- if (!response.ok || data?.ok !== true) throw new Error(data?.error ?? `HTTP ${response.status}`);
3104
+ await requestAppRestart();
2775
3105
  patch(token, { phase: 'restarting', restarting: true });
2776
3106
  } catch (error) {
2777
3107
  patch(token, { restarting: false, restartError: errorText(error) || t('update.unknown') });
@@ -2839,19 +3169,39 @@
2839
3169
  const canClose = !busy;
2840
3170
  const title = view.title === undefined || view.title === '' ? view.name : view.title;
2841
3171
  const showVersions = view.phase === 'choose' && view.listOpen === true;
3172
+ // The newest version a one-click update would install right now.
3173
+ const quickVersion = oneClickVersion(view);
3174
+ const quickAvailable = view.self !== true
3175
+ && view.versionsState === 'ready'
3176
+ && quickVersion !== ''
3177
+ && isUpdateAvailable(quickVersion, view.currentVersion);
2842
3178
 
2843
3179
  const footer = (() => {
2844
3180
  if (view.phase === 'choose') {
2845
3181
  return [
2846
3182
  h('button', { key: 'cancel', type: 'button', className: 'dsh-powerup-update-ghost', onClick: close }, t('update.cancel')),
3183
+ view.self === true
3184
+ ? null
3185
+ : h('button', {
3186
+ key: 'quick',
3187
+ type: 'button',
3188
+ className: 'dsh-powerup-update-quick',
3189
+ disabled: !quickAvailable,
3190
+ title: quickAvailable
3191
+ ? t('update.oneClickHint', { version: quickVersion })
3192
+ : quickVersion === ''
3193
+ ? t('update.oneClickNoLatest')
3194
+ : t('update.oneClickUpToDate'),
3195
+ onClick: () => startUpdate({ oneClick: true }),
3196
+ }, h(QuickIcon, { size: 13 }), t('update.oneClick')),
2847
3197
  h('button', {
2848
3198
  key: 'start',
2849
3199
  type: 'button',
2850
3200
  className: 'dsh-powerup-update-primary',
2851
3201
  disabled: view.versionsState === 'loading' || String(view.version ?? '').trim() === '',
2852
- onClick: startUpdate,
3202
+ onClick: () => startUpdate(),
2853
3203
  }, t('update.start')),
2854
- ];
3204
+ ].filter(Boolean);
2855
3205
  }
2856
3206
  if (view.phase === 'enable') {
2857
3207
  return [
@@ -3013,6 +3363,25 @@
3013
3363
  ? null
3014
3364
  : h('span', { className: 'dsh-powerup-update-note' }, t('update.registryFrom', { registry: view.versionsRegistry.hint })),
3015
3365
  ),
3366
+ view.self === true
3367
+ ? null
3368
+ : h('div', { key: 'quick', className: 'dsh-powerup-update-quick-note' },
3369
+ h('div', { className: 'dsh-powerup-update-quick-note-title' },
3370
+ h(QuickIcon, { size: 13 }),
3371
+ t('update.oneClickTitle'),
3372
+ ),
3373
+ h('p', { className: 'dsh-powerup-update-note' }, quickAvailable
3374
+ ? t('update.oneClickHint', { version: quickVersion })
3375
+ : quickVersion === ''
3376
+ ? t('update.oneClickNoLatest')
3377
+ : t('update.oneClickUpToDate')),
3378
+ quickAvailable
3379
+ ? h('p', { className: 'dsh-powerup-update-note' }, t('update.oneClickDefaults', {
3380
+ enable: getSettings().oneClickEnable === false ? t('update.off') : t('update.on'),
3381
+ restart: getSettings().oneClickRestart === false ? t('update.off') : t('update.on'),
3382
+ }))
3383
+ : null,
3384
+ ),
3016
3385
  ];
3017
3386
  }
3018
3387
  if (view.phase === 'working') {
@@ -3020,7 +3389,11 @@
3020
3389
  ? t('update.step.removing')
3021
3390
  : view.step === 'installing'
3022
3391
  ? t('update.step.installing', { version: view.logLabel ?? '' })
3023
- : t('update.step.checking');
3392
+ : view.step === 'rollback'
3393
+ ? t('update.step.rollback', { version: view.rollbackVersion ?? view.currentVersion ?? '' })
3394
+ : view.step === 'enabling'
3395
+ ? t('update.step.enabling')
3396
+ : t('update.step.checking');
3024
3397
  return [
3025
3398
  h('div', { key: 'status', className: 'dsh-powerup-update-status' },
3026
3399
  h('span', { className: 'dsh-powerup-update-spinner', 'aria-hidden': 'true' }),
@@ -3079,11 +3452,39 @@
3079
3452
  ? t('update.doneDisabled', { name: view.name, version: view.installedVersion ?? '' })
3080
3453
  : t('update.doneInstalled', { name: view.name, version: view.installedVersion ?? '' })),
3081
3454
  view.restartSkipped === true ? h('p', { key: 'restart', className: 'dsh-powerup-update-note' }, t('update.doneRestart')) : null,
3455
+ view.skippedEnable === true ? h('p', { key: 'skipped-enable', className: 'dsh-powerup-update-note' }, t('update.oneClickSkippedEnable')) : null,
3456
+ view.enableError === null || view.enableError === undefined
3457
+ ? null
3458
+ : notice('error', h(WarnIcon, { size: 14 }), t('update.errorTitle'), t('update.enableFailed', { message: view.enableError })),
3459
+ view.enableError === null || view.enableError === undefined
3460
+ ? null
3461
+ : h('p', { key: 'enable-failed', className: 'dsh-powerup-update-note' }, t('update.oneClickEnableFailed')),
3462
+ view.restartUnsupported === null || view.restartUnsupported === undefined
3463
+ ? null
3464
+ : notice('warn', h(WarnIcon, { size: 14 }), null, t('update.restartUnsupported', { reason: view.restartUnsupported })),
3465
+ view.restartError === null || view.restartError === undefined
3466
+ ? null
3467
+ : notice('error', h(WarnIcon, { size: 14 }), t('update.errorTitle'), t('update.restartFailed', { message: view.restartError })),
3468
+ view.autoClose === true
3469
+ ? h('p', { key: 'auto-close', className: 'dsh-powerup-update-note' }, t('update.doneAutoClose', { seconds: Math.round(ONE_CLICK_AUTO_CLOSE_MS / 1000) }))
3470
+ : null,
3082
3471
  ];
3083
3472
  }
3084
3473
  if (view.phase === 'error') {
3085
3474
  return [
3086
3475
  notice('error', h(WarnIcon, { size: 15 }), t('update.errorTitle'), view.error ?? t('update.unknown')),
3476
+ view.rolledBack === true
3477
+ ? notice('success', h(CheckIcon, { size: 15 }), t('update.rollbackOkTitle'), t('update.rollbackOkDesc', {
3478
+ name: view.name,
3479
+ version: view.rollbackVersion ?? view.currentVersion ?? '',
3480
+ }))
3481
+ : null,
3482
+ view.rollbackError !== undefined && view.rollbackError !== null
3483
+ ? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackFailedDesc', { message: view.rollbackError }))
3484
+ : null,
3485
+ view.rollbackUnavailable === true
3486
+ ? notice('warn', h(WarnIcon, { size: 15 }), t('update.rollbackFailedTitle'), t('update.rollbackUnavailable'))
3487
+ : null,
3087
3488
  h('span', { key: 'name', className: 'dsh-powerup-update-name' }, view.name),
3088
3489
  ];
3089
3490
  }
@@ -3359,6 +3760,26 @@
3359
3760
  { id: 'fork', icon: ForkIcon, name: t('action.fork'), hint: t('action.forkHint') },
3360
3761
  { id: 'export', icon: ExportIcon, name: t('action.export'), hint: t('action.exportHint') },
3361
3762
  ];
3763
+ /** One label/description row with a host-styled switch. */
3764
+ const settingRow = (key, checked, label, hint) => h('div', { key, className: 'dsh-powerup-setting' },
3765
+ h('div', { className: 'dsh-powerup-setting-copy' },
3766
+ h('span', { className: 'dsh-powerup-setting-label' }, label),
3767
+ h('span', { className: 'dsh-powerup-setting-hint' }, hint),
3768
+ ),
3769
+ h('button', {
3770
+ type: 'button',
3771
+ role: 'switch',
3772
+ 'aria-checked': checked ? 'true' : 'false',
3773
+ 'aria-label': label,
3774
+ className: 'dsh-powerup-switch',
3775
+ onClick: () => setSettings({ [key]: !checked }),
3776
+ },
3777
+ h('span', { className: 'dsh-powerup-switch-track' },
3778
+ h('span', { className: 'dsh-powerup-switch-thumb' }),
3779
+ ),
3780
+ h('span', null, checked ? t('page.enabled') : t('page.disabled')),
3781
+ ),
3782
+ );
3362
3783
  return h('div', { className: 'dsh-powerup-page' },
3363
3784
  h('div', { className: 'dsh-powerup-shell' },
3364
3785
  h('header', { className: 'dsh-powerup-hero' },
@@ -3402,6 +3823,19 @@
3402
3823
  ),
3403
3824
  ),
3404
3825
  ),
3826
+ h('section', { className: 'dsh-powerup-card' },
3827
+ h('div', { className: 'dsh-powerup-card-head' },
3828
+ h('div', { className: 'dsh-powerup-card-icon' }, h(QuickIcon, { size: 18 })),
3829
+ h('div', { className: 'dsh-powerup-card-copy' },
3830
+ h('h2', null, t('page.oneClickTitle')),
3831
+ h('p', null, t('page.oneClickDesc')),
3832
+ ),
3833
+ ),
3834
+ h('div', { className: 'dsh-powerup-settings' },
3835
+ settingRow('oneClickEnable', settings.oneClickEnable !== false, t('page.oneClickEnable'), t('page.oneClickEnableHint')),
3836
+ settingRow('oneClickRestart', settings.oneClickRestart !== false, t('page.oneClickRestart'), t('page.oneClickRestartHint')),
3837
+ ),
3838
+ ),
3405
3839
  h('section', { className: 'dsh-powerup-card' },
3406
3840
  h('div', { className: 'dsh-powerup-card-head' },
3407
3841
  h('div', { className: 'dsh-powerup-card-icon' }, h(UpdateIcon, { size: 18 })),
@@ -3571,6 +4005,7 @@
3571
4005
  CSS,
3572
4006
  PowerUpLineIcon,
3573
4007
  UpdateIcon,
4008
+ QuickIcon,
3574
4009
  PowerUpBridge,
3575
4010
  PowerUpPage,
3576
4011
  PowerUpOverlay,
@@ -3604,8 +4039,15 @@
3604
4039
  readRememberedRegistry,
3605
4040
  packageDisplayTitle,
3606
4041
  normalizeVersionInput,
4042
+ oneClickVersion,
4043
+ isUpdateAvailable,
4044
+ readSettings,
4045
+ getSettings,
4046
+ setSettings,
3607
4047
  inspectReason,
3608
4048
  operationReason,
4049
+ restorePreviousBundle,
4050
+ runOneClickUpdate,
3609
4051
  },
3610
4052
  };
3611
4053
  },
package/index.js CHANGED
@@ -9,7 +9,9 @@
9
9
  * GET /dsh-powerup/api/audit → profile bundles newer than this Host
10
10
  * POST /dsh-powerup/api/self-update → removes and reinstalls this plugin
11
11
  * in the background, surviving the
12
- * plugin's own unload
12
+ * plugin's own unload; a failed step
13
+ * reinstalls the version that was
14
+ * removed
13
15
  * POST /dsh-powerup/api/job-kill → stops one background job with an
14
16
  * optional human reason
15
17
  *
@@ -21,7 +23,7 @@
21
23
  */
22
24
 
23
25
  import { randomUUID } from 'node:crypto';
24
- import { appendFileSync, mkdirSync, statSync } from 'node:fs';
26
+ import { appendFileSync, mkdirSync, readFileSync, statSync } from 'node:fs';
25
27
  import { dirname, join } from 'node:path';
26
28
  import { homedir } from 'node:os';
27
29
  import { describeRestart, requestRestart } from './lib/restart.js';
@@ -41,6 +43,24 @@ const BODY_LIMIT = 16 * 1024;
41
43
  /** The moment this Host process started; a profile file newer than it may await a restart. */
42
44
  const HOST_STARTED_AT = Date.now() - process.uptime() * 1000;
43
45
 
46
+ /**
47
+ * The version this Host module was loaded from. A self-update removes the only
48
+ * installed copy before inspecting the target, so a failure must reinstall this
49
+ * exact version instead of leaving Power-Up missing.
50
+ * @returns {string}
51
+ */
52
+ function selfVersion() {
53
+ try {
54
+ const manifest = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
55
+ return typeof manifest?.version === 'string' ? manifest.version : '';
56
+ } catch {
57
+ return '';
58
+ }
59
+ }
60
+
61
+ /** Captured at load time, before self-update touches the package directory. */
62
+ const SELF_VERSION = selfVersion();
63
+
44
64
  /**
45
65
  * The desktop profile directory, resolved without depending on the shell tool.
46
66
  * @returns {string}
@@ -225,12 +245,13 @@ function normalizeVersion(value) {
225
245
  * @param {import('@deepseek-ai/cordis').Context} ctx
226
246
  * @param {string} version
227
247
  * @param {string | null} registry
228
- * @param {{ manager?: unknown, log?: (line: string) => void }} [options]
229
- * @returns {Promise<{ ok: boolean, stage?: string, error?: string }>}
248
+ * @param {{ manager?: unknown, log?: (line: string) => void, previousVersion?: string }} [options]
249
+ * @returns {Promise<{ ok: boolean, stage?: string, error?: string, rolledBack?: boolean, rollbackError?: string }>}
230
250
  */
231
251
  export async function performSelfUpdate(ctx, version, registry, options = {}) {
232
252
  const log = options.log ?? appendSelfUpdateLog;
233
253
  const manager = options.manager ?? ctx?.get?.('pluginManager');
254
+ const previousVersion = typeof options.previousVersion === 'string' ? options.previousVersion : SELF_VERSION;
234
255
  if (manager === undefined || typeof manager.installBundle !== 'function') {
235
256
  log('self-update: pluginManager service is unavailable');
236
257
  return { ok: false, stage: 'manager', error: 'pluginManager service is unavailable' };
@@ -238,11 +259,16 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
238
259
  const spec = `${MODULE_ID}@${version}`;
239
260
  log(`self-update: start ${spec} registry=${String(registry)}`);
240
261
  let stage = 'remove';
262
+ let removedOld = false;
241
263
  try {
242
264
  const removed = await manager.removeBundle(MODULE_ID);
243
265
  if (removed?.error !== undefined) {
244
266
  throw new Error(`remove failed: ${removed.error.code ?? 'error'} ${removed.error.diagnostic ?? ''}`.trim());
245
267
  }
268
+ if (removed?.application === 'cancelled' || removed?.application === 'failed') {
269
+ throw new Error(`remove ${removed.application}`);
270
+ }
271
+ removedOld = true;
246
272
  log(`self-update: removed (application=${removed?.application ?? 'unknown'})`);
247
273
  stage = 'inspect';
248
274
  const checked = await manager.inspect(spec, { registry });
@@ -256,15 +282,54 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
256
282
  registry,
257
283
  requestId: randomUUID(),
258
284
  });
259
- if (installed?.error !== undefined) {
260
- throw new Error(`install failed: ${installed.error.code ?? 'error'} ${installed.error.diagnostic ?? ''}`.trim());
285
+ if (installed?.error !== undefined || installed?.application === 'failed') {
286
+ const detail = installed?.error === undefined
287
+ ? ''
288
+ : `${installed.error.code ?? 'error'} ${installed.error.diagnostic ?? ''}`.trim();
289
+ throw new Error(`install failed${detail === '' ? '' : `: ${detail}`}`);
261
290
  }
262
291
  log(`self-update: installed (application=${installed?.application ?? 'unknown'}, version=${installed?.version ?? 'unknown'})`);
263
292
  return { ok: true, stage: 'install' };
264
293
  } catch (error) {
265
294
  const message = String(error?.message ?? error);
266
295
  log(`self-update: failed at ${stage}: ${message}${error?.stack === undefined ? '' : `\n${error.stack}`}`);
267
- return { ok: false, stage, error: message };
296
+ // Removing the old copy is the first step, so any later failure leaves
297
+ // Power-Up uninstalled. Put the running version back instead.
298
+ let rolledBack = false;
299
+ let rollbackError;
300
+ if (removedOld) {
301
+ if (previousVersion === '') {
302
+ rollbackError = 'the previous version is unknown';
303
+ log('self-update: cannot roll back: previous version unknown');
304
+ } else {
305
+ log(`self-update: rolling back to ${MODULE_ID}@${previousVersion}`);
306
+ try {
307
+ const restored = await manager.installBundle(`${MODULE_ID}@${previousVersion}`, {
308
+ enabled: true,
309
+ registry,
310
+ requestId: randomUUID(),
311
+ });
312
+ if (restored?.error !== undefined || restored?.application === 'failed') {
313
+ const detail = restored?.error === undefined
314
+ ? ''
315
+ : `${restored.error.code ?? 'error'} ${restored.error.diagnostic ?? ''}`.trim();
316
+ throw new Error(`rollback install failed${detail === '' ? '' : `: ${detail}`}`);
317
+ }
318
+ rolledBack = true;
319
+ log(`self-update: rolled back to ${previousVersion} (application=${restored?.application ?? 'unknown'})`);
320
+ } catch (rollbackFailure) {
321
+ rollbackError = String(rollbackFailure?.message ?? rollbackFailure);
322
+ log(`self-update: rollback failed: ${rollbackError}`);
323
+ }
324
+ }
325
+ }
326
+ return {
327
+ ok: false,
328
+ stage,
329
+ error: message,
330
+ rolledBack,
331
+ ...(rollbackError === undefined ? {} : { rollbackError }),
332
+ };
268
333
  }
269
334
  }
270
335
 
@@ -414,9 +479,11 @@ export const __test = {
414
479
  normalizeVersion,
415
480
  normalizeStopReason,
416
481
  killReasonFor,
482
+ selfVersion,
417
483
  auditProfileBundles,
418
484
  profileDirectory,
419
485
  HOST_STARTED_AT,
486
+ SELF_VERSION,
420
487
  ROUTE,
421
488
  MODULE_ID,
422
489
  };
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Power-Up",
4
- "description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, export the trajectory snapshot, and copy the session ID. The session header's background jobs panel gains an optional stop reason when a job is stopped by hand; the reason is appended to the completion notice injected into the session. The Plugins page gains an update control on every third-party installed plugin: choose a version from the registry, uninstall the old copy, reinstall through the Add plugin path, then enable and optionally restart DSH."
4
+ "description": "Adds a right-click action menu to the Trajectory ledger: copy a record, copy a Markdown quote, quote it into the composer, open the record inspector, fork the session at that record, export the trajectory snapshot, and copy the session ID. The session header's background jobs panel gains an optional stop reason when a job is stopped by hand; the reason is appended to the completion notice injected into the session. The Plugins page gains an update control on every third-party installed plugin: choose a version from the registry, uninstall the old copy, reinstall through the Add plugin path, then enable and optionally restart DSH. The update panel also offers a one-click update that installs the newest version without the enable and restart questions, enabling and restarting automatically by default; both defaults are configurable on the Power-Up page."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Power-Up",
4
- "description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加更新按钮:从安装源选择版本,先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。"
4
+ "description": "在轨迹页面为记录增加右键操作菜单:复制内容、复制 Markdown 引用、引用到输入框、查看记录详情、从该记录 Fork 会话、导出轨迹快照、复制会话 ID。在会话顶部的后台任务面板手动停止任务时可以填写停止原因,原因会附加在任务结束后注入会话的提示里。插件页为每个第三方已安装插件增加更新按钮:从安装源选择版本,先卸载旧版再按「添加插件」流程安装,完成后可立即启用并选择是否重启 DSH。插件更新面板还提供「一键更新」:安装最新版本并跳过启用与重启的询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.4.0",
4
- "description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an update control for third-party plugins installed from the Plugins page, with version lookup from the configured registries, a starred default source, uninstall-and-reinstall through the Add plugin path, restart-needed markers, a background self-update, and an optional DSH restart. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为已安装插件提供带版本查询的更新按钮,安装源可设默认,沿用「添加插件」的安装流程,支持待重启标记、后台自更新与一键重启。",
3
+ "version": "0.5.0",
4
+ "description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an update control for third-party plugins installed from the Plugins page, with version lookup from the configured registries, a starred default source, uninstall-and-reinstall through the Add plugin path, restart-needed markers, a background self-update, and an optional DSH restart, plus a one-click update that installs the newest version and can enable and restart automatically. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为已安装插件提供带版本查询的更新按钮,安装源可设默认,沿用「添加插件」的安装流程,支持待重启标记、后台自更新与一键重启;插件更新面板提供「一键更新」,默认安装最新版后自动启用并重启,可在 Power-Up 页面调整默认行为。",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",
7
7
  "main": "index.js",