@maplewf/dsh-web-update 0.0.0-stage → 0.1.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.en.md +65 -0
- package/README.md +64 -2
- package/client.js +779 -0
- package/cordis.patch.yml +27 -0
- package/icon.svg +15 -0
- package/index.js +766 -0
- package/lib/core.js +259 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +53 -4
package/client.js
ADDED
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-web-update",
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const h = React.createElement;
|
|
6
|
+
|
|
7
|
+
/** Text namespace owned by this plugin. */
|
|
8
|
+
const NS = "dsh-web-update";
|
|
9
|
+
/** Same-origin Host route; the browser cookie authenticates the owner peer. */
|
|
10
|
+
const ROUTE = "api/dsh-version-update";
|
|
11
|
+
/** Settings navigation entry rendered between the plugin pages. */
|
|
12
|
+
const SECTION_ID = "version-update";
|
|
13
|
+
const SECTION_ORDER = 30;
|
|
14
|
+
|
|
15
|
+
/** Status poll cadence while an install or restart is in flight. */
|
|
16
|
+
const POLL_INTERVAL_MS = 1000;
|
|
17
|
+
/** Give up polling when the server never comes back. */
|
|
18
|
+
const POLL_TIMEOUT_MS = 240000;
|
|
19
|
+
|
|
20
|
+
const dictionaries = {
|
|
21
|
+
zh: {
|
|
22
|
+
"nav.label": "版本更新",
|
|
23
|
+
"page.title": "版本更新",
|
|
24
|
+
"page.description": "检查并更新本机 dsh web 主体({package})。服务每次启动会检查一次,有新版本时右侧导航会显示红点。",
|
|
25
|
+
"field.current": "当前版本",
|
|
26
|
+
"field.latest": "最新版本",
|
|
27
|
+
"field.channel": "检查通道",
|
|
28
|
+
"field.checked": "最近检查",
|
|
29
|
+
"field.source": "检查方式",
|
|
30
|
+
"field.restartCommand": "重启命令",
|
|
31
|
+
"field.restartCommandPlaceholder": "留空 = 内置 systemctl --user restart {unit}",
|
|
32
|
+
"field.restartCommandHint": "留空使用内置命令;填入自定义命令则在安装完成后执行(经 /bin/sh -c),{unit} 会替换为服务名。保存后立即生效。",
|
|
33
|
+
"field.save": "保存",
|
|
34
|
+
"field.saved": "已保存",
|
|
35
|
+
"field.saveFailed": "保存失败:{error}",
|
|
36
|
+
"value.unknown": "未知",
|
|
37
|
+
"value.none": "尚未检查",
|
|
38
|
+
"source.npm-view": "npm 命令",
|
|
39
|
+
"source.registry-fetch": "registry 接口",
|
|
40
|
+
"state.checking": "正在检查…",
|
|
41
|
+
"state.upToDate": "已是最新版本",
|
|
42
|
+
"state.updateAvailable": "有新版本可用:{version}",
|
|
43
|
+
"state.ahead": "当前版本高于该通道的最新版本",
|
|
44
|
+
"state.checkFailed": "检查失败:{error}",
|
|
45
|
+
"state.notChecked": "尚未检查更新",
|
|
46
|
+
"action.check": "检查版本",
|
|
47
|
+
"action.update": "更新版本",
|
|
48
|
+
"action.retry": "重试",
|
|
49
|
+
"update.running": "正在安装 {target}…",
|
|
50
|
+
"update.installed": "安装完成,正在重启 Web 服务…",
|
|
51
|
+
"update.restarting": "正在重启 Web 服务,页面会自动重连…",
|
|
52
|
+
"update.done": "已更新到 {version}",
|
|
53
|
+
"update.restartSkipped": "已安装;按配置未自动重启,请手动重启服务生效",
|
|
54
|
+
"update.failed": "更新失败:{error}",
|
|
55
|
+
"update.sudoHint": "更新会写入系统级 npm 目录({root}),将通过 sudo -n 执行;若免密 sudo 不可用,请先在终端授权。",
|
|
56
|
+
"notice.checkStarted": "已向 npm 发起检查",
|
|
57
|
+
"notice.confirmTitle": "确认更新",
|
|
58
|
+
"notice.confirmBody": "将把 {package} 更新到 {version},安装完成后自动重启 Web 服务。页面会短暂断开并自动重连。",
|
|
59
|
+
"notice.confirmOk": "开始更新",
|
|
60
|
+
"notice.confirmCancel": "取消",
|
|
61
|
+
"notice.close": "关闭",
|
|
62
|
+
"log.show": "查看安装输出",
|
|
63
|
+
"log.hide": "收起安装输出",
|
|
64
|
+
},
|
|
65
|
+
en: {
|
|
66
|
+
"nav.label": "Version update",
|
|
67
|
+
"page.title": "Version update",
|
|
68
|
+
"page.description": "Checks and updates the local dsh web runtime ({package}). The check runs once whenever the service starts, and a red dot marks this entry when a newer version exists.",
|
|
69
|
+
"field.current": "Current version",
|
|
70
|
+
"field.latest": "Latest version",
|
|
71
|
+
"field.channel": "Channel",
|
|
72
|
+
"field.checked": "Last checked",
|
|
73
|
+
"field.source": "Checked via",
|
|
74
|
+
"field.restartCommand": "Restart command",
|
|
75
|
+
"field.restartCommandPlaceholder": "Empty = built-in systemctl --user restart {unit}",
|
|
76
|
+
"field.restartCommandHint": "Empty uses the built-in command; a custom command runs after the install (via /bin/sh -c) with {unit} replaced by the service name. Saving applies immediately.",
|
|
77
|
+
"field.save": "Save",
|
|
78
|
+
"field.saved": "Saved",
|
|
79
|
+
"field.saveFailed": "Save failed: {error}",
|
|
80
|
+
"value.unknown": "Unknown",
|
|
81
|
+
"value.none": "Not checked yet",
|
|
82
|
+
"source.npm-view": "npm CLI",
|
|
83
|
+
"source.registry-fetch": "Registry endpoint",
|
|
84
|
+
"state.checking": "Checking…",
|
|
85
|
+
"state.upToDate": "Up to date",
|
|
86
|
+
"state.updateAvailable": "A newer version is available: {version}",
|
|
87
|
+
"state.ahead": "Current version is ahead of this channel",
|
|
88
|
+
"state.checkFailed": "Check failed: {error}",
|
|
89
|
+
"state.notChecked": "Update not checked yet",
|
|
90
|
+
"action.check": "Check version",
|
|
91
|
+
"action.update": "Update version",
|
|
92
|
+
"action.retry": "Retry",
|
|
93
|
+
"update.running": "Installing {target}…",
|
|
94
|
+
"update.installed": "Installed; restarting the web service…",
|
|
95
|
+
"update.restarting": "Restarting the web service; the page reconnects automatically…",
|
|
96
|
+
"update.done": "Updated to {version}",
|
|
97
|
+
"update.restartSkipped": "Installed; auto-restart disabled by config, restart the service manually",
|
|
98
|
+
"update.failed": "Update failed: {error}",
|
|
99
|
+
"update.sudoHint": "The update writes into the system npm prefix ({root}) through sudo -n. If passwordless sudo is unavailable, authorize it once in a terminal.",
|
|
100
|
+
"notice.checkStarted": "Version check requested from npm",
|
|
101
|
+
"notice.confirmTitle": "Confirm update",
|
|
102
|
+
"notice.confirmBody": "This updates {package} to {version} and restarts the web service afterwards. The page disconnects briefly and reconnects automatically.",
|
|
103
|
+
"notice.confirmOk": "Start update",
|
|
104
|
+
"notice.confirmCancel": "Cancel",
|
|
105
|
+
"notice.close": "Close",
|
|
106
|
+
"log.show": "Show install output",
|
|
107
|
+
"log.hide": "Hide install output",
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const EMPTY_STATUS = {
|
|
112
|
+
phase: "idle",
|
|
113
|
+
instanceId: null,
|
|
114
|
+
unit: "deepseek-harness-web.service",
|
|
115
|
+
packageName: "@deepseek-ai/dsh",
|
|
116
|
+
channel: "latest",
|
|
117
|
+
currentVersion: "unknown",
|
|
118
|
+
latestVersion: null,
|
|
119
|
+
updateAvailable: false,
|
|
120
|
+
relation: "unknown",
|
|
121
|
+
checkedAt: null,
|
|
122
|
+
checkError: null,
|
|
123
|
+
checkSource: null,
|
|
124
|
+
currentRoot: null,
|
|
125
|
+
sudoRequired: true,
|
|
126
|
+
restartCommand: null,
|
|
127
|
+
update: { state: "idle", target: null, startedAt: null, finishedAt: null, command: null, log: "", error: null },
|
|
128
|
+
restart: { scheduled: false, skipped: false, runAt: null, timerUnit: null, command: null, error: null },
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** Plugin-wide snapshot so the nav dot and the page share one truth. */
|
|
132
|
+
let snapshot = EMPTY_STATUS;
|
|
133
|
+
const listeners = new Set();
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Replace the shared snapshot and notify every mounted subscriber.
|
|
137
|
+
* @param {object} next - partial status fields.
|
|
138
|
+
* @returns {void}
|
|
139
|
+
*/
|
|
140
|
+
function publish(next) {
|
|
141
|
+
snapshot = { ...snapshot, ...next };
|
|
142
|
+
for (const listener of listeners) listener();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Subscribe to snapshot changes.
|
|
147
|
+
* @param {() => void} listener - callback.
|
|
148
|
+
* @returns {() => void} unsubscribe.
|
|
149
|
+
*/
|
|
150
|
+
function subscribe(listener) {
|
|
151
|
+
listeners.add(listener);
|
|
152
|
+
return () => { listeners.delete(listener); };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* React binding for the shared snapshot.
|
|
157
|
+
* @returns {object} current status.
|
|
158
|
+
*/
|
|
159
|
+
function useStatus() {
|
|
160
|
+
const [value, setValue] = React.useState(snapshot);
|
|
161
|
+
React.useEffect(() => subscribe(() => setValue(snapshot)), []);
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Call the host route and fold the returned status into the snapshot.
|
|
167
|
+
* @param {string} action - status, check or update.
|
|
168
|
+
* @param {string} [channel] - update channel for check.
|
|
169
|
+
* @param {object} [payload] - JSON body for POST actions.
|
|
170
|
+
* @returns {Promise<object>} response body.
|
|
171
|
+
*/
|
|
172
|
+
async function callHost(action, channel, payload) {
|
|
173
|
+
const url = new URL(ROUTE, document.baseURI);
|
|
174
|
+
url.searchParams.set("action", action);
|
|
175
|
+
if (action === "check" && typeof channel === "string" && channel !== "") {
|
|
176
|
+
url.searchParams.set("channel", channel);
|
|
177
|
+
}
|
|
178
|
+
let response;
|
|
179
|
+
try {
|
|
180
|
+
response = await fetch(url.href, {
|
|
181
|
+
method: action === "status" ? "GET" : "POST",
|
|
182
|
+
credentials: "same-origin",
|
|
183
|
+
cache: "no-store",
|
|
184
|
+
headers: payload === undefined
|
|
185
|
+
? { accept: "application/json" }
|
|
186
|
+
: { accept: "application/json", "content-type": "application/json" },
|
|
187
|
+
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
188
|
+
});
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new Error(String(error?.message ?? error));
|
|
191
|
+
}
|
|
192
|
+
let body = null;
|
|
193
|
+
try {
|
|
194
|
+
body = await response.json();
|
|
195
|
+
} catch {
|
|
196
|
+
body = null;
|
|
197
|
+
}
|
|
198
|
+
if (body !== null && typeof body.currentVersion === "string") publish(body);
|
|
199
|
+
if (!response.ok || body?.ok !== true) {
|
|
200
|
+
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
|
201
|
+
}
|
|
202
|
+
return body;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Format one ISO timestamp for the current locale.
|
|
207
|
+
* @param {string | null} value - ISO timestamp.
|
|
208
|
+
* @param {object} t - translator.
|
|
209
|
+
* @returns {string} display text.
|
|
210
|
+
*/
|
|
211
|
+
function formatTime(value, t) {
|
|
212
|
+
if (typeof value !== "string" || value === "") return t("value.none");
|
|
213
|
+
const date = new Date(value);
|
|
214
|
+
if (Number.isNaN(date.getTime())) return t("value.none");
|
|
215
|
+
const pad = (part) => String(part).padStart(2, "0");
|
|
216
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} `
|
|
217
|
+
+ `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A small filled circle used for availability dots.
|
|
222
|
+
* @param {{ color: string, size?: number }} props - dot options.
|
|
223
|
+
* @returns {object} React element.
|
|
224
|
+
*/
|
|
225
|
+
function Dot(props) {
|
|
226
|
+
const size = props.size ?? 8;
|
|
227
|
+
return h("span", {
|
|
228
|
+
"aria-hidden": true,
|
|
229
|
+
style: {
|
|
230
|
+
display: "inline-block",
|
|
231
|
+
flex: "none",
|
|
232
|
+
width: `${size}px`,
|
|
233
|
+
height: `${size}px`,
|
|
234
|
+
borderRadius: "50%",
|
|
235
|
+
background: props.color,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Nav glyph: an arrow into a tray, with the update dot when one is pending.
|
|
242
|
+
* The settings shell renders this inside `span.navIcon` (16px box).
|
|
243
|
+
* @param {{ size?: number, active?: boolean }} props - slot owner props.
|
|
244
|
+
* @returns {object} React element.
|
|
245
|
+
*/
|
|
246
|
+
function SectionIcon(props) {
|
|
247
|
+
const status = useStatus();
|
|
248
|
+
const size = props.size ?? 16;
|
|
249
|
+
const color = props.active === true
|
|
250
|
+
? "var(--dsw-alias-label-primary)"
|
|
251
|
+
: "var(--dsw-alias-label-secondary)";
|
|
252
|
+
return h(
|
|
253
|
+
"span",
|
|
254
|
+
{ style: { position: "relative", display: "inline-flex", alignItems: "center", justifyContent: "center", width: `${size}px`, height: `${size}px` } },
|
|
255
|
+
h(
|
|
256
|
+
"svg",
|
|
257
|
+
{
|
|
258
|
+
width: size,
|
|
259
|
+
height: size,
|
|
260
|
+
viewBox: "0 0 24 24",
|
|
261
|
+
fill: "none",
|
|
262
|
+
stroke: color,
|
|
263
|
+
strokeWidth: 1.8,
|
|
264
|
+
strokeLinecap: "round",
|
|
265
|
+
strokeLinejoin: "round",
|
|
266
|
+
"aria-hidden": true,
|
|
267
|
+
focusable: false,
|
|
268
|
+
},
|
|
269
|
+
h("path", { d: "M12 4v9" }),
|
|
270
|
+
h("path", { d: "M8.5 9.5 12 13l3.5-3.5" }),
|
|
271
|
+
h("path", { d: "M5 16.5v1.5a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-1.5" }),
|
|
272
|
+
),
|
|
273
|
+
status.updateAvailable === true
|
|
274
|
+
? h("span", {
|
|
275
|
+
style: {
|
|
276
|
+
position: "absolute",
|
|
277
|
+
top: "-2px",
|
|
278
|
+
right: "-2px",
|
|
279
|
+
width: "7px",
|
|
280
|
+
height: "7px",
|
|
281
|
+
borderRadius: "50%",
|
|
282
|
+
background: "var(--dsw-alias-state-error-primary)",
|
|
283
|
+
boxShadow: "0 0 0 2px var(--dsw-alias-bg-layer-2)",
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
: null,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const styleSheet = [
|
|
291
|
+
/* Page scaffold — matches the shipped settings pages: stacked rows, quiet surfaces. */
|
|
292
|
+
".dsvuRoot{box-sizing:border-box;display:flex;flex-direction:column;gap:16px;width:100%;max-width:720px;",
|
|
293
|
+
"padding:8px 0 24px;color:var(--dsw-alias-label-primary);font-size:14px;line-height:22px}",
|
|
294
|
+
".dsvuTitle{margin:0;font-size:17px;line-height:24px;font-weight:600}",
|
|
295
|
+
".dsvuDescription{margin:0;color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px}",
|
|
296
|
+
".dsvuCard{box-sizing:border-box;display:flex;flex-direction:column;border:1px solid var(--dsw-alias-border-l1);",
|
|
297
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1);overflow:hidden}",
|
|
298
|
+
".dsvuRow{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:10px 14px;",
|
|
299
|
+
"border-top:1px solid var(--dsw-alias-border-l1)}",
|
|
300
|
+
".dsvuRow:first-child{border-top:0}",
|
|
301
|
+
".dsvuLabel{color:var(--dsw-alias-label-secondary);flex:none}",
|
|
302
|
+
".dsvuValue{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:right}",
|
|
303
|
+
".dsvuMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px}",
|
|
304
|
+
".dsvuChannels{display:inline-flex;gap:6px;flex:none}",
|
|
305
|
+
".dsvuChannel{box-sizing:border-box;border:none;border-radius:var(--dsw-radius-sm,6px);cursor:pointer;font:inherit;",
|
|
306
|
+
"font-size:12px;line-height:20px;height:26px;padding:0 10px;color:var(--dsw-alias-label-secondary);background:transparent;",
|
|
307
|
+
"box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l2))}",
|
|
308
|
+
".dsvuChannel:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}",
|
|
309
|
+
".dsvuChannel:disabled{cursor:not-allowed;opacity:.5}",
|
|
310
|
+
".dsvuChannelActive{color:var(--dsw-alias-label-primary-foreground);background:var(--dsw-alias-button-primary-fill);",
|
|
311
|
+
"box-shadow:none;font-weight:500}",
|
|
312
|
+
".dsvuStatus{display:flex;align-items:center;gap:8px;padding:12px 14px;border-top:1px solid var(--dsw-alias-border-l1);",
|
|
313
|
+
"background:var(--dsw-alias-bg-layer-2);font-size:13px;line-height:20px}",
|
|
314
|
+
".dsvuStatus[data-tone=ok]{color:var(--dsw-alias-label-secondary)}",
|
|
315
|
+
".dsvuStatus[data-tone=warn]{color:var(--dsw-alias-state-warn-primary)}",
|
|
316
|
+
".dsvuStatus[data-tone=error]{color:var(--dsw-alias-state-error-primary)}",
|
|
317
|
+
".dsvuActions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
|
|
318
|
+
".dsvuButton{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;",
|
|
319
|
+
"border:none;border-radius:var(--dsw-radius-md);cursor:pointer;font:inherit;font-size:13px;line-height:20px;",
|
|
320
|
+
"height:32px;padding:0 12px;color:var(--dsw-alias-label-primary);background:transparent;",
|
|
321
|
+
"box-shadow:inset 0 0 0 var(--dsh-hairline-width,.5px) var(--dsh-button-outline-color,var(--dsw-alias-border-l2))}",
|
|
322
|
+
".dsvuButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}",
|
|
323
|
+
".dsvuButton:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}",
|
|
324
|
+
".dsvuButton:disabled{cursor:not-allowed;opacity:.5}",
|
|
325
|
+
".dsvuButtonPrimary{background:var(--dsw-alias-button-primary-fill);color:var(--dsw-alias-label-primary-foreground);",
|
|
326
|
+
"box-shadow:none;font-weight:500}",
|
|
327
|
+
".dsvuButtonPrimary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover)}",
|
|
328
|
+
".dsvuHint{margin:0;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}",
|
|
329
|
+
".dsvuFieldHint{margin:0;padding:0 14px 10px;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}",
|
|
330
|
+
".dsvuRestartField{display:flex;align-items:center;gap:8px;flex:1;min-width:0;justify-content:flex-end}",
|
|
331
|
+
".dsvuInput{box-sizing:border-box;flex:1;min-width:0;height:28px;padding:0 8px;border:1px solid var(--dsw-alias-border-l2);",
|
|
332
|
+
"border-radius:var(--dsw-radius-sm,6px);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);",
|
|
333
|
+
"font:inherit;font-size:13px;line-height:20px}",
|
|
334
|
+
".dsvuInput:focus{outline:none;border-color:var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary))}",
|
|
335
|
+
".dsvuSaveOk{color:var(--dsw-alias-state-success-primary);font-size:12px;flex:none}",
|
|
336
|
+
".dsvuSaveError{color:var(--dsw-alias-state-error-primary);font-size:12px;flex:none;min-width:0;",
|
|
337
|
+
"overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
|
|
338
|
+
".dsvuProgress{display:flex;flex-direction:column;gap:8px;padding:12px 14px;border:1px solid var(--dsw-alias-border-l1);",
|
|
339
|
+
"border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1);font-size:13px}",
|
|
340
|
+
".dsvuSpinner{display:inline-block;width:12px;height:12px;border:1.5px solid var(--dsw-alias-border-l2);",
|
|
341
|
+
"border-top-color:var(--dsw-alias-label-primary);border-radius:50%;animation:dsvuSpin 1s linear infinite}",
|
|
342
|
+
"@keyframes dsvuSpin{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}",
|
|
343
|
+
"@media (prefers-reduced-motion:reduce){.dsvuSpinner{animation:none}}",
|
|
344
|
+
".dsvuLog{margin:0;max-height:220px;overflow:auto;padding:10px 12px;border-radius:var(--dsw-radius-sm);",
|
|
345
|
+
"background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);",
|
|
346
|
+
"font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;line-height:18px;white-space:pre-wrap;overflow-wrap:anywhere}",
|
|
347
|
+
".dsvuLink{border:none;background:transparent;padding:0;color:var(--dsw-alias-label-secondary);",
|
|
348
|
+
"font:inherit;font-size:12px;cursor:pointer;text-decoration:underline}",
|
|
349
|
+
".dsvuLink:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}",
|
|
350
|
+
".dsvuError{margin:0;color:var(--dsw-alias-state-error-primary);font-size:13px;line-height:20px}",
|
|
351
|
+
".dsvuNotice{margin:0;color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px}",
|
|
352
|
+
/* Confirmation dialog — same metrics as the shipped Modal primitive. */
|
|
353
|
+
".dsvuDialogRoot{position:fixed;inset:0;z-index:1300;display:flex;align-items:center;justify-content:center;padding:24px}",
|
|
354
|
+
".dsvuDialogMask{position:absolute;inset:0;background:var(--dsw-alias-bg-mask-1,var(--dsw-alias-bg-layer-2));backdrop-filter:var(--dsw-mask-blur)}",
|
|
355
|
+
".dsvuDialog{box-sizing:border-box;position:relative;z-index:1;display:flex;flex-direction:column;gap:20px;width:min(400px,100%);",
|
|
356
|
+
"padding:22px 24px 24px;border-radius:var(--dsw-radius-panel);background:var(--dsw-alias-bg-layer-2);",
|
|
357
|
+
"box-shadow:var(--dsw-elevation-prominent)}",
|
|
358
|
+
".dsvuDialogTitle{margin:0;font-size:16px;line-height:24px;font-weight:500}",
|
|
359
|
+
".dsvuDialogBody{margin:0;font-size:14px;line-height:22px;overflow-wrap:anywhere}",
|
|
360
|
+
".dsvuDialogFooter{display:flex;align-items:center;justify-content:flex-end;gap:8px}",
|
|
361
|
+
].join("");
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Confirmation dialog for the destructive update action.
|
|
365
|
+
* @param {{ t: object, packageName: string, version: string, onCancel: () => void, onConfirm: () => void }} props - dialog props.
|
|
366
|
+
* @returns {object} React element.
|
|
367
|
+
*/
|
|
368
|
+
function UpdateDialog(props) {
|
|
369
|
+
const { t } = props;
|
|
370
|
+
React.useEffect(() => {
|
|
371
|
+
const onKeyDown = (event) => {
|
|
372
|
+
if (event.key === "Escape") {
|
|
373
|
+
event.preventDefault();
|
|
374
|
+
props.onCancel();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
window.addEventListener("keydown", onKeyDown);
|
|
378
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
379
|
+
}, [props.onCancel]);
|
|
380
|
+
|
|
381
|
+
return h(
|
|
382
|
+
"div",
|
|
383
|
+
{ className: "dsvuDialogRoot", role: "presentation" },
|
|
384
|
+
h("div", { className: "dsvuDialogMask", onClick: props.onCancel }),
|
|
385
|
+
h(
|
|
386
|
+
"div",
|
|
387
|
+
{ className: "dsvuDialog", role: "dialog", "aria-modal": "true", "aria-label": t("notice.confirmTitle") },
|
|
388
|
+
h("h2", { className: "dsvuDialogTitle" }, t("notice.confirmTitle")),
|
|
389
|
+
h("p", { className: "dsvuDialogBody" }, t("notice.confirmBody", {
|
|
390
|
+
package: props.packageName,
|
|
391
|
+
version: props.version,
|
|
392
|
+
})),
|
|
393
|
+
h(
|
|
394
|
+
"div",
|
|
395
|
+
{ className: "dsvuDialogFooter" },
|
|
396
|
+
h("button", { type: "button", className: "dsvuButton", onClick: props.onCancel }, t("notice.confirmCancel")),
|
|
397
|
+
h("button", { type: "button", className: "dsvuButton dsvuButtonPrimary", onClick: props.onConfirm, autoFocus: true }, t("notice.confirmOk")),
|
|
398
|
+
),
|
|
399
|
+
),
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Settings page for checking and installing runtime updates.
|
|
405
|
+
* @param {{ t: object }} props - slot props plus translator.
|
|
406
|
+
* @returns {object} React element.
|
|
407
|
+
*/
|
|
408
|
+
function VersionPage(props) {
|
|
409
|
+
const { t } = props;
|
|
410
|
+
const status = useStatus();
|
|
411
|
+
const [busy, setBusy] = React.useState(null);
|
|
412
|
+
const [message, setMessage] = React.useState(null);
|
|
413
|
+
const [showLog, setShowLog] = React.useState(false);
|
|
414
|
+
const [confirming, setConfirming] = React.useState(false);
|
|
415
|
+
const [commandDraft, setCommandDraft] = React.useState(
|
|
416
|
+
typeof status.restartCommand === "string" ? status.restartCommand : "",
|
|
417
|
+
);
|
|
418
|
+
const [savingCommand, setSavingCommand] = React.useState(false);
|
|
419
|
+
const [saveResult, setSaveResult] = React.useState(null);
|
|
420
|
+
const instanceRef = React.useRef(status.instanceId);
|
|
421
|
+
const restartSeenRef = React.useRef(false);
|
|
422
|
+
|
|
423
|
+
const active = status.update.state === "running"
|
|
424
|
+
|| status.phase === "updating"
|
|
425
|
+
|| status.phase === "restarting";
|
|
426
|
+
|
|
427
|
+
/** One status refresh that survives the connection dropping mid-restart. */
|
|
428
|
+
const refresh = React.useCallback(async () => {
|
|
429
|
+
try {
|
|
430
|
+
await callHost("status");
|
|
431
|
+
} catch {
|
|
432
|
+
/* The service is restarting; the poll below keeps trying. */
|
|
433
|
+
}
|
|
434
|
+
}, []);
|
|
435
|
+
|
|
436
|
+
React.useEffect(() => {
|
|
437
|
+
void refresh();
|
|
438
|
+
}, [refresh]);
|
|
439
|
+
|
|
440
|
+
React.useEffect(() => {
|
|
441
|
+
instanceRef.current = status.instanceId;
|
|
442
|
+
}, [status.instanceId]);
|
|
443
|
+
|
|
444
|
+
React.useEffect(() => {
|
|
445
|
+
if (status.update.state !== "idle" && status.update.state !== "error") {
|
|
446
|
+
restartSeenRef.current = false;
|
|
447
|
+
}
|
|
448
|
+
}, [status.update.state]);
|
|
449
|
+
|
|
450
|
+
React.useEffect(() => {
|
|
451
|
+
if (active !== true) return undefined;
|
|
452
|
+
const startedAt = Date.now();
|
|
453
|
+
let stopped = false;
|
|
454
|
+
const timer = setInterval(() => {
|
|
455
|
+
if (stopped) return;
|
|
456
|
+
if (Date.now() - startedAt > POLL_TIMEOUT_MS) {
|
|
457
|
+
stopped = true;
|
|
458
|
+
clearInterval(timer);
|
|
459
|
+
setMessage({ kind: "error", text: t("update.restarting") });
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
void callHost("status").then((body) => {
|
|
463
|
+
if (typeof body.instanceId === "string" && instanceRef.current !== null
|
|
464
|
+
&& body.instanceId !== instanceRef.current && restartSeenRef.current !== true) {
|
|
465
|
+
restartSeenRef.current = true;
|
|
466
|
+
instanceRef.current = body.instanceId;
|
|
467
|
+
setMessage({ kind: "notice", text: t("update.done", { version: body.currentVersion }) });
|
|
468
|
+
}
|
|
469
|
+
}).catch(() => { /* keep polling until the deadline */ });
|
|
470
|
+
}, POLL_INTERVAL_MS);
|
|
471
|
+
return () => {
|
|
472
|
+
stopped = true;
|
|
473
|
+
clearInterval(timer);
|
|
474
|
+
};
|
|
475
|
+
}, [active, t]);
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Run one host action with the shared busy/error handling.
|
|
479
|
+
* @param {string} action - check or update.
|
|
480
|
+
* @returns {Promise<void>} completion.
|
|
481
|
+
*/
|
|
482
|
+
const runAction = async (action, channel) => {
|
|
483
|
+
setBusy(action);
|
|
484
|
+
setMessage(null);
|
|
485
|
+
try {
|
|
486
|
+
await callHost(action, channel);
|
|
487
|
+
if (action === "check") setMessage({ kind: "notice", text: t("notice.checkStarted") });
|
|
488
|
+
} catch (error) {
|
|
489
|
+
setMessage({ kind: "error", text: String(error?.message ?? error) });
|
|
490
|
+
} finally {
|
|
491
|
+
setBusy(null);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
/** Persist the restart-command field through the host route (volatile, in place). */
|
|
496
|
+
const saveRestartCommand = async () => {
|
|
497
|
+
setSavingCommand(true);
|
|
498
|
+
setSaveResult(null);
|
|
499
|
+
try {
|
|
500
|
+
await callHost("set-restart-command", undefined, { command: commandDraft });
|
|
501
|
+
setSaveResult({ ok: true });
|
|
502
|
+
} catch (error) {
|
|
503
|
+
setSaveResult({ ok: false, error: String(error?.message ?? error) });
|
|
504
|
+
} finally {
|
|
505
|
+
setSavingCommand(false);
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
const checking = busy === "check" || status.phase === "checking";
|
|
510
|
+
const updating = busy === "update" || active;
|
|
511
|
+
const canUpdate = status.updateAvailable === true && checking !== true && updating !== true && status.phase !== "restarting";
|
|
512
|
+
|
|
513
|
+
let tone = "ok";
|
|
514
|
+
let stateText;
|
|
515
|
+
let stateDot = null;
|
|
516
|
+
if (status.phase === "checking") {
|
|
517
|
+
stateText = t("state.checking");
|
|
518
|
+
} else if (status.checkError !== null) {
|
|
519
|
+
tone = "error";
|
|
520
|
+
stateDot = h(Dot, { color: "var(--dsw-alias-state-error-primary)" });
|
|
521
|
+
stateText = t("state.checkFailed", { error: status.checkError });
|
|
522
|
+
} else if (status.checkedAt === null) {
|
|
523
|
+
tone = "ok";
|
|
524
|
+
stateText = t("state.notChecked");
|
|
525
|
+
} else if (status.updateAvailable === true) {
|
|
526
|
+
tone = "warn";
|
|
527
|
+
stateDot = h(Dot, { color: "var(--dsw-alias-state-error-primary)" });
|
|
528
|
+
stateText = t("state.updateAvailable", { version: status.latestVersion ?? "" });
|
|
529
|
+
} else if (status.relation === "older") {
|
|
530
|
+
tone = "ok";
|
|
531
|
+
stateText = t("state.ahead");
|
|
532
|
+
} else {
|
|
533
|
+
tone = "ok";
|
|
534
|
+
stateDot = h(Dot, { color: "var(--dsw-alias-state-success-primary)" });
|
|
535
|
+
stateText = t("state.upToDate");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const field = (label, value, mono) => h(
|
|
539
|
+
"div",
|
|
540
|
+
{ className: "dsvuRow", key: label },
|
|
541
|
+
h("span", { className: "dsvuLabel" }, label),
|
|
542
|
+
h("span", { className: mono === true ? "dsvuValue dsvuMono" : "dsvuValue" }, value),
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
const latestText = status.latestVersion === null ? t("value.unknown") : status.latestVersion;
|
|
546
|
+
|
|
547
|
+
return h(
|
|
548
|
+
React.Fragment,
|
|
549
|
+
null,
|
|
550
|
+
h("style", null, styleSheet),
|
|
551
|
+
h(
|
|
552
|
+
"div",
|
|
553
|
+
{ className: "dsvuRoot" },
|
|
554
|
+
h("h1", { className: "dsvuTitle" }, t("page.title")),
|
|
555
|
+
h("p", { className: "dsvuDescription" }, t("page.description", { package: status.packageName })),
|
|
556
|
+
h(
|
|
557
|
+
"div",
|
|
558
|
+
{ className: "dsvuCard" },
|
|
559
|
+
field(t("field.current"), status.currentVersion === "unknown" ? t("value.unknown") : status.currentVersion, true),
|
|
560
|
+
field(t("field.latest"), latestText, true),
|
|
561
|
+
h(
|
|
562
|
+
"div",
|
|
563
|
+
{ className: "dsvuRow", key: "channel" },
|
|
564
|
+
h("span", { className: "dsvuLabel" }, t("field.channel")),
|
|
565
|
+
h(
|
|
566
|
+
"div",
|
|
567
|
+
{ className: "dsvuChannels", role: "group", "aria-label": t("field.channel") },
|
|
568
|
+
(status.availableChannels && status.availableChannels.length > 0
|
|
569
|
+
? status.availableChannels
|
|
570
|
+
: ["latest", "next", "alpha"]
|
|
571
|
+
).map((channel) => h(
|
|
572
|
+
"button",
|
|
573
|
+
{
|
|
574
|
+
type: "button",
|
|
575
|
+
key: channel,
|
|
576
|
+
className: channel === status.channel ? "dsvuChannel dsvuChannelActive" : "dsvuChannel",
|
|
577
|
+
disabled: checking === true || updating === true,
|
|
578
|
+
onClick: () => { void runAction("check", channel); },
|
|
579
|
+
},
|
|
580
|
+
channel,
|
|
581
|
+
)),
|
|
582
|
+
),
|
|
583
|
+
),
|
|
584
|
+
field(t("field.checked"), formatTime(status.checkedAt, t)),
|
|
585
|
+
status.checkSource === null ? null : field(t("field.source"), t(`source.${status.checkSource}`)),
|
|
586
|
+
h(
|
|
587
|
+
"div",
|
|
588
|
+
{ className: "dsvuRow", key: "restart-command" },
|
|
589
|
+
h("span", { className: "dsvuLabel" }, t("field.restartCommand")),
|
|
590
|
+
h(
|
|
591
|
+
"div",
|
|
592
|
+
{ className: "dsvuRestartField" },
|
|
593
|
+
h("input", {
|
|
594
|
+
type: "text",
|
|
595
|
+
className: "dsvuInput",
|
|
596
|
+
value: commandDraft,
|
|
597
|
+
placeholder: t("field.restartCommandPlaceholder", { unit: status.unit }),
|
|
598
|
+
spellCheck: false,
|
|
599
|
+
onChange: (event) => {
|
|
600
|
+
setCommandDraft(event.target.value);
|
|
601
|
+
setSaveResult(null);
|
|
602
|
+
},
|
|
603
|
+
onKeyDown: (event) => {
|
|
604
|
+
if (event.key === "Enter" && savingCommand !== true) {
|
|
605
|
+
event.preventDefault();
|
|
606
|
+
void saveRestartCommand();
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
}),
|
|
610
|
+
h(
|
|
611
|
+
"button",
|
|
612
|
+
{
|
|
613
|
+
type: "button",
|
|
614
|
+
className: "dsvuButton",
|
|
615
|
+
disabled: savingCommand === true,
|
|
616
|
+
onClick: () => { void saveRestartCommand(); },
|
|
617
|
+
},
|
|
618
|
+
t("field.save"),
|
|
619
|
+
),
|
|
620
|
+
saveResult === null ? null
|
|
621
|
+
: saveResult.ok === true
|
|
622
|
+
? h("span", { className: "dsvuSaveOk" }, t("field.saved"))
|
|
623
|
+
: h("span", { className: "dsvuSaveError" }, t("field.saveFailed", { error: saveResult.error })),
|
|
624
|
+
),
|
|
625
|
+
),
|
|
626
|
+
h("p", { className: "dsvuFieldHint", key: "restart-command-hint" }, t("field.restartCommandHint", { unit: status.unit })),
|
|
627
|
+
h(
|
|
628
|
+
"div",
|
|
629
|
+
{ className: "dsvuStatus", "data-tone": tone },
|
|
630
|
+
stateDot,
|
|
631
|
+
h("span", null, stateText),
|
|
632
|
+
),
|
|
633
|
+
),
|
|
634
|
+
h(
|
|
635
|
+
"div",
|
|
636
|
+
{ className: "dsvuActions" },
|
|
637
|
+
h(
|
|
638
|
+
"button",
|
|
639
|
+
{
|
|
640
|
+
type: "button",
|
|
641
|
+
className: "dsvuButton",
|
|
642
|
+
disabled: checking === true || updating === true,
|
|
643
|
+
onClick: () => { void runAction("check"); },
|
|
644
|
+
},
|
|
645
|
+
checking === true ? h("span", { className: "dsvuSpinner" }) : null,
|
|
646
|
+
t("action.check"),
|
|
647
|
+
),
|
|
648
|
+
h(
|
|
649
|
+
"button",
|
|
650
|
+
{
|
|
651
|
+
type: "button",
|
|
652
|
+
className: "dsvuButton dsvuButtonPrimary",
|
|
653
|
+
disabled: canUpdate !== true,
|
|
654
|
+
title: canUpdate === true ? t("action.update") : stateText,
|
|
655
|
+
onClick: () => setConfirming(true),
|
|
656
|
+
},
|
|
657
|
+
t("action.update"),
|
|
658
|
+
),
|
|
659
|
+
),
|
|
660
|
+
canUpdate === true && status.sudoRequired === true
|
|
661
|
+
? h("p", { className: "dsvuHint" }, t("update.sudoHint", { root: status.currentRoot ?? "npm root -g" }))
|
|
662
|
+
: null,
|
|
663
|
+
message === null
|
|
664
|
+
? null
|
|
665
|
+
: h(
|
|
666
|
+
"p",
|
|
667
|
+
{ className: message.kind === "error" ? "dsvuError" : "dsvuNotice" },
|
|
668
|
+
message.text,
|
|
669
|
+
),
|
|
670
|
+
updating === true
|
|
671
|
+
? h(
|
|
672
|
+
"div",
|
|
673
|
+
{ className: "dsvuProgress" },
|
|
674
|
+
h(
|
|
675
|
+
"div",
|
|
676
|
+
{ style: { display: "flex", alignItems: "center", gap: "8px" } },
|
|
677
|
+
h("span", { className: "dsvuSpinner" }),
|
|
678
|
+
h(
|
|
679
|
+
"span",
|
|
680
|
+
null,
|
|
681
|
+
status.phase === "restarting"
|
|
682
|
+
? t("update.restarting")
|
|
683
|
+
: status.update.state === "installed"
|
|
684
|
+
? t("update.installed")
|
|
685
|
+
: t("update.running", { target: status.update.target ?? status.latestVersion ?? "" }),
|
|
686
|
+
),
|
|
687
|
+
),
|
|
688
|
+
status.update.command === null
|
|
689
|
+
? null
|
|
690
|
+
: h("span", { className: "dsvuMono dsvuHint" }, status.update.command),
|
|
691
|
+
status.update.log === "" ? null : h(
|
|
692
|
+
React.Fragment,
|
|
693
|
+
null,
|
|
694
|
+
h(
|
|
695
|
+
"button",
|
|
696
|
+
{ type: "button", className: "dsvuLink", onClick: () => setShowLog((value) => !value) },
|
|
697
|
+
showLog ? t("log.hide") : t("log.show"),
|
|
698
|
+
),
|
|
699
|
+
showLog ? h("pre", { className: "dsvuLog" }, status.update.log) : null,
|
|
700
|
+
),
|
|
701
|
+
status.update.error === null
|
|
702
|
+
? null
|
|
703
|
+
: h("p", { className: "dsvuError" }, t("update.failed", { error: status.update.error })),
|
|
704
|
+
)
|
|
705
|
+
: null,
|
|
706
|
+
status.update.state === "error" && status.update.error !== null && updating !== true
|
|
707
|
+
? h("p", { className: "dsvuError" }, t("update.failed", { error: status.update.error }))
|
|
708
|
+
: null,
|
|
709
|
+
status.restart.scheduled === true
|
|
710
|
+
? h(
|
|
711
|
+
"p",
|
|
712
|
+
{ className: "dsvuHint" },
|
|
713
|
+
t("update.restarting"),
|
|
714
|
+
status.restart.command === null
|
|
715
|
+
? null
|
|
716
|
+
: h("span", { className: "dsvuMono", style: { display: "block", marginTop: "4px" } }, status.restart.command),
|
|
717
|
+
)
|
|
718
|
+
: null,
|
|
719
|
+
status.restart.skipped === true
|
|
720
|
+
? h("p", { className: "dsvuHint" }, t("update.restartSkipped"))
|
|
721
|
+
: null,
|
|
722
|
+
),
|
|
723
|
+
confirming === true
|
|
724
|
+
? h(UpdateDialog, {
|
|
725
|
+
t,
|
|
726
|
+
packageName: status.packageName,
|
|
727
|
+
version: status.latestVersion ?? "",
|
|
728
|
+
onCancel: () => setConfirming(false),
|
|
729
|
+
onConfirm: () => {
|
|
730
|
+
setConfirming(false);
|
|
731
|
+
void runAction("update");
|
|
732
|
+
},
|
|
733
|
+
})
|
|
734
|
+
: null,
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
return {
|
|
739
|
+
inject: ["slots", "locale"],
|
|
740
|
+
/**
|
|
741
|
+
* Register the locale dictionaries, the settings entry and its nav icon.
|
|
742
|
+
* @param {object} ctx - client plugin context.
|
|
743
|
+
* @returns {void}
|
|
744
|
+
*/
|
|
745
|
+
apply(ctx) {
|
|
746
|
+
const t = ctx.locale.bind(NS);
|
|
747
|
+
ctx.effect(
|
|
748
|
+
() => ctx.locale.register(NS, dictionaries),
|
|
749
|
+
"dsh-web-update: locale dictionaries",
|
|
750
|
+
);
|
|
751
|
+
ctx.effect(() => {
|
|
752
|
+
void callHost("status").catch(() => { /* the host may still be checking */ });
|
|
753
|
+
return () => {};
|
|
754
|
+
}, "dsh-web-update: initial status");
|
|
755
|
+
|
|
756
|
+
ctx.slots.inject("settings.section.icon", () => ctx.slots.register(
|
|
757
|
+
{
|
|
758
|
+
name: "settings.section.icon",
|
|
759
|
+
id: SECTION_ID,
|
|
760
|
+
},
|
|
761
|
+
(owner) => h(SectionIcon, {
|
|
762
|
+
size: owner?.size ?? 16,
|
|
763
|
+
active: owner?.active === true,
|
|
764
|
+
}),
|
|
765
|
+
));
|
|
766
|
+
|
|
767
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register(
|
|
768
|
+
{
|
|
769
|
+
name: "settings.section",
|
|
770
|
+
id: SECTION_ID,
|
|
771
|
+
order: SECTION_ORDER,
|
|
772
|
+
label: () => t("nav.label"),
|
|
773
|
+
},
|
|
774
|
+
(ownerProps) => h(VersionPage, { ...ownerProps, t }),
|
|
775
|
+
));
|
|
776
|
+
},
|
|
777
|
+
};
|
|
778
|
+
},
|
|
779
|
+
});
|