@dshtrading/client-ui-updater 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ Copyright (c) 2026 zhu1090093659 (dsh-trading)
2
+
3
+ # PolyForm Noncommercial License 1.0.0
4
+
5
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncommercial Purposes
34
+
35
+ Any noncommercial purpose is a permitted purpose.
36
+
37
+ ## Personal Uses
38
+
39
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
40
+
41
+ ## Noncommercial Organizations
42
+
43
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
44
+
45
+ ## Fair Use
46
+
47
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
48
+
49
+ ## No Other Rights
50
+
51
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
52
+
53
+ ## Patent Defense
54
+
55
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
56
+
57
+ ## Violations
58
+
59
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
60
+
61
+ ## No Liability
62
+
63
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
64
+
65
+ ## Definitions
66
+
67
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
68
+
69
+ **You** refers to the individual or entity agreeing to these terms.
70
+
71
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
72
+
73
+ **Your licenses** are all the licenses granted to you for the software under these terms.
74
+
75
+ **Use** means anything you do with the software requiring one of your licenses.
@@ -0,0 +1,15 @@
1
+ //#region src/client/contract.d.ts
2
+ /**
3
+ * Locale contract for the updater settings section. The zh dictionary in
4
+ * locales.ts is the key source of truth; this union + the LocaleNamespaceMap
5
+ * merge give the framework-injected t seat its key types.
6
+ */
7
+ type UpdaterLocaleKey = 'nav' | 'lead' | 'currentVersion' | 'desktopApp' | 'unsupported' | 'viewReleases' | 'checkNow' | 'checking' | 'lastCheck' | 'never' | 'upToDate' | 'available' | 'publishedAt' | 'notesTitle' | 'applyNow' | 'payloadMissing' | 'phase.prepare' | 'phase.download' | 'phase.verify' | 'phase.install' | 'progress' | 'done' | 'restartHint' | 'restartNow' | 'restartManual' | 'checkError' | 'retry';
8
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
9
+ interface LocaleNamespaceMap {
10
+ /** Updater settings section copy (check / notes / incremental apply). */
11
+ 'dshtrading.updater': UpdaterLocaleKey;
12
+ }
13
+ }
14
+ //#endregion
15
+ export { UpdaterLocaleKey };
@@ -0,0 +1,6 @@
1
+ import { UpdaterLocaleKey } from "./contract.js";
2
+ //#region src/client/locales.d.ts
3
+ declare const zh: Record<UpdaterLocaleKey, string>;
4
+ declare const en: Record<UpdaterLocaleKey, string>;
5
+ //#endregion
6
+ export { en, zh };
@@ -0,0 +1,61 @@
1
+ //#region src/client/locales.ts
2
+ const zh = {
3
+ nav: "软件更新",
4
+ lead: "检测 GitHub Releases 上的新版本,增量更新只下载变动的交易插件包,无需重装应用。",
5
+ currentVersion: "交易插件版本",
6
+ desktopApp: "桌面应用版本",
7
+ unsupported: "当前环境不支持自动增量更新(仅 DSH Trading 桌面版支持)。可以前往发布页手动下载完整安装包。",
8
+ viewReleases: "在 GitHub 查看发布",
9
+ checkNow: "检查更新",
10
+ checking: "正在检查…",
11
+ lastCheck: "上次检查",
12
+ never: "尚未检查",
13
+ upToDate: "已是最新版本。",
14
+ available: "发现新版本 {version}",
15
+ publishedAt: "发布于 {date}",
16
+ notesTitle: "更新说明",
17
+ applyNow: "立即更新",
18
+ payloadMissing: "该版本未附带增量更新包,请前往发布页下载完整安装包。",
19
+ "phase.prepare": "正在准备…",
20
+ "phase.download": "正在下载增量包…",
21
+ "phase.verify": "正在校验增量包…",
22
+ "phase.install": "正在安装更新…",
23
+ progress: "{percent}%",
24
+ done: "已更新到 {version}",
25
+ restartHint: "重启 DSH Trading 后生效。",
26
+ restartNow: "重启应用",
27
+ restartManual: "请手动重启 DSH Trading 以完成更新。",
28
+ checkError: "检查失败:{message}",
29
+ retry: "重试"
30
+ };
31
+ const en = {
32
+ nav: "Software updates",
33
+ lead: "Detects new versions published on GitHub Releases and applies incremental updates — only the changed trading plugin packages are downloaded, no reinstall needed.",
34
+ currentVersion: "Trading plugins",
35
+ desktopApp: "Desktop app",
36
+ unsupported: "Incremental updates are only available inside the DSH Trading desktop app. You can download a full installer from the releases page.",
37
+ viewReleases: "View releases on GitHub",
38
+ checkNow: "Check for updates",
39
+ checking: "Checking…",
40
+ lastCheck: "Last checked",
41
+ never: "Never checked",
42
+ upToDate: "You are up to date.",
43
+ available: "New version {version} available",
44
+ publishedAt: "Published {date}",
45
+ notesTitle: "Release notes",
46
+ applyNow: "Update now",
47
+ payloadMissing: "This release does not carry the incremental update payload. Please download a full installer from the releases page.",
48
+ "phase.prepare": "Preparing…",
49
+ "phase.download": "Downloading update payload…",
50
+ "phase.verify": "Verifying update payload…",
51
+ "phase.install": "Installing update…",
52
+ progress: "{percent}%",
53
+ done: "Updated to {version}",
54
+ restartHint: "Restart DSH Trading to activate.",
55
+ restartNow: "Restart app",
56
+ restartManual: "Please restart DSH Trading manually to finish the update.",
57
+ checkError: "Check failed: {message}",
58
+ retry: "Retry"
59
+ };
60
+ //#endregion
61
+ export { en, zh };
package/lib/client.js ADDED
@@ -0,0 +1,465 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@dshtrading/client-ui-updater",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region src/client/locales.ts
10
+ const zh = {
11
+ nav: "软件更新",
12
+ lead: "检测 GitHub Releases 上的新版本,增量更新只下载变动的交易插件包,无需重装应用。",
13
+ currentVersion: "交易插件版本",
14
+ desktopApp: "桌面应用版本",
15
+ unsupported: "当前环境不支持自动增量更新(仅 DSH Trading 桌面版支持)。可以前往发布页手动下载完整安装包。",
16
+ viewReleases: "在 GitHub 查看发布",
17
+ checkNow: "检查更新",
18
+ checking: "正在检查…",
19
+ lastCheck: "上次检查",
20
+ never: "尚未检查",
21
+ upToDate: "已是最新版本。",
22
+ available: "发现新版本 {version}",
23
+ publishedAt: "发布于 {date}",
24
+ notesTitle: "更新说明",
25
+ applyNow: "立即更新",
26
+ payloadMissing: "该版本未附带增量更新包,请前往发布页下载完整安装包。",
27
+ "phase.prepare": "正在准备…",
28
+ "phase.download": "正在下载增量包…",
29
+ "phase.verify": "正在校验增量包…",
30
+ "phase.install": "正在安装更新…",
31
+ progress: "{percent}%",
32
+ done: "已更新到 {version}",
33
+ restartHint: "重启 DSH Trading 后生效。",
34
+ restartNow: "重启应用",
35
+ restartManual: "请手动重启 DSH Trading 以完成更新。",
36
+ checkError: "检查失败:{message}",
37
+ retry: "重试"
38
+ };
39
+ const en = {
40
+ nav: "Software updates",
41
+ lead: "Detects new versions published on GitHub Releases and applies incremental updates — only the changed trading plugin packages are downloaded, no reinstall needed.",
42
+ currentVersion: "Trading plugins",
43
+ desktopApp: "Desktop app",
44
+ unsupported: "Incremental updates are only available inside the DSH Trading desktop app. You can download a full installer from the releases page.",
45
+ viewReleases: "View releases on GitHub",
46
+ checkNow: "Check for updates",
47
+ checking: "Checking…",
48
+ lastCheck: "Last checked",
49
+ never: "Never checked",
50
+ upToDate: "You are up to date.",
51
+ available: "New version {version} available",
52
+ publishedAt: "Published {date}",
53
+ notesTitle: "Release notes",
54
+ applyNow: "Update now",
55
+ payloadMissing: "This release does not carry the incremental update payload. Please download a full installer from the releases page.",
56
+ "phase.prepare": "Preparing…",
57
+ "phase.download": "Downloading update payload…",
58
+ "phase.verify": "Verifying update payload…",
59
+ "phase.install": "Installing update…",
60
+ progress: "{percent}%",
61
+ done: "Updated to {version}",
62
+ restartHint: "Restart DSH Trading to activate.",
63
+ restartNow: "Restart app",
64
+ restartManual: "Please restart DSH Trading manually to finish the update.",
65
+ checkError: "Check failed: {message}",
66
+ retry: "Retry"
67
+ };
68
+ //#endregion
69
+ //#region src/client/api.ts
70
+ var UpdaterBridgeError = class extends Error {
71
+ status;
72
+ code;
73
+ constructor(status, message, code) {
74
+ super(message);
75
+ this.status = status;
76
+ this.code = code;
77
+ }
78
+ };
79
+ async function updaterJson(path, init) {
80
+ const response = await fetch(path, init);
81
+ if (!response.ok) {
82
+ const body = await response.json().catch(() => void 0);
83
+ const detail = typeof body?.message === "string" && body.message !== "" ? ": " + body.message : "";
84
+ throw new UpdaterBridgeError(response.status, "updater " + path + " failed: " + String(response.status) + detail, body?.code);
85
+ }
86
+ const wire = await response.json();
87
+ if (wire !== null && typeof wire === "object" && wire.ok === false) {
88
+ const business = wire;
89
+ throw new UpdaterBridgeError(200, (business.code ?? "UPDATER_UNKNOWN") + ": " + (business.message ?? "updater bridge error"), business.code);
90
+ }
91
+ return wire;
92
+ }
93
+ /** Current updater snapshot (environment + check + apply state). */
94
+ async function fetchUpdaterState() {
95
+ return updaterJson("/dshtrading/api/updater/state", { headers: { accept: "application/json" } });
96
+ }
97
+ /** Run a GitHub release check; force=true bypasses the host-side TTL cache. */
98
+ async function requestUpdaterCheck(force) {
99
+ return updaterJson(`/dshtrading/api/updater/check?force=${force ? "1" : "0"}`, { headers: { accept: "application/json" } });
100
+ }
101
+ /** Start the incremental apply pipeline; returns the running snapshot. */
102
+ async function requestUpdaterApply() {
103
+ return updaterJson("/dshtrading/api/updater/apply", {
104
+ method: "POST",
105
+ headers: { "content-type": "application/json" },
106
+ body: "{}"
107
+ });
108
+ }
109
+ /** Resolve the desktop shell bridge, if this page runs inside DSH Trading. */
110
+ function desktopBridge() {
111
+ if (typeof window === "undefined" || !("desktop" in window)) return void 0;
112
+ return window.desktop;
113
+ }
114
+ //#endregion
115
+ //#region src/client/contract.ts
116
+ /**
117
+ * Window event contract with the trading shell rail (client-ui-trading
118
+ * SessionRail badge). Cross-plugin coupling is intentionally a DOM custom
119
+ * event, not an import (client plugins never import each other's modules).
120
+ * Detail: { available: boolean, version?: string }.
121
+ */
122
+ const UPDATE_AVAILABLE_EVENT = "dshtrading-update-available";
123
+ //#endregion
124
+ //#region \0dsh-css:/home/runner/work/dsh-trading/dsh-trading/packages/client-ui-updater/src/client/updater-section.module.css.mjs
125
+ const css = ".D0_G6G_root{--upd-text-primary:var(--dsw-alias-text-primary,#1a1e24);--upd-text-secondary:var(--dsw-alias-text-secondary,#5f6672);--upd-text-muted:var(--dsw-alias-text-muted,#8e95a3);--upd-border:var(--dsw-alias-border-l2,#e3e6ea);--upd-bg-hover:var(--dsw-alias-fill-hover,#0000000a);--upd-bg-active:var(--dsw-alias-primary-bg,#2563eb0f);--upd-primary:var(--dsw-alias-primary,#2563eb);--upd-ok:#16a34a;--upd-danger:#dc2626;color:var(--upd-text-primary);flex-direction:column;gap:16px;padding:4px 0 24px;font-size:13px;display:flex}body[data-ds-dark-theme] .D0_G6G_root,[data-theme=dark] .D0_G6G_root,:root[data-theme=dark] .D0_G6G_root,html.dark .D0_G6G_root,body.dark .D0_G6G_root{--upd-text-primary:var(--dsw-alias-text-primary,#f3f4f6);--upd-text-secondary:var(--dsw-alias-text-secondary,#9ca3af);--upd-text-muted:var(--dsw-alias-text-muted,#6b7280);--upd-border:var(--dsw-alias-border-l2,#ffffff1a);--upd-bg-hover:var(--dsw-alias-fill-hover,#ffffff0f);--upd-bg-active:#2563eb29;--upd-primary:#3b82f6;--upd-ok:#4ade80;--upd-danger:#f87171}.D0_G6G_lead{color:var(--upd-text-secondary);margin:0;font-size:13.5px;line-height:1.6}.D0_G6G_versions{border:1px solid var(--upd-border);background:var(--upd-bg-hover);border-radius:8px;flex-wrap:wrap;gap:6px 24px;padding:10px 12px;display:flex}.D0_G6G_versionItem{flex-direction:column;gap:2px;display:flex}.D0_G6G_versionLabel{color:var(--upd-text-muted);font-size:11.5px}.D0_G6G_versionValue{font-variant-numeric:tabular-nums;font-size:13px;font-weight:600}.D0_G6G_statusRow{flex-wrap:wrap;align-items:center;gap:12px;display:flex}.D0_G6G_statusText{color:var(--upd-text-secondary)}.D0_G6G_statusTextOk{color:var(--upd-ok)}.D0_G6G_statusTextAvailable{color:var(--upd-primary);font-weight:600}.D0_G6G_statusTextError{color:var(--upd-danger)}.D0_G6G_availableCard{border:1px solid var(--upd-primary);background:var(--upd-bg-active);border-radius:8px;flex-direction:column;gap:10px;padding:14px;display:flex}.D0_G6G_availableTitle{color:var(--upd-primary);margin:0;font-size:14px;font-weight:600}.D0_G6G_availableMeta{color:var(--upd-text-muted);margin:0;font-size:12px}.D0_G6G_notesTitle{color:var(--upd-text-secondary);margin:0;font-size:12.5px;font-weight:600}.D0_G6G_notes{border:1px solid var(--upd-border);background:var(--upd-bg-hover);color:var(--upd-text-secondary);white-space:pre-wrap;word-break:break-word;border-radius:6px;max-height:260px;margin:0;padding:10px 12px;font-family:inherit;font-size:12.5px;line-height:1.6;overflow:auto}.D0_G6G_actions{flex-wrap:wrap;align-items:center;gap:10px;display:flex}.D0_G6G_primaryButton{appearance:none;background:var(--upd-primary);color:#fff;cursor:pointer;border:none;border-radius:6px;padding:7px 16px;font-size:13px;font-weight:500}.D0_G6G_primaryButton:hover{filter:brightness(1.08)}.D0_G6G_primaryButton:disabled{opacity:.55;cursor:default;filter:none}.D0_G6G_secondaryButton{appearance:none;border:1px solid var(--upd-border);color:var(--upd-text-secondary);cursor:pointer;background:0 0;border-radius:6px;padding:6px 14px;font-size:13px}.D0_G6G_secondaryButton:hover{background:var(--upd-bg-hover)}.D0_G6G_secondaryButton:disabled{opacity:.55;cursor:default}.D0_G6G_link{color:var(--upd-primary);font-size:12.5px;text-decoration:none}.D0_G6G_link:hover{text-decoration:underline}.D0_G6G_progressWrap{flex-direction:column;gap:6px;display:flex}.D0_G6G_progressLabel{color:var(--upd-text-secondary);justify-content:space-between;font-size:12.5px;display:flex}.D0_G6G_progressTrack{background:var(--upd-bg-hover);border:1px solid var(--upd-border);border-radius:3px;height:6px;overflow:hidden}.D0_G6G_progressFill{background:var(--upd-primary);border-radius:3px;height:100%;transition:width .24s}.D0_G6G_progressIndeterminate{width:40%;animation:1.1s ease-in-out infinite alternate D0_G6G_upd-slide}@keyframes D0_G6G_upd-slide{0%{margin-left:0}to{margin-left:60%}}.D0_G6G_doneCard{border:1px solid var(--upd-ok);border-radius:8px;flex-direction:column;gap:8px;padding:14px;display:flex}.D0_G6G_doneTitle{color:var(--upd-ok);margin:0;font-size:14px;font-weight:600}.D0_G6G_doneMeta{color:var(--upd-text-secondary);margin:0;font-size:12.5px}.D0_G6G_errorText{color:var(--upd-danger);word-break:break-word;margin:0;font-size:12.5px}";
126
+ const tagId = "@dshtrading/client-ui-updater/updater-section.module.css";
127
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
128
+ const tag = document.createElement("style");
129
+ tag.dataset.plugin = "@dshtrading/client-ui-updater";
130
+ tag.dataset.pluginCss = tagId;
131
+ tag.textContent = css;
132
+ document.head.appendChild(tag);
133
+ }
134
+ var updater_section_module_css_default = {
135
+ "notes": "D0_G6G_notes",
136
+ "upd-slide": "D0_G6G_upd-slide",
137
+ "statusTextError": "D0_G6G_statusTextError",
138
+ "versionItem": "D0_G6G_versionItem",
139
+ "progressLabel": "D0_G6G_progressLabel",
140
+ "lead": "D0_G6G_lead",
141
+ "versionValue": "D0_G6G_versionValue",
142
+ "availableTitle": "D0_G6G_availableTitle",
143
+ "doneCard": "D0_G6G_doneCard",
144
+ "errorText": "D0_G6G_errorText",
145
+ "availableCard": "D0_G6G_availableCard",
146
+ "versions": "D0_G6G_versions",
147
+ "doneMeta": "D0_G6G_doneMeta",
148
+ "primaryButton": "D0_G6G_primaryButton",
149
+ "statusTextOk": "D0_G6G_statusTextOk",
150
+ "statusTextAvailable": "D0_G6G_statusTextAvailable",
151
+ "actions": "D0_G6G_actions",
152
+ "availableMeta": "D0_G6G_availableMeta",
153
+ "progressWrap": "D0_G6G_progressWrap",
154
+ "doneTitle": "D0_G6G_doneTitle",
155
+ "secondaryButton": "D0_G6G_secondaryButton",
156
+ "versionLabel": "D0_G6G_versionLabel",
157
+ "link": "D0_G6G_link",
158
+ "statusText": "D0_G6G_statusText",
159
+ "progressIndeterminate": "D0_G6G_progressIndeterminate",
160
+ "notesTitle": "D0_G6G_notesTitle",
161
+ "progressFill": "D0_G6G_progressFill",
162
+ "progressTrack": "D0_G6G_progressTrack",
163
+ "statusRow": "D0_G6G_statusRow",
164
+ "root": "D0_G6G_root"
165
+ };
166
+ //#endregion
167
+ //#region src/client/UpdaterSection.tsx
168
+ /**
169
+ * Software-update settings page (the first-level section registered by this
170
+ * plugin). Pure view over /dshtrading/api/updater: renders the current
171
+ * versions, the latest GitHub release with its notes, and drives the
172
+ * incremental apply + restart flow. Polls the host snapshot while mounted
173
+ * (faster while an apply is running); no SSE dependency.
174
+ */
175
+ /** Poll cadences: lazy when idle, tight while an apply pipeline is running. */
176
+ const POLL_IDLE_MS = 3e4;
177
+ const POLL_RUNNING_MS = 1200;
178
+ /** ISO date (yyyy-mm-dd) for the published line; empty when unknown. */
179
+ function formatDay(iso) {
180
+ if (iso === void 0) return "";
181
+ const parsed = new Date(iso);
182
+ if (Number.isNaN(parsed.getTime())) return "";
183
+ return parsed.toISOString().slice(0, 10);
184
+ }
185
+ function UpdaterSection({ t }) {
186
+ const [state, setState] = (0, react.useState)(void 0);
187
+ const [actionError, setActionError] = (0, react.useState)(void 0);
188
+ const [checkBusy, setCheckBusy] = (0, react.useState)(false);
189
+ const applyBusyRef = (0, react.useRef)(false);
190
+ const running = state?.apply.phase === "running";
191
+ const refresh = (0, react.useCallback)(async () => {
192
+ try {
193
+ setState(await fetchUpdaterState());
194
+ } catch {}
195
+ }, []);
196
+ (0, react.useEffect)(() => {
197
+ refresh();
198
+ }, [refresh]);
199
+ (0, react.useEffect)(() => {
200
+ const interval = setInterval(() => {
201
+ refresh();
202
+ }, running ? POLL_RUNNING_MS : POLL_IDLE_MS);
203
+ return () => {
204
+ clearInterval(interval);
205
+ };
206
+ }, [refresh, running]);
207
+ (0, react.useEffect)(() => {
208
+ if (state === void 0) return;
209
+ const available = state.check.available === true && state.apply.phase !== "done";
210
+ window.dispatchEvent(new CustomEvent(UPDATE_AVAILABLE_EVENT, { detail: {
211
+ available,
212
+ version: state.check.latest?.version
213
+ } }));
214
+ }, [state]);
215
+ const handleCheck = async () => {
216
+ setCheckBusy(true);
217
+ setActionError(void 0);
218
+ try {
219
+ setState(await requestUpdaterCheck(true));
220
+ } catch (error) {
221
+ setActionError(error instanceof Error ? error.message : String(error));
222
+ } finally {
223
+ setCheckBusy(false);
224
+ }
225
+ };
226
+ const handleApply = async () => {
227
+ if (applyBusyRef.current) return;
228
+ applyBusyRef.current = true;
229
+ setActionError(void 0);
230
+ try {
231
+ setState(await requestUpdaterApply());
232
+ refresh();
233
+ } catch (error) {
234
+ setActionError(error instanceof Error ? error.message : String(error));
235
+ } finally {
236
+ applyBusyRef.current = false;
237
+ }
238
+ };
239
+ const handleRestart = () => {
240
+ desktopBridge()?.relaunch?.();
241
+ };
242
+ const environment = state?.environment;
243
+ const check = state?.check;
244
+ const apply = state?.apply;
245
+ const progress = state?.progress;
246
+ const latest = check?.latest;
247
+ const releasesUrl = latest?.url ?? "https://github.com/zhu1090093659/dsh-trading/releases";
248
+ const publishedDay = formatDay(latest?.publishedAt);
249
+ const hasUpdate = check?.available === true && apply?.phase !== "done";
250
+ hasUpdate && latest?.payloadAvailable;
251
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
252
+ className: updater_section_module_css_default.root,
253
+ children: [
254
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
255
+ className: updater_section_module_css_default.lead,
256
+ children: t("lead")
257
+ }),
258
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
259
+ className: updater_section_module_css_default.versions,
260
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
261
+ className: updater_section_module_css_default.versionItem,
262
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
263
+ className: updater_section_module_css_default.versionLabel,
264
+ children: t("currentVersion")
265
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
266
+ className: updater_section_module_css_default.versionValue,
267
+ children: environment?.familyVersion ?? "—"
268
+ })]
269
+ }), environment?.appVersion !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
270
+ className: updater_section_module_css_default.versionItem,
271
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
272
+ className: updater_section_module_css_default.versionLabel,
273
+ children: t("desktopApp")
274
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
275
+ className: updater_section_module_css_default.versionValue,
276
+ children: environment.appVersion
277
+ })]
278
+ })]
279
+ }),
280
+ environment !== void 0 && !environment.supported && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
281
+ className: updater_section_module_css_default.statusText,
282
+ children: t("unsupported")
283
+ }),
284
+ environment?.supported === true && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
285
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
286
+ className: updater_section_module_css_default.statusRow,
287
+ children: [
288
+ check?.status === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
289
+ className: `${updater_section_module_css_default.statusText} ${updater_section_module_css_default.statusTextError}`,
290
+ children: t("checkError", { message: check.error ?? "" })
291
+ }),
292
+ check?.status === "ok" && !hasUpdate && apply?.phase !== "done" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
293
+ className: `${updater_section_module_css_default.statusText} ${updater_section_module_css_default.statusTextOk}`,
294
+ children: t("upToDate")
295
+ }),
296
+ check?.at !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
297
+ className: updater_section_module_css_default.statusText,
298
+ children: [
299
+ t("lastCheck"),
300
+ ":",
301
+ " ",
302
+ check.at.slice(0, 19).replace("T", " ")
303
+ ]
304
+ }),
305
+ check?.at === void 0 && check?.status !== "ok" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
306
+ className: updater_section_module_css_default.statusText,
307
+ children: t("never")
308
+ }),
309
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
310
+ type: "button",
311
+ className: updater_section_module_css_default.secondaryButton,
312
+ disabled: checkBusy || running,
313
+ onClick: () => {
314
+ handleCheck();
315
+ },
316
+ children: checkBusy ? t("checking") : t("checkNow")
317
+ }),
318
+ actionError !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
319
+ type: "button",
320
+ className: updater_section_module_css_default.secondaryButton,
321
+ onClick: () => {
322
+ handleCheck();
323
+ },
324
+ children: t("retry")
325
+ })
326
+ ]
327
+ }),
328
+ running && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
329
+ className: updater_section_module_css_default.progressWrap,
330
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
331
+ className: updater_section_module_css_default.progressLabel,
332
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: progress?.step === "download" ? t("phase.download") : progress?.step === "verify" ? t("phase.verify") : progress?.step === "install" ? t("phase.install") : t("phase.prepare") }), progress?.percent !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("progress", { percent: progress.percent }) })]
333
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
334
+ className: updater_section_module_css_default.progressTrack,
335
+ role: "progressbar",
336
+ "aria-valuemin": 0,
337
+ "aria-valuemax": 100,
338
+ "aria-valuenow": progress?.percent ?? void 0,
339
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
340
+ className: `${updater_section_module_css_default.progressFill} ${progress?.percent === void 0 ? updater_section_module_css_default.progressIndeterminate : ""}`,
341
+ style: progress?.percent === void 0 ? void 0 : { width: `${progress.percent}%` }
342
+ })
343
+ })]
344
+ }),
345
+ hasUpdate && latest !== void 0 && !running && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
346
+ className: updater_section_module_css_default.availableCard,
347
+ children: [
348
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
349
+ className: updater_section_module_css_default.availableTitle,
350
+ children: t("available", { version: latest.version })
351
+ }),
352
+ publishedDay !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
353
+ className: updater_section_module_css_default.availableMeta,
354
+ children: t("publishedAt", { date: publishedDay })
355
+ }),
356
+ latest.notes.trim() !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
357
+ className: updater_section_module_css_default.notesTitle,
358
+ children: t("notesTitle")
359
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
360
+ className: updater_section_module_css_default.notes,
361
+ children: latest.notes
362
+ })] }),
363
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
364
+ className: updater_section_module_css_default.actions,
365
+ children: [latest.payloadAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
366
+ type: "button",
367
+ className: updater_section_module_css_default.primaryButton,
368
+ onClick: () => {
369
+ handleApply();
370
+ },
371
+ children: t("applyNow")
372
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
373
+ className: updater_section_module_css_default.link,
374
+ href: releasesUrl,
375
+ target: "_blank",
376
+ rel: "noreferrer",
377
+ children: t("viewReleases")
378
+ })]
379
+ }),
380
+ !latest.payloadAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
381
+ className: updater_section_module_css_default.doneMeta,
382
+ children: t("payloadMissing")
383
+ })
384
+ ]
385
+ }),
386
+ apply?.phase === "done" && apply.targetVersion !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
387
+ className: updater_section_module_css_default.doneCard,
388
+ children: [
389
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
390
+ className: updater_section_module_css_default.doneTitle,
391
+ children: t("done", { version: apply.targetVersion })
392
+ }),
393
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
394
+ className: updater_section_module_css_default.doneMeta,
395
+ children: t("restartHint")
396
+ }),
397
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
398
+ className: updater_section_module_css_default.actions,
399
+ children: [
400
+ desktopBridge()?.relaunch !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
401
+ type: "button",
402
+ className: updater_section_module_css_default.primaryButton,
403
+ onClick: handleRestart,
404
+ children: t("restartNow")
405
+ }),
406
+ desktopBridge()?.relaunch === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
407
+ className: updater_section_module_css_default.doneMeta,
408
+ children: t("restartManual")
409
+ }),
410
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
411
+ className: updater_section_module_css_default.link,
412
+ href: releasesUrl,
413
+ target: "_blank",
414
+ rel: "noreferrer",
415
+ children: t("viewReleases")
416
+ })
417
+ ]
418
+ })
419
+ ]
420
+ }),
421
+ apply?.phase === "error" && apply.error !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
422
+ className: updater_section_module_css_default.errorText,
423
+ children: apply.error
424
+ })
425
+ ] }),
426
+ environment === void 0 || !environment.supported ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
427
+ className: updater_section_module_css_default.link,
428
+ href: releasesUrl,
429
+ target: "_blank",
430
+ rel: "noreferrer",
431
+ children: t("viewReleases")
432
+ }) : null
433
+ ]
434
+ });
435
+ }
436
+ //#endregion
437
+ //#region src/client/index.ts
438
+ /** 本面板/字符串翻译的 locale namespace。 */
439
+ const NS = "dshtrading.updater";
440
+ /** Required services (cordis fiber inject). */
441
+ const inject = ["slots", "locale"];
442
+ /** 注册『软件更新』设置一级菜单。 */
443
+ function apply(ctx) {
444
+ const t = ctx.locale.bind(NS);
445
+ ctx.effect(() => ctx.locale.register(NS, {
446
+ zh,
447
+ en
448
+ }), "dsh-trading-updater: dictionaries");
449
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
450
+ name: "settings.section",
451
+ id: "updater",
452
+ order: 20,
453
+ label: () => t("nav"),
454
+ locale: NS
455
+ }, UpdaterSection));
456
+ }
457
+ //#endregion
458
+ exports.UPDATE_AVAILABLE_EVENT = UPDATE_AVAILABLE_EVENT;
459
+ exports.apply = apply;
460
+ exports.inject = inject;
461
+ return module.exports;
462
+ }
463
+ });
464
+
465
+ //# sourceMappingURL=client.js.map