@ququ-jiaxk/dsh-plugin-center 0.1.33 → 0.1.35
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/lib/client.js +132 -40
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -30,7 +30,7 @@ __export(client_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(client_exports);
|
|
31
31
|
var import_react = require("react");
|
|
32
32
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
33
|
+
var PLUGIN_VERSION = true ? "0.1.35" : "0.0.0";
|
|
34
34
|
var PANEL_ID = "plugin-center";
|
|
35
35
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
36
36
|
var hostCtx = null;
|
|
@@ -49,6 +49,63 @@ var selfUpdateTarget = null;
|
|
|
49
49
|
var selfUpdatePolling = false;
|
|
50
50
|
var selfUpdateNotified = false;
|
|
51
51
|
var lastSelfCheckAt = 0;
|
|
52
|
+
var selfUpdateInfo = { latest: null, checkedAt: 0, checking: false };
|
|
53
|
+
var selfUpdateSubscribers = /* @__PURE__ */ new Set();
|
|
54
|
+
var selfUpdateRequest = null;
|
|
55
|
+
function publishSelfUpdate(patch) {
|
|
56
|
+
selfUpdateInfo = { ...selfUpdateInfo, ...patch };
|
|
57
|
+
for (const notify of selfUpdateSubscribers) notify();
|
|
58
|
+
}
|
|
59
|
+
function useSelfUpdateInfo() {
|
|
60
|
+
const [info, setInfo] = (0, import_react.useState)(selfUpdateInfo);
|
|
61
|
+
(0, import_react.useEffect)(() => {
|
|
62
|
+
const notify = () => setInfo(selfUpdateInfo);
|
|
63
|
+
selfUpdateSubscribers.add(notify);
|
|
64
|
+
return () => {
|
|
65
|
+
selfUpdateSubscribers.delete(notify);
|
|
66
|
+
};
|
|
67
|
+
}, []);
|
|
68
|
+
return info;
|
|
69
|
+
}
|
|
70
|
+
async function fetchSelfUpdateInfo() {
|
|
71
|
+
if (typeof fetch !== "function") return null;
|
|
72
|
+
if (selfUpdateRequest) return selfUpdateRequest;
|
|
73
|
+
publishSelfUpdate({ checking: true });
|
|
74
|
+
selfUpdateRequest = (async () => {
|
|
75
|
+
try {
|
|
76
|
+
const response = await fetch("/plugin-center/api/self/update-check", {
|
|
77
|
+
signal: typeof AbortSignal !== "undefined" && AbortSignal.timeout ? AbortSignal.timeout(15e3) : void 0
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
80
|
+
const data = await response.json();
|
|
81
|
+
publishSelfUpdate({
|
|
82
|
+
latest: data?.status === "available" && data.latest ? String(data.latest) : null,
|
|
83
|
+
checkedAt: Date.now(),
|
|
84
|
+
checking: false
|
|
85
|
+
});
|
|
86
|
+
return data;
|
|
87
|
+
} catch {
|
|
88
|
+
publishSelfUpdate({ checkedAt: Date.now(), checking: false });
|
|
89
|
+
return null;
|
|
90
|
+
} finally {
|
|
91
|
+
selfUpdateRequest = null;
|
|
92
|
+
}
|
|
93
|
+
})();
|
|
94
|
+
return selfUpdateRequest;
|
|
95
|
+
}
|
|
96
|
+
function startSelfUpdateWatcher() {
|
|
97
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
98
|
+
if (typeof fetch !== "function" || typeof setTimeout !== "function") return;
|
|
99
|
+
setTimeout(() => void fetchSelfUpdateInfo(), 2500);
|
|
100
|
+
if (typeof setInterval === "function") {
|
|
101
|
+
setInterval(() => void fetchSelfUpdateInfo(), 6 * 60 * 60 * 1e3);
|
|
102
|
+
}
|
|
103
|
+
document.addEventListener("visibilitychange", () => {
|
|
104
|
+
if (document.visibilityState !== "visible") return;
|
|
105
|
+
if (Date.now() - selfUpdateInfo.checkedAt < 30 * 60 * 1e3) return;
|
|
106
|
+
void fetchSelfUpdateInfo();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
52
109
|
var authDraft = null;
|
|
53
110
|
var uploadDraft = null;
|
|
54
111
|
async function api(path, init = {}) {
|
|
@@ -94,13 +151,18 @@ function apply(ctx) {
|
|
|
94
151
|
ctx.slots.inject("main", function* () {
|
|
95
152
|
yield ctx.slots.register({ name: "main", key: PANEL_ID }, Panel);
|
|
96
153
|
});
|
|
154
|
+
startSelfUpdateWatcher();
|
|
97
155
|
}
|
|
98
|
-
function PanelIcon() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
102
|
-
|
|
103
|
-
|
|
156
|
+
function PanelIcon({ size = 16 }) {
|
|
157
|
+
const { latest } = useSelfUpdateInfo();
|
|
158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "pcx-sidebar-icon", children: [
|
|
159
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "1.75", y: "1.75", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "9.25", y: "1.75", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "1.75", y: "9.25", width: "5", height: "5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.3" }),
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M11.75 9.5v4.25M9.63 11.63h4.25", stroke: "currentColor", strokeWidth: "1.3", strokeLinecap: "round" })
|
|
164
|
+
] }),
|
|
165
|
+
latest ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-sidebar-dot", "aria-hidden": "true" }) : null
|
|
104
166
|
] });
|
|
105
167
|
}
|
|
106
168
|
function isNewer(latest, installed) {
|
|
@@ -168,9 +230,22 @@ function Panel() {
|
|
|
168
230
|
const [dialog, setDialog] = (0, import_react.useState)(null);
|
|
169
231
|
const [passwordOpen, setPasswordOpen] = (0, import_react.useState)(false);
|
|
170
232
|
const [authView, setAuthView] = (0, import_react.useState)("login");
|
|
171
|
-
const [selfUpdate, setSelfUpdate] = (0, import_react.useState)(
|
|
172
|
-
selfUpdateTarget
|
|
173
|
-
|
|
233
|
+
const [selfUpdate, setSelfUpdate] = (0, import_react.useState)(() => {
|
|
234
|
+
if (selfUpdateTarget) return { phase: "running", to: selfUpdateTarget };
|
|
235
|
+
if (selfUpdateInfo.latest) return { phase: "available", to: selfUpdateInfo.latest };
|
|
236
|
+
return { phase: "idle" };
|
|
237
|
+
});
|
|
238
|
+
const updateInfo = useSelfUpdateInfo();
|
|
239
|
+
(0, import_react.useEffect)(() => {
|
|
240
|
+
if (selfUpdateTarget) return;
|
|
241
|
+
if (updateInfo.latest) {
|
|
242
|
+
setSelfUpdate(
|
|
243
|
+
(current) => current.phase === "idle" || current.phase === "checking" ? { phase: "available", to: updateInfo.latest } : current
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
setSelfUpdate((current) => current.phase === "available" ? { phase: "idle" } : current);
|
|
247
|
+
}
|
|
248
|
+
}, [updateInfo.latest]);
|
|
174
249
|
(0, import_react.useEffect)(() => {
|
|
175
250
|
if (!notice) return;
|
|
176
251
|
const timer = setTimeout(() => setNotice(""), 4e3);
|
|
@@ -215,37 +290,38 @@ function Panel() {
|
|
|
215
290
|
}, [cached, load]);
|
|
216
291
|
async function checkSelfUpdate(manual) {
|
|
217
292
|
if (manual) setSelfUpdate({ phase: "checking" });
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
setSelfUpdate({ phase: "available", to: result.latest });
|
|
222
|
-
if (manual) setNotice(`\u53D1\u73B0\u65B0\u7248\u672C v${result.latest}`);
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (result?.status === "not-updatable") {
|
|
226
|
-
setSelfUpdate({ phase: "idle" });
|
|
227
|
-
if (manual) {
|
|
228
|
-
setDialog({
|
|
229
|
-
title: "\u5F53\u524D\u5B89\u88C5\u65B9\u5F0F\u4E0D\u652F\u6301\u81EA\u66F4\u65B0",
|
|
230
|
-
description: String(result.hint ?? ""),
|
|
231
|
-
input: false,
|
|
232
|
-
confirmLabel: "\u77E5\u9053\u4E86",
|
|
233
|
-
action: async () => void 0
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
if (result?.status === "unavailable") {
|
|
239
|
-
setSelfUpdate({ phase: "idle" });
|
|
240
|
-
if (manual) setError(`\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF1A${result.reason || result.problem || "\u672A\u77E5\u539F\u56E0"}`);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
293
|
+
lastSelfCheckAt = Date.now();
|
|
294
|
+
const result = await fetchSelfUpdateInfo();
|
|
295
|
+
if (!result) {
|
|
243
296
|
setSelfUpdate({ phase: "idle" });
|
|
244
|
-
if (manual)
|
|
245
|
-
|
|
297
|
+
if (manual) setError("\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (result.status === "available" && result.latest) {
|
|
301
|
+
setSelfUpdate({ phase: "available", to: result.latest });
|
|
302
|
+
if (manual) setNotice(`\u53D1\u73B0\u65B0\u7248\u672C v${result.latest}`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (result.status === "not-updatable") {
|
|
306
|
+
setSelfUpdate({ phase: "idle" });
|
|
307
|
+
if (manual) {
|
|
308
|
+
setDialog({
|
|
309
|
+
title: "\u5F53\u524D\u5B89\u88C5\u65B9\u5F0F\u4E0D\u652F\u6301\u81EA\u66F4\u65B0",
|
|
310
|
+
description: String(result.hint ?? ""),
|
|
311
|
+
input: false,
|
|
312
|
+
confirmLabel: "\u77E5\u9053\u4E86",
|
|
313
|
+
action: async () => void 0
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (result.status === "unavailable") {
|
|
246
319
|
setSelfUpdate({ phase: "idle" });
|
|
247
|
-
if (manual) setError(
|
|
320
|
+
if (manual) setError(`\u68C0\u67E5\u66F4\u65B0\u5931\u8D25\uFF1A${result.reason || result.problem || "\u672A\u77E5\u539F\u56E0"}`);
|
|
321
|
+
return;
|
|
248
322
|
}
|
|
323
|
+
setSelfUpdate({ phase: "idle" });
|
|
324
|
+
if (manual) setNotice("\u63D2\u4EF6\u4E2D\u5FC3\u5DF2\u662F\u6700\u65B0\u7248\u672C");
|
|
249
325
|
}
|
|
250
326
|
async function pollSelfUpdate(version) {
|
|
251
327
|
if (selfUpdatePolling) return;
|
|
@@ -267,6 +343,7 @@ function Panel() {
|
|
|
267
343
|
if (next.self?.version === version || next.self?.installedVersion === version) {
|
|
268
344
|
selfUpdateTarget = null;
|
|
269
345
|
selfUpdateNotified = true;
|
|
346
|
+
publishSelfUpdate({ latest: null, checkedAt: Date.now() });
|
|
270
347
|
if (record?.application === "restart-required" || next.self?.version !== version) {
|
|
271
348
|
setSelfUpdate({ phase: "restart", to: version });
|
|
272
349
|
return;
|
|
@@ -329,8 +406,7 @@ function Panel() {
|
|
|
329
406
|
void pollSelfUpdate(selfUpdateTarget);
|
|
330
407
|
return;
|
|
331
408
|
}
|
|
332
|
-
if (Date.now() - lastSelfCheckAt <
|
|
333
|
-
lastSelfCheckAt = Date.now();
|
|
409
|
+
if (Date.now() - Math.max(lastSelfCheckAt, selfUpdateInfo.checkedAt) < 30 * 1e3) return;
|
|
334
410
|
void checkSelfUpdate(false);
|
|
335
411
|
}, [ready]);
|
|
336
412
|
(0, import_react.useEffect)(() => {
|
|
@@ -2520,6 +2596,22 @@ var CSS = `
|
|
|
2520
2596
|
}
|
|
2521
2597
|
.pcx-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
|
2522
2598
|
.pcx-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
|
2599
|
+
.pcx-sidebar-icon {
|
|
2600
|
+
position: relative;
|
|
2601
|
+
display: inline-flex;
|
|
2602
|
+
align-items: center;
|
|
2603
|
+
justify-content: center;
|
|
2604
|
+
}
|
|
2605
|
+
.pcx-sidebar-dot {
|
|
2606
|
+
position: absolute;
|
|
2607
|
+
top: -1px;
|
|
2608
|
+
right: -2px;
|
|
2609
|
+
width: 7px;
|
|
2610
|
+
height: 7px;
|
|
2611
|
+
border-radius: 50%;
|
|
2612
|
+
background: var(--dsw-alias-state-business-primary, #1f6feb);
|
|
2613
|
+
box-shadow: 0 0 0 1.5px var(--dsw-specific-sidebar-fill, #fff);
|
|
2614
|
+
}
|
|
2523
2615
|
.pcx-logo {
|
|
2524
2616
|
width: 28px; height: 28px; border-radius: 8px; flex: none;
|
|
2525
2617
|
display: grid; place-items: center;
|