dsh-cloud-backup 0.0.0-stage → 0.1.138

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/client.js ADDED
@@ -0,0 +1,3060 @@
1
+ // dsh-cloud-backup 前端:设置页「云盘备份」分区(授权 / 自动备份 / 快照列表 / 还原)。
2
+ window.__ModuleLoader__.load({
3
+ id: "dsh-cloud-backup",
4
+ factory: (require) => {
5
+ var module = { exports: {} };
6
+ var exports = module.exports;
7
+
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ // react-dom 只用于 createPortal(弹窗挂到 body,避免被卡片滚动容器裁剪)
11
+ let react_dom = null;
12
+ try { react_dom = require("react-dom"); } catch (e) { react_dom = null; }
13
+
14
+ const NS = "dsh-cloud-backup";
15
+ const API = "/api/dsh-cloud-backup";
16
+ const POLL_MS = 2000;
17
+
18
+ // 云端读取失败要多快才提示:登录 / 续期刚起步的几秒不打扰用户
19
+ // 能被用例用 __DSHCB_GRACE_MS 覆盖(浏览器里没有这个全局,仍是 6 秒)
20
+ const CLOUD_GRACE_MS = (function () {
21
+ const g = (typeof globalThis !== "undefined") ? globalThis.__DSHCB_GRACE_MS : undefined;
22
+ const v = (g === undefined || g === null) ? NaN : Number(g);
23
+ return Number.isFinite(v) && v >= 0 ? v : 6000;
24
+ })();
25
+
26
+ // 列表上方消息层的自隐时长:纯通知(没有操作按钮)3 秒后消失,带操作的一直留到用户处理
27
+ // 能被用例用 __DSHCB_LANE_TTL_MS 覆盖
28
+ const LANE_TTL_MS = (function () {
29
+ const g = (typeof globalThis !== "undefined") ? globalThis.__DSHCB_LANE_TTL_MS : undefined;
30
+ const v = (g === undefined || g === null) ? NaN : Number(g);
31
+ return Number.isFinite(v) && v >= 0 ? v : 3000;
32
+ })();
33
+
34
+ const DICT = {
35
+ zh: {
36
+ more: "更多",
37
+ secAuth: "授权信息",
38
+ secRecent: "最近备份",
39
+ schedOffShort: "关闭",
40
+ schedOnShort: "开启",
41
+ schedOnLine: "自动备份已开启,",
42
+ schedNextLine: "下次自动备份时间",
43
+ selIdNone: "尚未选择快照(点列表中的任意一份)",
44
+ listRefreshed: "列表已刷新",
45
+ recentInfoTip: "为什么每行的按钮不一样:已上传且本地有缓存 → 只有「删除」;待上传(仅本地)→「上传」把这份送到云盘;已上传但本地无缓存 →「下载」把云端那份取回本地;云端未同步 →「重试」重新读取该份状态。",
46
+ dlgCopy: "复制",
47
+ promptTitle: "插件还原提示词",
48
+ promptLead: "把下面这段整段复制,粘贴给任意 agent(或用命令行自己执行)即可把插件本体装回来。",
49
+ promptCopied: "提示词已复制到剪贴板",
50
+ batchOp: "批量操作",
51
+ batchCancel: "取消",
52
+ batchCount: "已选 {n} 项 · 共 {mb}",
53
+ batchNone: "未选择任何快照",
54
+ batchDeleteBtn: "删除选中",
55
+ batchTitle: "删除 {n} 份快照?",
56
+ batchLead: "云端会移到回收站(可在阿里云盘回收站找回 30 天),本机缓存一并清除。",
57
+ batchLast: "其中 {n} 份是云端最后一份快照(删除后云端将没有任何备份)—— 仍要继续?",
58
+ batchDeleting: "正在删除 {i} / {n} …",
59
+ batchDone: "已删除 {n} 份",
60
+ batchFailStop: "第 {i} 份失败,已停止:{err}",
61
+ selId: "已选还原文件快照ID:",
62
+ snapWord: "快照",
63
+ nav: "云盘备份",
64
+ title: "云盘备份",
65
+ subtitle: "把 DSH 会话与配置按内容去重后备份到免费云盘(阿里云盘首发)",
66
+ loading: "读取状态中…",
67
+ phaseLoading: "读取中",
68
+ rowConnect: "连接状态",
69
+ rowAccount: "账号",
70
+ rowDrive: "云盘",
71
+ rowFolder: "云盘目录",
72
+ rowRefresh: "自动续期",
73
+ renewOn: "开启",
74
+ rowStateDir: "状态目录",
75
+ rowCrypto: "凭据加密",
76
+ connected: "已连接",
77
+ notConnected: "未连接",
78
+ connect: "连接阿里云盘",
79
+ refresh: "刷新状态",
80
+ verify: "验证连接",
81
+ disconnect: "断开连接",
82
+ busy: "处理中…",
83
+ qrTitle: "用「阿里云盘」App 扫码",
84
+ secLocal: "① 免扫码:从本机导入",
85
+ qrNew: "等待扫码…",
86
+ qrScanned: "已扫码,请在手机上点击确认",
87
+ qrConnecting: "已确认,正在获取令牌…",
88
+ qrFailed: "获取令牌失败",
89
+ qrRegen: "重新生成二维码",
90
+ qrExpireIn: "剩余",
91
+ seconds: "秒",
92
+ qrFail: "获取二维码失败",
93
+ qrNote: "二维码只在本机生成与轮询;令牌由宿主加密保存,不上传云端。",
94
+ restoreSkippedMix: "其中 {d} 个已存在但内容不同(勾选「覆盖同名文件」才会写入)",
95
+ wsMergedNote: "工作区登记表已合并:新增 {a} 个、保留本机 {k} 个、补回会话 {j} 个",
96
+ rgPlSkipMix: "插件跳过 {n} 个(其它 profile {s} · 本地缺包 {b})",
97
+ lrPlBlob: "本地缺包 {b}",
98
+ rgPlSkip: "插件跳过 {n} 个(属于 {p},本实例不装)",
99
+ rgRestart: "工作区 / 会话的改动要重启 DSH 才看得到",
100
+ lrPlSkip: "跳过插件 {n}",
101
+ lrRestart: "需重启 DSH",
102
+ lrHist: "还原记录",
103
+ lrHistHide: "收起记录",
104
+ lrHistEmpty: "还没有还原记录",
105
+ rsRestartChip: "需要重启才生效",
106
+ rsBusyText: "正在还原,请勿切换界面或退出",
107
+ rsCancel: "取消",
108
+ rsStopping: "正在停止…",
109
+ rsCancelled: "已取消还原,已写入的文件保留",
110
+ rsDoneText: "已还原 {s} 快照",
111
+ rsDoneSep: ",",
112
+ rsNeedApply: "需重启后生效",
113
+ cacheCleanTag: "缓存已清理",
114
+ restartNow: "立即重启",
115
+ restarting: "重启中…",
116
+ restartDone: "已发出重启指令,DSH 正在重启…",
117
+ restartPort: "端口 ",
118
+ lrHideNote: "收起这条提示",
119
+ watchWait: "\u7b49\u5f85\u6d4f\u89c8\u5668\u767b\u5f55\u2026",
120
+ watchCancel: "\u53d6\u6d88\u7b49\u5f85",
121
+ watchTimeout: "\u6ca1\u7b49\u5230\u6d4f\u89c8\u5668\u767b\u5f55",
122
+ watchDismiss: "\u53d6\u6d88",
123
+ watchAutoDone: "\u5df2\u81ea\u52a8\u5bfc\u5165\u6d4f\u89c8\u5668\u767b\u5f55\u6001\uff0c\u8fde\u63a5\u6210\u529f",
124
+ openBrowserLogin: "打开阿里云盘网页版登录",
125
+ qrZoom: "放大二维码",
126
+ qrZoomOut: "恢复大小",
127
+ copyLink: "复制链接",
128
+ linkCopied: "链接已复制,粘到浏览器地址栏打开即可",
129
+ linkCopyManual: "复制未成功,请手动复制这个地址:",
130
+ qrTry: "尝试",
131
+ qrDiagAt: "诊断:",
132
+ yes: "开启(到期前 10 分钟自动刷新)",
133
+ no: "未启用",
134
+ verified: "最近验证",
135
+ never: "从未",
136
+ importLocal: "从本机导入(免扫码)",
137
+ openBrowser: "在浏览器中打开登录页",
138
+ copyUrl: "或复制此链接到浏览器:",
139
+ backupNow: "立即备份",
140
+ backupRunning: "备份中…",
141
+ rowLastBackup: "上次备份",
142
+ backupFiles: "文件",
143
+ backupUploaded: "已传云端",
144
+ backupUploadFail: "上传失败",
145
+ backupUploadSkipped: "未上传(本次跳过)",
146
+ importHint: "若本机已安装并登录「阿里云盘」客户端,可直接点击从本机导入按钮,不必扫码;只读本机文件,令牌仍由宿主加密保存。",
147
+ secRestore: "最近备份",
148
+ restoreNone: "还没有快照(先做一次备份)",
149
+ stateUploaded: "已上传",
150
+ statePending: "待上传",
151
+ stateFailed: "上传失败",
152
+ stateNoSync: "云端未同步",
153
+ listSummaryNosync: "云端暂时读不到 · 本机缓存 {n} 份",
154
+ cloudDownTitle: "云盘暂时连不上",
155
+ cloudDownHint: "下面显示的是上次同步成功的结果",
156
+ cloudDownRetry: "重试",
157
+ cloudAuthTitle: "登录已失效",
158
+ cloudAuthHint: "重新登录云盘后可正常读取",
159
+ cloudConfigTitle: "登录信息不完整",
160
+ cloudConfigHint: "重新登录一次即可补齐",
161
+ cloudRelogin: "重新登录",
162
+ cloudCachedTag: "(上次同步的结果)",
163
+ dlAskTitle: "这份快照只剩在云端",
164
+ dlAskLead: "本地清单与数据块已删除,要先把快照下载到本地,再执行还原",
165
+ dlAskOk: "下载",
166
+ dlAskNo: "取消",
167
+ stateUnknown: "状态未知",
168
+ backupSkip: "备份未执行:",
169
+ listSummary: "云端 {n} 份备份",
170
+ listSummaryPending: " · {k} 份待上传",
171
+ listSummaryFailed: " · {m} 份需重传",
172
+ delBackupBtn: "删除",
173
+ delBackupTitle: "删除这份备份",
174
+ delBackupLead: "删除后这份备份不再出现在列表里;云端会进阿里云盘回收站(30 天内可找回)。",
175
+ delBackupCloud: "云端:进回收站,可在云盘界面恢复",
176
+ delBackupCache: "本地缓存:一并清理,释放 {mb}",
177
+ delBackupLast: "这是最后一份云端备份,删掉后云端就没有历史了。",
178
+ delDone: "已删除",
179
+ cacheCleanBtn: "清理缓存",
180
+ cacheCleanTitle: "清理本地缓存",
181
+ cacheCleanLead: "只删本机为了还原而下载的副本;云端备份不受影响。保留最近的若干份,其余回收。",
182
+ cacheCleanKeep: "保留最近 {n} 份缓存",
183
+ cacheCleanNone: "没有可清理的缓存",
184
+ cacheCleanDone: "已清理 {n} 份缓存 · 释放 {mb}",
185
+ uploadBtn: "上传",
186
+ retryUpload: "重传",
187
+ uploadDone: "已上传",
188
+ emptyList: "还没有备份(点「立即备份」把当前状态存到云盘)",
189
+ listUnavailable: "云端暂时读不到,列表不可用",
190
+ restoreLoadFail: "读取失败:",
191
+ restoreRemote: "含云端",
192
+ restoreRemoteOn: "本地",
193
+ restoreTarget: "还原到目录",
194
+ restoreTargetHint: "留空即当前 DSH_HOME(会覆盖正在用的数据,执行前会再让你确认一次)",
195
+ restorePreview: "预览",
196
+ restoreRun: "立即还原",
197
+ homeAskTitle: "还原到当前 DSH_HOME?",
198
+ homeAskLead: "目标就是本机正在使用的 DSH 目录:还原会覆盖当前的会话、存储与插件配置。",
199
+ homeAskTo: "目标目录",
200
+ homeAskL1: "· 覆盖前会把原文件备份为 <文件名>.bak-restore-<时间戳>",
201
+ homeAskL2: "· 还原完成后建议重启桌面版,让会话与配置重新加载",
202
+ homeAskYes: "确认还原",
203
+ restoreVerify: "校验还原结果",
204
+ openLogs: "打开日志",
205
+ logsOpened: "已打开日志目录",
206
+ plugNote: "插件已打包的随快照保存,未打包的只记来源,装回时联网下载",
207
+ plugNotePack: "其中 {p} 个已打包随快照保存,{s} 个只记来源,装回时联网下载",
208
+ pluginPacks: "插件",
209
+ pluginCount: "本快照含 {n} 个插件",
210
+ pluginCountMany: "插件 {n} 个({p})",
211
+ pluginCountIn: "{p} · 本快照含 {n} 个插件",
212
+ rowHost: "运行环境",
213
+ hostDesktop: "桌面端",
214
+ hostWeb: "Web 端",
215
+ hostGeneric: "命令行(未能判定 profile)",
216
+ lrHostNote: " · 来自 {from},当前 {to}",
217
+ pluginPrompt: "手动生成提示词",
218
+ plugOr: "或",
219
+ compatBad: "当前 DSH {v} 超出兼容范围 {r},宿主可能跳过本插件",
220
+ compatBadRange: "兼容范围无法解析:{r}",
221
+ compatNone: "未声明兼容范围",
222
+ pluginPromptTip: "不自动装:复制一段提示词,交给任意 agent 手动装。",
223
+ pluginPromptOk: "提示词已复制,可粘贴给任意 agent",
224
+ pluginPromptFail: "生成失败:",
225
+ restoreWithPlugins: "还原时同时装回插件",
226
+ lrPluginsOk: "装回插件",
227
+ lrPluginsFail: "插件失败",
228
+ lrTitle: "上次还原:",
229
+ lrWritten: "写入",
230
+ lrSkipped: "跳过",
231
+ lrFailed: "失败",
232
+ snapRefresh: "刷新列表",
233
+ pruneCancel: "取消",
234
+ pruneOneBtn: "删除",
235
+ dlgDelete: "确定删除",
236
+ dlgCloseAria: "关闭弹窗",
237
+ dirSessions: "会话",
238
+ dirStorages: "存储",
239
+ dirProfiles: "插件配置",
240
+ dirOurFree: "插件数据 · our-free-model",
241
+ dirMarket: "插件数据 · dshmarket",
242
+ dirRoot: "根文件",
243
+ dirSessionsNote: "各工作区的会话记录(.jsonl)",
244
+ dirStoragesNote: "Harness 持久化缓存与工作区登记",
245
+ dirProfilesNote: "每个 profile 的插件清单与 patch 文件",
246
+ dirOurFreeNote: "插件状态文件(目录 / 可用性 / 备份清单)",
247
+ dirMarketNote: "插件市场状态文件",
248
+ dirRootNote: "AGENTS.md、prompt-inject.md 等",
249
+ dirWorkspaceNote: "工作区目录(DSH 把路径里的 : 和 \\ 编码成 -)",
250
+ pullItem: "下载",
251
+ pullNoNeed: "本地已完整,无需下载",
252
+ pullGot: "已下载",
253
+ pullSnapTotal: "快照共",
254
+ pullFiles: "文件",
255
+ pullBlobs: "块",
256
+ schedTitle: "自动备份",
257
+ schedOn: "已开启",
258
+ schedHours: "小时",
259
+ schedPending: "已排期",
260
+ schedOffHint: "自动备份已关闭,只能手动「立即备份」。",
261
+ syncTitle: "同步云盘",
262
+ syncOff: "关闭",
263
+ syncOn: "开启",
264
+ syncOnLine: "新备份会自动上传到云盘;列表里的「已上传」就是云端那一份。",
265
+ sideEntry: "侧栏入口",
266
+ sideEntryOn: "开启后,在侧栏显示「云盘备份」入口。设置里的入口不变。",
267
+ sideEntryOff: "关闭后只在「设置」里保留入口。",
268
+ syncOffLine: "已关闭:新备份只保存到本机,不上传云盘(单份仍可手动上传)。",
269
+ savedLocalOnly: "已保存到本机 · 未上传",
270
+ restorePull: "从云端下载",
271
+ restoreConfirm: "我确认覆盖目标目录里的同名文件(自动留 .bak-restore 备份)",
272
+ restoreRunning: "还原中…",
273
+ restorePulling: "下载中…",
274
+ restoreFiles: "文件",
275
+ sizeWord: "大小",
276
+ restoreMiss: "缺块",
277
+ restoreNoManifest: "缺清单",
278
+ viewBusy: "更新中…",
279
+ pullProg: "下载中",
280
+ pullWhole: "快照完整度",
281
+ pullScopeBlocks: "所选 {s} 块(本机已有 {r})",
282
+ pullPausedTag: "已暂停",
283
+ pullPause: "暂停",
284
+ pullResume: "继续",
285
+ selAll: "全选",
286
+ selNone: "全不选",
287
+ selCount: "已选 {n} / {m} 项",
288
+ selEmpty: "一个目录都没选:先在文件树里勾选",
289
+ restorePickFirst: "请先选一份快照",
290
+ },
291
+ en: {
292
+ more: "More",
293
+ secAuth: "Authorization",
294
+ secRecent: "Recent backups",
295
+ schedOffShort: "Off",
296
+ schedOnShort: "On",
297
+ schedOnLine: "Auto backup on, ",
298
+ schedNextLine: "Next auto backup",
299
+ selIdNone: "No snapshot selected (click one in the list)",
300
+ listRefreshed: "List refreshed",
301
+ recentInfoTip: "Why rows differ: uploaded + cached locally \u2192 Delete only; pending (local only) \u2192 Upload sends it to the cloud; uploaded without local cache \u2192 Download fetches it back; cloud not synced \u2192 Retry re-reads that snapshot state.",
302
+ dlgCopy: "Copy",
303
+ promptTitle: "Plugin restore prompt",
304
+ promptLead: "Copy the whole text below and paste it to any agent to install the plugin bodies back.",
305
+ promptCopied: "Prompt copied to clipboard",
306
+ batchOp: "Batch select",
307
+ batchCancel: "Cancel",
308
+ batchCount: "{n} selected · {mb}",
309
+ batchNone: "No snapshot selected",
310
+ batchDeleteBtn: "Delete selected",
311
+ batchTitle: "Delete {n} snapshots?",
312
+ batchLead: "They move to the cloud trash (restorable for 30 days) and local caches are cleared too.",
313
+ batchLast: "{n} of them is the last cloud copy (the cloud would have no backup left) — continue?",
314
+ batchDeleting: "Deleting {i} / {n} …",
315
+ batchDone: "Deleted {n}",
316
+ batchFailStop: "Failed at #{i}, stopped: {err}",
317
+ selId: "Selected snapshot ID: ",
318
+ snapWord: "snapshot",
319
+ nav: "Cloud Backup",
320
+ title: "Cloud Backup",
321
+ subtitle: "Content-addressed backup of DSH sessions and config to a free cloud drive (Aliyun Drive first).",
322
+ loading: "Loading…",
323
+ phaseLoading: "loading",
324
+ rowConnect: "Connection",
325
+ rowAccount: "Account",
326
+ rowDrive: "Drive",
327
+ rowFolder: "Drive folder",
328
+ rowRefresh: "Auto refresh",
329
+ renewOn: "On",
330
+ rowStateDir: "State dir",
331
+ rowCrypto: "Credential encryption",
332
+ connected: "Connected",
333
+ notConnected: "Not connected",
334
+ connect: "Connect Aliyun Drive",
335
+ refresh: "Refresh",
336
+ verify: "Verify",
337
+ disconnect: "Disconnect",
338
+ busy: "Working…",
339
+ qrTitle: "Scan with the Aliyun Drive app",
340
+ secLocal: "1) No QR: import from this machine",
341
+ qrNew: "Waiting for scan…",
342
+ qrScanned: "Scanned — confirm on your phone",
343
+ qrConnecting: "Confirmed — fetching token…",
344
+ qrFailed: "Failed to fetch token",
345
+ qrRegen: "Regenerate QR code",
346
+ qrExpireIn: "expires in",
347
+ seconds: "seconds",
348
+ qrFail: "Failed to get QR code",
349
+ qrNote: "The QR code is generated and polled locally; tokens are encrypted by the host and never uploaded.",
350
+ restoreSkippedMix: "{d} of them exist with different content (tick “Overwrite files with the same name” to write them)",
351
+ wsMergedNote: "Workspace registry merged: +{a} new, {k} kept, {j} sessions re-linked",
352
+ rgPlSkipMix: "plugins skipped {n} (other profiles {s} · blob missing {b})",
353
+ lrPlBlob: "blob missing {b}",
354
+ rgPlSkip: "plugins skipped {n} (owned by {p}, not installed here)",
355
+ rgRestart: "restart DSH to see workspace / session changes",
356
+ lrPlSkip: "plugins skipped {n}",
357
+ lrRestart: "restart DSH",
358
+ lrHist: "Restore log",
359
+ lrHistHide: "Hide log",
360
+ lrHistEmpty: "No restores yet",
361
+ rsRestartChip: "restart to apply",
362
+ rsBusyText: "Restoring \u2014 don't switch pages or quit",
363
+ rsCancel: "Cancel",
364
+ rsStopping: "Stopping\u2026",
365
+ rsCancelled: "Restore cancelled; files already written are kept",
366
+ rsDoneText: "Restored snapshot {s}",
367
+ rsDoneSep: ", ",
368
+ rsNeedApply: "restart to apply",
369
+ cacheCleanTag: "cache cleared",
370
+ restartNow: "Restart now",
371
+ restarting: "Restarting…",
372
+ restartDone: "Restart requested; DSH is restarting…",
373
+ restartPort: "port ",
374
+ lrHideNote: "Hide this note",
375
+ watchWait: "Waiting for browser sign-in\u2026",
376
+ watchCancel: "Stop waiting",
377
+ watchTimeout: "No browser sign-in detected",
378
+ watchDismiss: "Dismiss",
379
+ watchAutoDone: "Imported the browser session automatically \u2014 connected",
380
+
381
+ openBrowserLogin: "Open Aliyun Drive web login",
382
+ qrZoom: "Enlarge QR code",
383
+ qrZoomOut: "Restore size",
384
+ copyLink: "Copy link",
385
+ linkCopied: "Link copied \u2014 paste it into your browser",
386
+ linkCopyManual: "Copy failed, please copy this address manually: ",
387
+ qrTry: "attempt",
388
+ qrDiagAt: "diagnostics: ",
389
+ yes: "on (auto refresh 10 min before expiry)",
390
+ no: "disabled",
391
+ verified: "Last verified",
392
+ never: "never",
393
+ importLocal: "Import from this machine (no QR)",
394
+ openBrowser: "Open sign-in page in browser",
395
+ copyUrl: "Or paste this link into a browser:",
396
+ backupNow: "Back up now",
397
+ backupRunning: "Backing up…",
398
+ rowLastBackup: "Last backup",
399
+ backupFiles: "files",
400
+ backupUploaded: "uploaded",
401
+ backupUploadFail: "upload failed",
402
+ backupUploadSkipped: "not uploaded (skipped)",
403
+ importHint: "If the Aliyun Drive desktop client is installed and signed in on this machine, click Import from this machine — no QR scan needed. Only local files are read; the host still stores tokens encrypted.",
404
+ secRestore: "Recent backups",
405
+ restoreNone: "No snapshots yet (run a backup first)",
406
+ stateUploaded: "uploaded",
407
+ statePending: "pending upload",
408
+ stateFailed: "upload failed",
409
+ stateNoSync: "cloud unavailable",
410
+ listSummaryNosync: "cloud unreachable · {n} cached locally",
411
+ cloudDownTitle: "Can't reach the cloud drive",
412
+ cloudDownHint: "showing the last successful sync",
413
+ cloudDownRetry: "Retry",
414
+ cloudAuthTitle: "Sign-in expired",
415
+ cloudAuthHint: "sign in to the drive again to read backups",
416
+ cloudConfigTitle: "Sign-in info incomplete",
417
+ cloudConfigHint: "sign in again to complete it",
418
+ cloudRelogin: "Sign in again",
419
+ cloudCachedTag: "(last successful sync)",
420
+ dlAskTitle: "This snapshot is only in the cloud",
421
+ dlAskLead: "Its local manifest and data blocks are gone; download it first, then restore",
422
+ dlAskOk: "Download",
423
+ dlAskNo: "Cancel",
424
+ stateUnknown: "state unknown",
425
+ backupSkip: "Backup skipped: ",
426
+ listSummary: "{n} backups in the cloud",
427
+ listSummaryPending: " · {k} pending",
428
+ listSummaryFailed: " · {m} to retry",
429
+ delBackupBtn: "Delete",
430
+ delBackupTitle: "Delete this backup",
431
+ delBackupLead: "It disappears from the list; the cloud copy moves to the Aliyun Drive recycle bin (recoverable for 30 days).",
432
+ delBackupCloud: "Cloud: moved to the recycle bin, recoverable in Aliyun Drive",
433
+ delBackupCache: "Local cache: removed too, frees {mb}",
434
+ delBackupLast: "This is the last cloud backup; deleting it leaves no cloud history.",
435
+ delDone: "Deleted",
436
+ cacheCleanBtn: "Clear cache",
437
+ cacheCleanTitle: "Clear local cache",
438
+ cacheCleanLead: "Only the copies downloaded to this machine for restore; cloud backups are untouched. Keeps the newest few, reclaims the rest.",
439
+ cacheCleanKeep: "Keep the newest {n} cache copies",
440
+ cacheCleanNone: "Nothing to clean",
441
+ cacheCleanDone: "Cleared {n} cache copies, freed {mb}",
442
+ uploadBtn: "Upload",
443
+ retryUpload: "Retry",
444
+ uploadDone: "Uploaded",
445
+ emptyList: "No backups yet (press Backup now to store the current state in the cloud)",
446
+ listUnavailable: "Cloud not reachable \u2014 list unavailable",
447
+ restoreLoadFail: "Failed to read: ",
448
+ restoreRemote: "with cloud",
449
+ restoreRemoteOn: "Local",
450
+ restoreTarget: "Restore into",
451
+ restoreTargetHint: "Empty = current DSH_HOME (overwrites live data; you'll be asked to confirm once more)",
452
+ restorePreview: "Preview",
453
+ restoreRun: "Restore now",
454
+ homeAskTitle: "Restore into the live DSH_HOME?",
455
+ homeAskLead: "The target is this machine's live DSH directory: restoring overwrites current sessions, storage and plugin config.",
456
+ homeAskTo: "Target",
457
+ homeAskL1: "· Existing files are backed up as <name>.bak-restore-<stamp> before overwrite",
458
+ homeAskL2: "· Restart the desktop app afterwards so sessions and config reload",
459
+ homeAskYes: "Restore",
460
+ restoreVerify: "Verify result",
461
+ openLogs: "Open logs",
462
+ logsOpened: "Opened log folder",
463
+ plugNote: "Packed plugins travel with the snapshot, the rest only keep their source, downloaded when reinstalling",
464
+ plugNotePack: " — {p} packed with the snapshot, {s} recorded by source only, downloaded when reinstalling",
465
+ pluginPacks: "Plugins",
466
+ pluginCount: "This snapshot carries {n} plugins",
467
+ pluginCountMany: "{n} plugins ({p})",
468
+ pluginCountIn: "{p} · {n} plugin packages",
469
+ rowHost: "Runtime",
470
+ hostDesktop: "Desktop",
471
+ hostWeb: "Web",
472
+ hostGeneric: "CLI (profile unknown)",
473
+ lrHostNote: " · from {from}, currently {to}",
474
+ pluginPrompt: "generate a prompt manually",
475
+ plugOr: "or",
476
+ compatBad: "Running DSH {v} is outside the supported range {r}; the host may skip this plugin",
477
+ compatBadRange: "Unreadable compatibility range: {r}",
478
+ compatNone: "No compatibility range declared",
479
+ pluginPromptTip: "Skip auto-install: copy a prompt and let any agent do it.",
480
+ pluginPromptOk: "Prompt copied — paste it to any agent",
481
+ pluginPromptFail: "Failed: ",
482
+ restoreWithPlugins: "Also install plugins on restore",
483
+ lrPluginsOk: "plugins installed",
484
+ lrPluginsFail: "plugins failed",
485
+ lrTitle: "Last restore:",
486
+ lrWritten: "written",
487
+ lrSkipped: "skipped",
488
+ lrFailed: "failed",
489
+ snapRefresh: "Refresh",
490
+ pruneCancel: "Cancel",
491
+ pruneOneBtn: "Delete",
492
+ dlgDelete: "Delete",
493
+ dlgCloseAria: "Close dialog",
494
+ dirSessions: "Sessions",
495
+ dirStorages: "Storages",
496
+ dirProfiles: "Plugin config",
497
+ dirOurFree: "Plugin data · our-free-model",
498
+ dirMarket: "Plugin data · dshmarket",
499
+ dirRoot: "Root files",
500
+ dirSessionsNote: "session logs per workspace (.jsonl)",
501
+ dirStoragesNote: "Harness persistent cache and workspace registry",
502
+ dirProfilesNote: "plugin manifest and patch per profile",
503
+ dirOurFreeNote: "plugin state files (catalog / availability / backup list)",
504
+ dirMarketNote: "plugin market state file",
505
+ dirRootNote: "AGENTS.md, prompt-inject.md and friends",
506
+ dirWorkspaceNote: "workspace dir (DSH encodes : and \\ as -)",
507
+ pullItem: "Download",
508
+ pullNoNeed: "Already complete locally \u2014 nothing to download",
509
+ pullGot: "downloaded",
510
+ pullSnapTotal: "snapshot total",
511
+ pullFiles: "files",
512
+ pullBlobs: "blobs",
513
+ schedTitle: "Automatic backup",
514
+ schedOn: "On",
515
+ schedHours: "h",
516
+ schedPending: "scheduled",
517
+ schedOffHint: "Automatic backup is off — only manual \"Backup now\" runs.",
518
+ syncTitle: "Cloud sync",
519
+ syncOff: "Off",
520
+ syncOn: "On",
521
+ syncOnLine: "New backups upload to the cloud automatically; a row marked Uploaded is that cloud copy.",
522
+ sideEntry: "Sidebar entry",
523
+ sideEntryOn: "When on, a Cloud Backup entry appears in the sidebar. The entry in Settings stays.",
524
+ sideEntryOff: "When off, the entry lives in Settings only.",
525
+ syncOffLine: "Off: new backups stay on this machine only (a single backup can still be uploaded by hand).",
526
+ savedLocalOnly: "Saved on this machine (cloud sync is off, nothing was uploaded).",
527
+ restorePull: "Download from cloud",
528
+ restoreConfirm: "Overwrite files with the same name (a .bak-restore copy is kept)",
529
+ restoreRunning: "Restoring…",
530
+ restorePulling: "Downloading…",
531
+ restoreFiles: "files",
532
+ sizeWord: "size",
533
+ restoreMiss: "missing",
534
+ restoreNoManifest: "no manifest",
535
+ viewBusy: "refreshing…",
536
+ pullProg: "Downloading",
537
+ pullWhole: "snapshot complete",
538
+ pullScopeBlocks: "{s} blocks in scope ({r} already downloaded)",
539
+ pullPausedTag: "paused",
540
+ pullPause: "Pause",
541
+ pullResume: "Resume",
542
+ selAll: "Select all",
543
+ selNone: "Select none",
544
+ selCount: "{n} / {m} selected",
545
+ selEmpty: "Nothing selected: pick directories in the tree first",
546
+ restorePickFirst: "Pick a snapshot first",
547
+ },
548
+ };
549
+
550
+ // 本地兜底:locale 服务不可用(或字典未加载)时仍能出文案
551
+ let t = function (key) { return DICT.zh[key] || key; };
552
+
553
+ const css = `/* dsh-cloud-backup:按「全新 UI 效果图」重绘(浅色为基准,深色自动派生) */
554
+ /* 主题令牌:卡片与弹窗共用(弹窗经 portal 挂在 body 下,不在卡片作用域内) */
555
+ .dshcb-card,.dshcb-modalroot,.dshcb-toast{
556
+ --cb-fg:#303030; --cb-fg2:#555557; --cb-fg3:#8b8c8f; --cb-fg4:#aaaabb;
557
+ --cb-icon:#6f7276; --cb-line:#ededee; --cb-border:#e2e3e5; --cb-fill:#f7f7f9;
558
+ --cb-accent:#0c90e6; --cb-primary:#303030; --cb-onprimary:#fff;
559
+ --cb-surface:#fff; --cb-hover:#fafafa; --cb-warn:#b45309; --cb-err:#d92c2c;
560
+ }
561
+ .dshcb-card{position:relative;overflow:hidden}
562
+ /* 「读取中」时的卡片底部边缘流光:只在首屏拿不到 /status 时出现 */
563
+ .dshcb-card.dshcb-loading::after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;
564
+ background:linear-gradient(90deg,transparent 0%,var(--cb-accent) 50%,transparent 100%);background-size:38% 100%;
565
+ animation:dshcb-edge 1.35s linear infinite;pointer-events:none}
566
+ @keyframes dshcb-edge{0%{background-position:-40% 0}100%{background-position:140% 0}}
567
+ @media (prefers-reduced-motion:reduce){.dshcb-card.dshcb-loading::after{animation:none;background:var(--cb-accent);opacity:.5}}
568
+ .dshcb-card{
569
+ font-family:var(--dsw-font-family,var(--dsh-font-family-text,-apple-system,"SF Pro Text","PingFang SC","Segoe UI",system-ui,sans-serif));
570
+ font-size:12px; line-height:1.5; color:var(--cb-fg);
571
+ background:var(--cb-surface);
572
+ border:1px solid var(--cb-line); border-radius:16px;
573
+ box-shadow:0 1px 2px rgba(0,0,0,.04), 0 12px 32px rgba(0,0,0,.07);
574
+ padding:18px 20px 16px; margin:0 0 12px; box-sizing:border-box;
575
+ }
576
+ /* 深色:跟随宿主(宿主给 body 打 data-ds-dark-theme)。不用 prefers-color-scheme,
577
+ 否则「系统深色 + DSH 选浅色」时卡片会被刷成深色,与周围设置面板不一致。 */
578
+ body[data-ds-dark-theme] .dshcb-card,
579
+ body[data-ds-dark-theme] .dshcb-modalroot,
580
+ body[data-ds-dark-theme] .dshcb-toast{
581
+ --cb-fg:#f2f3f5; --cb-fg2:#c9ccd1; --cb-fg3:#a2a6ac; --cb-fg4:#878b91;
582
+ --cb-icon:#a2a6ac; --cb-line:rgba(255,255,255,.10); --cb-border:rgba(255,255,255,.16);
583
+ --cb-fill:rgba(255,255,255,.07); --cb-accent:#3ea6f5; --cb-primary:#f2f3f5; --cb-onprimary:#17181a;
584
+ --cb-surface:#1e1f21; --cb-hover:rgba(255,255,255,.045); --cb-warn:#e0a144; --cb-err:#ff6b6b;
585
+ }
586
+ .dshcb-ico{display:block;flex:0 0 auto}
587
+ .dshcb-card *,.dshcb-modalroot *{box-sizing:border-box}
588
+
589
+ /* ① 标题行 */
590
+ .dshcb-head{display:flex;align-items:center;gap:10px}
591
+ .dshcb-headL{display:flex;align-items:center;gap:8px;min-width:0}
592
+ .dshcb-headL .dshcb-ico{color:var(--cb-fg)}
593
+ .dshcb-h1{font-size:16.5px;font-weight:600;letter-spacing:.01em;white-space:nowrap}
594
+ .dshcb-ver{font-size:11px;color:var(--cb-fg3);background:var(--cb-fill);border-radius:6px;padding:1px 6px;font-variant-numeric:tabular-nums}
595
+ .dshcb-headR{margin-left:auto;display:flex;align-items:center;gap:14px}
596
+ .dshcb-state{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--cb-fg2);white-space:nowrap}
597
+ /* 状态点:宿主 StateDot 的做法(同色 10% 光晕 + 实心核心),四态四色 + 呼吸动效 */
598
+ .dshcb-dot{position:relative;width:7px;height:7px;flex:0 0 7px;border-radius:50%;display:inline-block;color:var(--cb-fg4)}
599
+ .dshcb-dot::before{content:"";position:absolute;inset:0;border-radius:50%;background:currentColor;
600
+ animation:dshcb-breathe 2.6s ease-in-out infinite}
601
+ .dshcb-dot::after{content:"";position:absolute;inset:1.5px;border-radius:50%;background:currentColor}
602
+ .dshcb-state.s-ok .dshcb-dot{color:var(--cb-accent)}
603
+ .dshcb-state.s-busy .dshcb-dot{color:var(--dsw-alias-state-warn-primary,var(--cb-warn))}
604
+ .dshcb-state.s-busy .dshcb-dot::before{animation-duration:1.2s}
605
+ .dshcb-state.s-err .dshcb-dot{color:var(--dsw-alias-state-error-primary,var(--cb-err))}
606
+ .dshcb-state.s-err .dshcb-dot::before{animation-duration:1.6s}
607
+ .dshcb-state.s-off .dshcb-dot{color:var(--cb-fg4)}
608
+ .dshcb-state.s-off .dshcb-dot::before{animation-duration:3.6s}
609
+ @keyframes dshcb-breathe{0%,100%{opacity:.14;transform:scale(1)}50%{opacity:.34;transform:scale(1.5)}}
610
+ @media (prefers-reduced-motion: reduce){.dshcb-dot::before{animation:none;opacity:.28}}
611
+ .dshcb-morewrap{position:relative}
612
+ .dshcb-more{appearance:none;border:0;background:transparent;font:inherit;font-size:12px;color:var(--cb-fg2);
613
+ display:inline-flex;align-items:center;gap:4px;padding:2px 4px;border-radius:6px;cursor:pointer}
614
+ .dshcb-more:hover{background:var(--cb-fill)}
615
+ .dshcb-menu{position:absolute;right:0;top:calc(100% + 4px);z-index:100;min-width:150px;padding:4px;border-radius:10px;
616
+ background:var(--dsw-specific-menu,var(--cb-surface));border:1px solid var(--dsw-alias-border-inverted,var(--cb-border));
617
+ box-shadow:var(--dsw-shadow-lv3,0 0 1px rgba(0,0,0,.2),0 0 4px rgba(0,0,0,.02),0 12px 32px rgba(0,0,0,.08));
618
+ animation:dshcb-pop .12s ease-out}
619
+ .dshcb-mi{display:block;width:100%;text-align:left;appearance:none;border:0;background:transparent;font:inherit;
620
+ font-size:13px;line-height:20px;color:var(--dsw-alias-label-primary,var(--cb-fg));min-height:31px;padding:5px 9px;
621
+ border-radius:9px;cursor:pointer;white-space:nowrap}
622
+ .dshcb-mi:hover{background:var(--dsw-alias-interactive-bg-hover,var(--cb-fill))}
623
+ .dshcb-mi.danger{color:var(--cb-err)}
624
+ @keyframes dshcb-pop{from{opacity:0;transform:translateY(-4px) scale(.98)}to{opacity:1;transform:none}}
625
+
626
+ /* 弹窗:完全对齐宿主 Modal 规格(fixed 满屏层 + mask 模糊,点遮罩即取消;r24 卡片 / shadow-lv3 /
627
+ 标题 16·500 / 描述 14·22 / 页脚右对齐胶囊按钮 h36 r18) */
628
+ .dshcb-modalroot{position:fixed;inset:0;z-index:1000;display:flex;align-items:center;justify-content:center;padding:24px}
629
+ .dshcb-mask{position:absolute;inset:0;background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.24));
630
+ backdrop-filter:var(--dsw-mask-blur,blur(2px))}
631
+ .dshcb-dialog{position:relative;z-index:1;display:flex;flex-direction:column;gap:20px;width:min(440px,100%);
632
+ max-height:calc(100vh - 48px);padding:0 0 24px;overflow:hidden;border-radius:24px;
633
+ border:1px solid var(--dsw-alias-border-inverted,var(--cb-border));
634
+ background:var(--dsw-alias-bg-layer-2,var(--cb-surface));
635
+ box-shadow:var(--dsw-shadow-lv3,0 0 1px rgba(0,0,0,.2),0 0 4px rgba(0,0,0,.02),0 12px 32px rgba(0,0,0,.08));
636
+ animation:dshcb-dlg-in .16s cubic-bezier(.2,0,.2,1)}
637
+ .dshcb-dlgContent{display:flex;flex-direction:column;min-height:0;overflow-y:auto;overscroll-behavior:contain}
638
+ .dshcb-dlgHead{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:22px 14px 12px 24px}
639
+ .dshcb-dlgTitle{margin:0;font-size:15px;line-height:22px;font-weight:500;
640
+ color:var(--dsw-alias-label-primary,var(--cb-fg))}
641
+ .dshcb-dlgClose{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;
642
+ border:0;border-radius:8px;background:transparent;cursor:pointer;
643
+ color:var(--dsw-alias-label-secondary,var(--cb-fg3))}
644
+ .dshcb-dlgClose:hover{background:var(--dsw-alias-interactive-bg-hover,var(--cb-fill))}
645
+ .dshcb-dlgLead{margin:0;padding:0 22px;font-size:13px;line-height:20px;
646
+ color:var(--dsw-alias-label-primary,var(--cb-fg))}
647
+ .dshcb-dlgBody{display:flex;flex-direction:column;gap:12px;margin-top:20px;padding:0 24px}
648
+ .dshcb-dlgWarn{display:flex;align-items:flex-start;gap:10px;font-size:13px;line-height:20px;
649
+ color:var(--dsw-alias-label-secondary,var(--cb-fg2))}
650
+ .dshcb-dlgWarn p{margin:0}
651
+ .dshcb-dlgWarnIco{flex:none;margin-top:2px;color:var(--dsw-alias-state-error-primary,var(--cb-err))}
652
+ .dshcb-dlgList{margin:0;padding:9px 11px;list-style:none;max-height:200px;overflow-y:auto;overscroll-behavior:contain;
653
+ border:1px solid var(--cb-line);border-radius:10px;background:var(--cb-fill);
654
+ font-size:12px;line-height:18px;color:var(--cb-fg2);font-variant-numeric:tabular-nums}
655
+ .dshcb-dlgList li+li{margin-top:6px}
656
+ .dshcb-dlgSkip{margin:0;font-size:12px;line-height:18px;color:var(--cb-fg3)}
657
+ .dshcb-dlgPre{margin:0;padding:10px 12px;max-height:240px;overflow:auto;overscroll-behavior:contain;white-space:pre-wrap;word-break:break-all;
658
+ font-family:var(--dsw-font-family-mono,ui-monospace,SFMono-Regular,Menlo,Consolas,monospace);font-size:11.5px;line-height:1.55;
659
+ color:var(--cb-fg2);background:var(--cb-fill);border:1px solid var(--cb-line);border-radius:10px}
660
+ .dshcb-dlgFoot{display:flex;align-items:center;justify-content:flex-end;gap:8px;padding:0 24px}
661
+ .dshcb-dbtn{appearance:none;display:inline-flex;align-items:center;justify-content:center;gap:4px;height:32px;
662
+ min-width:66px;padding:0 12px;border:0;border-radius:16px;font:inherit;font-size:13px;line-height:20px;
663
+ cursor:pointer;color:var(--dsw-alias-label-primary,var(--cb-fg))}
664
+ .dshcb-dbtn.outline{border:1px solid var(--dsw-alias-border-l2,var(--cb-border));background:transparent}
665
+ .dshcb-dbtn.outline:hover{background:var(--dsw-alias-interactive-bg-hover,var(--cb-hover))}
666
+ .dshcb-dbtn.primary{font-weight:500;
667
+ background:var(--dsw-alias-button-primary-fill,var(--cb-primary));
668
+ color:var(--dsw-alias-label-primary-foreground,var(--cb-onprimary))}
669
+ .dshcb-dbtn.primary:hover{background:var(--dsw-alias-button-primary-hover,var(--cb-primary));opacity:.92}
670
+ @keyframes dshcb-dlg-in{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}
671
+ @media (prefers-reduced-motion: reduce){.dshcb-dialog,.dshcb-menu{animation:none}}
672
+ .dshcb-mi.danger{color:var(--cb-err)}
673
+ .dshcb-sub{margin:4px 0 0;font-size:12px;color:var(--cb-fg3)}
674
+
675
+ /* ②③④ 分区 */
676
+ .dshcb-sec{margin-top:12px;padding-top:12px;border-top:1px solid var(--cb-line)}
677
+ .dshcb-sech{display:flex;align-items:center;gap:10px;width:100%;padding:0;text-align:left;
678
+ appearance:none;border:0;background:transparent;font:inherit;color:inherit}
679
+ button.dshcb-sech{cursor:pointer}
680
+ .dshcb-sechT{flex:0 0 auto;font-size:13.5px;font-weight:600;color:var(--cb-fg)}
681
+ .dshcb-sechS{min-width:0;font-size:11.5px;color:var(--cb-fg3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
682
+ .dshcb-sechR{margin-left:auto;display:flex;align-items:center;gap:8px}
683
+ .dshcb-sechIco{margin-left:auto;display:inline-flex;color:var(--cb-fg4)}
684
+ .dshcb-infoIco{flex:0 0 auto;display:inline-flex;align-items:center;color:var(--cb-fg4);cursor:help}
685
+ /* 说明浮层:跟随主题的黑/白半透明气泡(自绘,替代原生 title) */
686
+ .dshcb-tipHost{position:relative;display:inline-flex;align-items:center;outline:none}
687
+ .dshcb-tip{position:absolute;left:-6px;bottom:calc(100% + 8px);z-index:90;width:max-content;max-width:min(300px,72vw);
688
+ padding:7px 10px;border-radius:8px;font-size:11.5px;line-height:1.55;font-weight:400;text-align:left;white-space:normal;
689
+ color:#fff;background:rgba(28,29,31,.92);box-shadow:0 3px 10px rgba(0,0,0,.04);
690
+ opacity:0;visibility:hidden;transition:opacity .12s ease,visibility .12s;pointer-events:none}
691
+ .dshcb-tip::after{content:"";position:absolute;left:14px;top:100%;border:5px solid transparent;border-top-color:rgba(28,29,31,.92)}
692
+ .dshcb-tipHost:hover .dshcb-tip,.dshcb-tipHost:focus .dshcb-tip,.dshcb-tipHost:focus-within .dshcb-tip{opacity:1;visibility:visible}
693
+ body[data-ds-dark-theme] .dshcb-tip{color:#1b1c1e;background:rgba(244,245,247,.94);box-shadow:0 3px 10px rgba(0,0,0,.10)}
694
+ body[data-ds-dark-theme] .dshcb-tip::after{border-top-color:rgba(244,245,247,.94)}
695
+ @media (prefers-reduced-motion:reduce){ .dshcb-tip{transition:none} }
696
+ .dshcb-infoIco:hover{color:var(--cb-fg2)}
697
+
698
+ .dshcb-table{margin-top:10px;border:1px solid var(--cb-line);border-radius:10px;overflow:hidden}
699
+ .dshcb-tr{display:flex;align-items:center;gap:10px;min-height:29px;padding:5px 12px;border-top:1px solid var(--cb-line)}
700
+ .dshcb-tr:first-child{border-top:0}
701
+ .dshcb-tk{flex:0 0 auto;color:var(--cb-fg3)}
702
+ .dshcb-tv{margin-left:auto;min-width:0;text-align:right;color:var(--cb-fg);word-break:break-all;font-variant-numeric:tabular-nums}
703
+
704
+ /* 主面板页:只负责页面留白 / 居中 / 滚动,卡片外观与「设置」里完全一致 */
705
+ .dshcb-page{box-sizing:border-box;min-height:100%;overflow:auto;display:flex;justify-content:center;
706
+ align-items:flex-start;padding:22px 28px 48px}
707
+ .dshcb-page .dshcb-card{width:100%;max-width:1120px;margin:0}
708
+
709
+ /* 行内悬浮提示(自绘;半透明黑,深色下改浅色) */
710
+ .dshcb-hoverTip{position:fixed;z-index:90;width:max-content;max-width:min(320px,72vw);padding:5px 9px;border-radius:7px;
711
+ font-size:11px;line-height:1.45;white-space:normal;overflow-wrap:break-word;background:rgba(22,23,26,.86);color:#fff;
712
+ box-shadow:0 2px 6px rgba(0,0,0,.03);pointer-events:none;transform:none}
713
+ body[data-ds-dark-theme] .dshcb-hoverTip{background:rgba(244,245,247,.94);color:#111;box-shadow:0 3px 10px rgba(0,0,0,.10)}
714
+
715
+ /* 分段控件(滑块在选项之间平滑滑动,缩略图由 .dshcb-segthumb 承担) */
716
+ .dshcb-seg{position:relative;display:inline-flex;align-items:center;gap:2px;box-sizing:border-box;height:30px;padding:2px;border-radius:9px;background:var(--cb-fill)}
717
+ .dshcb-seg.dis{opacity:.5;pointer-events:none}
718
+ .dshcb-seg.sm .dshcb-segi{font-size:11px;padding:0 9px}
719
+ .dshcb-segthumb{position:absolute;left:0;top:2px;bottom:2px;z-index:0;border-radius:7px;pointer-events:none;
720
+ background:var(--cb-surface);border:1px solid var(--cb-border);box-shadow:0 1px 2px rgba(0,0,0,.06);
721
+ will-change:transform,width;
722
+ transition:transform .26s cubic-bezier(.22,1,.36,1),width .26s cubic-bezier(.22,1,.36,1)}
723
+ .dshcb-segthumb.notrans{transition:none}
724
+ .dshcb-segi{position:relative;z-index:1;appearance:none;border:1px solid transparent;background:transparent;font:inherit;
725
+ font-size:12px;color:var(--cb-fg2);box-sizing:border-box;height:26px;display:inline-flex;align-items:center;padding:0 12px;border-radius:7px;cursor:pointer;white-space:nowrap;
726
+ transition:color .2s ease}
727
+ .dshcb-segi:hover{color:var(--cb-fg)}
728
+ .dshcb-segi.on{color:var(--cb-fg);font-weight:600}
729
+ @media (prefers-reduced-motion: reduce){.dshcb-segthumb{transition:none}}
730
+
731
+ /* 说明行 + 按钮 */
732
+ .dshcb-line{margin-top:12px;display:flex;align-items:center;gap:12px}
733
+ .dshcb-lineText{font-size:12px;color:var(--cb-fg3)}
734
+ .dshcb-line .dshcb-btn{margin-left:auto}
735
+ .dshcb-btn{appearance:none;border:1px solid var(--cb-border);background:var(--cb-surface);color:var(--cb-fg);
736
+ font:inherit;font-size:12px;font-weight:500;padding:6px 12px;border-radius:9px;cursor:pointer;
737
+ transition:background .15s ease,opacity .15s ease;white-space:nowrap}
738
+ .dshcb-btn:hover{background:var(--cb-hover)}
739
+ .dshcb-btn.d2{background:var(--cb-primary);border-color:var(--cb-primary);color:var(--cb-onprimary)}
740
+ .dshcb-btn.d2:hover{opacity:.86;background:var(--cb-primary)}
741
+ .dshcb-btn:disabled{opacity:.45;cursor:default;background:var(--cb-primary);background-color:var(--cb-primary)}
742
+ .dshcb-btn:not(.d2):disabled{background:var(--cb-surface)}
743
+ .dshcb-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
744
+
745
+ .dshcb-tools{flex-wrap:wrap;justify-content:flex-end;gap:0;row-gap:2px}
746
+ .dshcb-batchSum{color:var(--cb-fg3);cursor:default}
747
+ .dshcb-item.dshcb-batch .dshcb-iacts,.dshcb-item.dshcb-batch .dshcb-ichev{display:none}
748
+ .dshcb-tool{appearance:none;border:0;background:transparent;font:inherit;font-size:12px;color:var(--cb-fg2);
749
+ display:inline-flex;align-items:center;gap:5px;padding:4px 6px;border-radius:7px;cursor:pointer;white-space:nowrap}
750
+ .dshcb-tool .dshcb-ico{color:var(--cb-icon)}
751
+ .dshcb-tool:hover{background:var(--cb-fill)}
752
+ .dshcb-tool.on,.dshcb-tool.on .dshcb-ico{color:var(--cb-accent)}
753
+ .dshcb-tool:disabled{opacity:.45;cursor:default;background:transparent}
754
+
755
+
756
+ /* ⑤ 快照列表(高度封顶 + 内部滚动,卡片不会随快照数量无限变高) */
757
+ .dshcb-list{margin-top:10px;border:1px solid var(--cb-line);border-radius:10px;
758
+ max-height:min(46vh,380px);overflow-y:auto;overflow-x:hidden;overscroll-behavior:auto;
759
+ scrollbar-width:thin;scrollbar-color:var(--cb-line) transparent}
760
+ .dshcb-list::-webkit-scrollbar{width:8px}
761
+ .dshcb-list::-webkit-scrollbar-track{background:transparent}
762
+ .dshcb-list::-webkit-scrollbar-thumb{background:var(--cb-line);border-radius:4px}
763
+ .dshcb-list::-webkit-scrollbar-thumb:hover{background:var(--cb-fg4)}
764
+ .dshcb-listSkel{padding:5px 9px}
765
+ .dshcb-skel{height:46px;border-radius:9px;margin:5px 0;background-color:var(--cb-fill);
766
+ background-image:linear-gradient(90deg,transparent 0%,var(--cb-line) 50%,transparent 100%);
767
+ background-size:220% 100%;background-repeat:no-repeat;animation:dshcb-shimmer 1.35s linear infinite}
768
+ @keyframes dshcb-shimmer{0%{background-position:-120% 0}100%{background-position:140% 0}}
769
+ .dshcb-listHint{padding:5px 11px 3px;font-size:11px;color:var(--cb-fg3)}
770
+ .dshcb-spin{display:inline-block;width:12px;height:12px;margin-right:7px;vertical-align:-2px;border-radius:50%;
771
+ border:2px solid var(--cb-fill);border-top-color:var(--cb-accent);animation:dshcb-spin .8s linear infinite}
772
+ @keyframes dshcb-spin{to{transform:rotate(360deg)}}
773
+ .dshcb-grpEmpty{padding:10px 12px;font-size:11px;line-height:16px;color:var(--cb-fg4);border-bottom:1px solid var(--cb-line)}
774
+ .dshcb-item{display:flex;align-items:center;gap:10px;padding:8px 12px;border-top:1px solid var(--cb-line);
775
+ cursor:pointer;flex-wrap:wrap} /* item 允许换行:展开的目录树要独占一行 */
776
+ .dshcb-rowMain{display:flex;align-items:center;gap:10px;min-width:0;flex:1 0 100%}
777
+ /* 行内(勾选/图标/标题/动作/箭头)永不换行:标题过长只省略,不许把「下载/删除」挤到第二行 */
778
+ .dshcb-item:first-child{border-top:0}
779
+ .dshcb-item.on{background:var(--cb-fill)} /* 当前选中/待还原的那一行 */
780
+ .dshcb-badge{flex:0 0 auto;height:15px;line-height:15px;padding:0 6px;border-radius:8px;font-size:9.5px;font-weight:500;
781
+ color:var(--cb-fg3);background:var(--cb-fill);font-variant-numeric:tabular-nums}
782
+ .dshcb-badge.muted{background:var(--cb-fill);color:var(--cb-fg3)}
783
+ .dshcb-tool.warn{color:var(--cb-err)}
784
+ .dshcb-badge.warn{color:var(--cb-err);background:transparent}
785
+ .dshcb-badge.err{color:#fff;background:var(--cb-err)}
786
+ /* 消息层:一处组件、三种等级;由状态派生,不落库、不重复 */
787
+ .dshcb-lane{display:flex;flex-direction:column;gap:8px;margin-top:10px}
788
+ .dshcb-lane .dshcb-pullRow{margin-top:0}
789
+ .dshcb-msg{display:flex;align-items:flex-start;gap:9px;padding:8px 10px;border-radius:10px;
790
+ background:var(--cb-fill);box-shadow:inset 0 0 0 1px var(--cb-line)}
791
+ .dshcb-msgMain{flex:1;min-width:0;display:flex;flex-wrap:wrap;align-items:baseline;gap:2px 10px}
792
+ .dshcb-msgT{font:500 11.5px/17px var(--cb-font);color:var(--cb-fg)}
793
+ .dshcb-msgD{font:11px/17px var(--cb-font);color:var(--cb-fg3);word-break:break-word}
794
+ .dshcb-msgAct{flex:none;display:flex;align-items:center;gap:6px;align-self:center}
795
+ .dshcb-msg--blocker .dshcb-msgT{color:var(--cb-err)}
796
+ .dshcb-msg--warn .dshcb-msgT{color:var(--cb-warn)}
797
+ .dshcb-msg--info .dshcb-msgT{color:var(--cb-fg)}
798
+ /* 只有一行正文时让这一行落在卡片水平中心;多行保持左对齐,读起来更稳 */
799
+ .dshcb-msgClose{border:0;background:transparent;cursor:pointer;padding:0 2px;font-size:12px;line-height:1;color:var(--cb-fg3)}
800
+ .dshcb-msgClose:hover{color:var(--cb-fg)}
801
+ /* 主按钮旁的就地说明 */
802
+ /* 列表首次加载的占位(骨架):比白屏 / “暂无备份”更诚实 */
803
+ .dshcb-skelrow{cursor:default;pointer-events:none}
804
+ .dshcb-skelico,.dshcb-skelbar{background-color:var(--cb-fill);
805
+ background-image:linear-gradient(90deg,transparent 0%,var(--cb-line) 50%,transparent 100%);
806
+ background-size:220% 100%;background-repeat:no-repeat;animation:dshcb-shimmer 1.35s linear infinite}
807
+ .dshcb-skelico{flex:0 0 auto;width:20px;height:20px;border-radius:5px}
808
+ .dshcb-skelbar{display:block;height:10px;border-radius:5px;margin:3px 0}
809
+ .dshcb-skelbar2{height:8px}
810
+ .dshcb-plugRow{display:flex;align-items:center;flex-wrap:wrap;gap:8px;margin:2px 0 4px}
811
+ .dshcb-needRestart{color:var(--cb-err);font-weight:500}
812
+ .dshcb-plugChk{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:var(--cb-fg2);cursor:pointer}
813
+ .dshcb-or{font-size:12px;color:var(--cb-fg3)}
814
+ .dshcb-plugChk input{width:14px;height:14px;margin:0}
815
+ .dshcb-plugRow .dshcb-link{margin-left:0}
816
+ .dshcb-pickedBar{display:inline-block;width:132px;height:9px;border-radius:5px;vertical-align:-1px}
817
+ @media (prefers-reduced-motion: reduce){.dshcb-skelico,.dshcb-skelbar,.dshcb-skel,.dshcb-pickedBar{animation:none}}
818
+ .dshcb-sechMeta{margin-left:8px;font-size:10.5px;font-weight:400;color:var(--cb-fg3)}
819
+ .dshcb-item:hover{background:var(--cb-hover)}
820
+ /* 勾选框:与宿主复选框一致的「方格勾」 */
821
+ .dshcb-radio{width:16px;height:16px;flex:0 0 16px;border-radius:4.5px;border:1.5px solid var(--cb-fg4);
822
+ display:inline-flex;align-items:center;justify-content:center;color:var(--cb-onprimary);background:transparent;
823
+ transition:background .15s ease,border-color .15s ease}
824
+ .dshcb-radio:hover{border-color:var(--cb-fg3)}
825
+ .dshcb-radio.on{background:var(--cb-primary);border-color:var(--cb-primary)}
826
+ .dshcb-fico{display:inline-flex;color:var(--cb-icon)}
827
+ .dshcb-itxt{display:flex;flex-direction:column;gap:2px;min-width:0;flex:1 1 auto}
828
+ .dshcb-ititle{display:flex;align-items:center;gap:6px;min-width:0;font-size:12.5px;font-weight:600;color:var(--cb-fg)}
829
+ .dshcb-itname{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
830
+ .dshcb-itag{font-size:10.5px;font-weight:500;color:var(--cb-fg3);margin-left:2px}
831
+ .dshcb-isub{font-size:10.5px;color:var(--cb-fg3);font-variant-numeric:tabular-nums;
832
+ overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
833
+ .dshcb-iacts{margin-left:auto;display:flex;align-items:center;gap:2px;flex:0 0 auto}
834
+ .dshcb-ichev{display:inline-flex;color:var(--cb-fg4);flex:0 0 auto;transition:transform .15s ease}
835
+ .dshcb-tree{flex:1 0 100%;margin:7px 0 0;padding:8px 0 2px;border-top:1px solid var(--cb-line)}
836
+ .dshcb-treeLoad{font-size:11px;color:var(--cb-fg3)}
837
+ .dshcb-errLine{color:var(--cb-err)}
838
+ .dshcb-tn{display:flex;align-items:flex-start;gap:8px;padding:6px 0 6px 7px}
839
+ .dshcb-tnHead{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 0 6px;border-bottom:1px dashed var(--cb-line);margin-bottom:4px}
840
+ .dshcb-tnSel{font-size:11px;color:var(--cb-fg3);font-variant-numeric:tabular-nums}
841
+ .dshcb-tnActs{display:flex;gap:14px}
842
+ .dshcb-tn{cursor:pointer;border-radius:6px}
843
+ .dshcb-tn:hover{background:color-mix(in srgb,currentColor 4%,transparent)}
844
+ .dshcb-tn .dshcb-radio{width:16px;height:16px;flex:0 0 16px;margin-top:1px}
845
+ .dshcb-pullRow{display:flex;align-items:center;justify-content:space-between;gap:10px}
846
+ .dshcb-pullTxt{min-width:0}
847
+ .dshcb-btn.ghost{height:28px;padding:0 10px;font-size:12px;border-radius:8px;background:transparent;border:1px solid var(--cb-line);color:var(--cb-fg)}
848
+ .dshcb-btn.ghost:hover{background:color-mix(in srgb,currentColor 7%,transparent)}
849
+ .dshcb-tnBody{min-width:0}
850
+ .dshcb-tnName{font-size:12px;font-weight:600;color:var(--cb-fg)}
851
+ .dshcb-tnSub{font-size:11px;color:var(--cb-fg3);word-break:break-word}
852
+ .dshcb-tnMeta{margin-left:auto;flex:0 0 auto;font-size:11px;color:var(--cb-fg3);
853
+ font-variant-numeric:tabular-nums;padding-top:2px}
854
+
855
+ /* ⑥ 还原操作区 */
856
+ .dshcb-picked{margin-top:12px;font-size:12px;color:var(--cb-fg2)}
857
+ .dshcb-pickedWait{display:inline-flex;align-items:center;gap:6px;color:var(--cb-fg3)}
858
+ .dshcb-pickedId{color:var(--cb-fg);font-variant-numeric:tabular-nums}
859
+ .dshcb-picked{position:relative}
860
+ .dshcb-picked .dshcb-tipHost{position:static;margin-left:5px;vertical-align:-3px}
861
+ .dshcb-picked .dshcb-tip{left:0;bottom:calc(100% + 6px);max-width:min(340px,100%)}
862
+ .dshcb-picked .dshcb-tip::after{display:none}
863
+ .dshcb-rbar{margin-top:8px;display:flex;align-items:center;gap:10px}
864
+ .dshcb-rsCard{margin-top:8px;display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:8px;background:var(--cb-fill);font-size:12px;color:var(--cb-fg2)}
865
+ .dshcb-rsTxt{min-width:0;flex:0 1 auto;overflow-wrap:anywhere}
866
+ .dshcb-rsGap{flex:1 1 auto}
867
+ .dshcb-rsNeed{color:var(--cb-err);font-weight:500}
868
+ .dshcb-rsBar{flex:1 1 auto;min-width:60px;height:4px;border-radius:2px;background:var(--cb-line);overflow:hidden}
869
+ .dshcb-rsBar>i{position:relative;display:block;height:100%;background:var(--cb-accent);transition:width .3s ease;overflow:hidden}
870
+ .dshcb-rsBar:not(.dshcb-rsBar--indet)>i::after{content:"";position:absolute;top:0;bottom:0;left:0;right:0;background-image:linear-gradient(90deg,rgba(255,255,255,0) 0,rgba(255,255,255,.55) 50%,rgba(255,255,255,0) 100%);background-size:32px 100%;background-repeat:repeat-x;animation:dshcb-rsFlow 1.1s linear infinite}
871
+ @keyframes dshcb-rsFlow{from{background-position:-32px 0}to{background-position:32px 0}}
872
+ .dshcb-rsBar--indet>i{width:35%;animation:dshcb-rsMove 1.2s ease-in-out infinite}
873
+ @keyframes dshcb-rsMove{0%{margin-left:-35%}100%{margin-left:100%}}
874
+ .dshcb-input{flex:1 1 auto;min-width:0;height:34px;padding:0 11px;font:inherit;font-size:12px;color:var(--cb-fg);
875
+ background:var(--cb-surface);border:1px solid var(--cb-border);border-radius:10px;outline:none}
876
+ .dshcb-input:focus{border-color:var(--cb-accent)}
877
+ .dshcb-input::placeholder{color:var(--cb-fg4)}
878
+ .dshcb-foot{margin-top:12px;display:flex;align-items:center;gap:8px;font-size:12px;color:var(--cb-fg2)}
879
+ .dshcb-foot input[type=checkbox]{width:15px;height:15px;flex:0 0 15px;margin:0;accent-color:var(--cb-primary)}
880
+ .dshcb-link{margin-left:auto;appearance:none;border:0;background:transparent;font:inherit;font-size:12px;
881
+ color:var(--cb-accent);cursor:pointer;padding:2px 0 2px 4px;white-space:nowrap}
882
+ .dshcb-link:hover{text-decoration:underline}
883
+ .dshcb-link:disabled{opacity:.5;cursor:default;text-decoration:none}
884
+ /* 还原记录:按钮行 + 弹窗 + 重启标记 */
885
+ .dshcb-footBtns{display:flex;align-items:center;gap:10px;margin-left:auto}
886
+ .dshcb-footBtns .dshcb-link{margin-left:0}
887
+ /* 还原记录弹窗:宽度跟着记录文本走(窄记录就窄框,长记录才拉宽到上限再折行) */
888
+ .dshcb-dialog.dshcb-dlgHist{width:fit-content;min-width:min(300px,92vw);max-width:min(760px,92vw)}
889
+ .dshcb-histList{margin:0 24px 24px;max-height:min(52vh,380px);font-variant-numeric:tabular-nums}
890
+ .dshcb-dialog.dshcb-dlgHist .dshcb-dlgHead,.dshcb-dialog.dshcb-dlgHist .dshcb-dlgContent{min-width:0}
891
+ .dshcb-histEmptyLi{color:var(--dsw-alias-label-secondary,var(--cb-fg3))}
892
+ /* 浮层 tips:一次性提示,几秒后自动消失 */
893
+ .dshcb-toast{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);z-index:80;max-width:min(420px,86vw);
894
+ padding:8px 12px;border-radius:10px;font-size:12px;background:#1c1d1f;background-color:#1c1d1f;border:1px solid rgba(255,255,255,.08);backdrop-filter:none;
895
+ box-shadow:0 3px 10px rgba(0,0,0,.06);color:#fff;font-family:system-ui,-apple-system,"Segoe UI","Microsoft YaHei",sans-serif;font-size:12px;line-height:18px;
896
+ animation:dshcb-toastin .16s ease-out}
897
+ .dshcb-toast.ok{border-color:rgba(255,255,255,.16)}
898
+ .dshcb-toast.err{border-color:rgba(255,255,255,.16)}
899
+ body[data-ds-dark-theme] .dshcb-toast.err{border-color:rgba(0,0,0,.10)}
900
+ body[data-ds-dark-theme] .dshcb-toast{background:#f2f3f5;background-color:#f2f3f5;border-color:rgba(0,0,0,.06);box-shadow:0 3px 10px rgba(0,0,0,.3);color:#1b1c1e}
901
+ @keyframes dshcb-toastin{from{opacity:0;transform:translate(-50%,-50%) scale(.96)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
902
+ @media (prefers-reduced-motion: reduce){.dshcb-toast{animation:none}
903
+ .dshcb-spin{animation:none}}
904
+
905
+ .dshcb-qrbox{margin-top:14px;padding:14px;border:1px solid var(--cb-line);border-radius:12px;
906
+ display:flex;flex-direction:column;align-items:center;gap:8px}
907
+ .dshcb-qrhead{font-size:13px;font-weight:600}
908
+ .dshcb-qr{width:180px;height:180px;border-radius:8px;background:#fff}
909
+ .dshcb-qrstate{font-size:11px;color:var(--cb-fg3)}
910
+ .dshcb-qrstate.ok{color:var(--cb-accent)}
911
+ .dshcb-qrhint{font-size:11px;color:var(--cb-fg3);text-align:center}
912
+ .dshcb-btn.sm{height:30px;padding:0 10px;font-size:12px;flex:0 0 auto}
913
+ padding:6px 8px;border-radius:7px;margin-top:6px;user-select:all;white-space:nowrap;overflow-x:auto;overflow-y:hidden;font-variant-numeric:tabular-nums}
914
+ .dshcb-qr.big{width:320px;height:320px;cursor:zoom-out}
915
+ .dshcb-qr{cursor:zoom-in}
916
+ .dshcb-qrrow{display:flex;flex-wrap:wrap;gap:6px 14px;justify-content:center;align-items:center}
917
+ .dshcb-watch{display:flex;flex-wrap:wrap;gap:6px 10px;justify-content:center;align-items:center;font-size:11.5px;color:var(--cb-fg3)}
918
+ .dshcb-linkbtn{padding:0;border:0;background:none;font:inherit;font-size:12px;color:var(--cb-accent);cursor:pointer}
919
+ .dshcb-linkbtn:hover{text-decoration:underline}
920
+ `;
921
+ const cssRestore = ""; // 新版样式已合并进 css
922
+
923
+ function ensureCss() {
924
+ if (typeof document === "undefined") return;
925
+ if (document.getElementById("dshcb-css")) return;
926
+ const el = document.createElement("style");
927
+ el.id = "dshcb-css";
928
+ el.textContent = css + cssRestore;
929
+ document.head.appendChild(el);
930
+ }
931
+
932
+ // 复制文本:优先剪贴板 API,失败退回 textarea + execCommand(桌面 webview 里常有权限限制)
933
+
934
+ async function call(pathname, body) {
935
+ const init = body === undefined
936
+ ? { cache: "no-store" }
937
+ : { method: "POST", headers: { "content-type": "application/json", "x-dshcb-csrf": "1" }, body: JSON.stringify(body || {}) };
938
+ const res = await fetch(API + pathname, init);
939
+ const text = await res.text();
940
+ let json = null;
941
+ try { json = text ? JSON.parse(text) : null; } catch (e) {}
942
+ if (!json) throw new Error("响应不是 JSON(HTTP " + res.status + ")");
943
+ if (json.ok === false) throw new Error(json.error || ("HTTP " + res.status));
944
+ if (!res.ok) throw new Error("HTTP " + res.status);
945
+ return json;
946
+ }
947
+
948
+ function joinNum(label, n) {
949
+ return /[A-Za-z]$/.test(String(label)) ? String(label) + " " + n : String(label) + n;
950
+ }
951
+
952
+ function fmtStamp(s) {
953
+ if (!s) return "—";
954
+ const d = new Date(s);
955
+ if (isNaN(d.getTime())) return String(s);
956
+ const p = (n) => String(n).padStart(2, "0");
957
+ return d.getFullYear() + "-" + p(d.getMonth() + 1) + "-" + p(d.getDate()) + " " + p(d.getHours()) + ":" + p(d.getMinutes());
958
+ }
959
+
960
+ const DIR_KEY = {
961
+ sessions: "dirSessions",
962
+ storages: "dirStorages",
963
+ profiles: "dirProfiles",
964
+ "our-free-model": "dirOurFree",
965
+ "dsh-market": "dirMarket",
966
+ "(根)": "dirRoot",
967
+ };
968
+ const DIR_NOTE_KEY = {
969
+ sessions: "dirSessionsNote",
970
+ storages: "dirStoragesNote",
971
+ profiles: "dirProfilesNote",
972
+ "our-free-model": "dirOurFreeNote",
973
+ "dsh-market": "dirMarketNote",
974
+ "(根)": "dirRootNote",
975
+ };
976
+ function dirLabel(name) {
977
+ return DIR_KEY[name] ? t(DIR_KEY[name]) : String(name);
978
+ }
979
+ function dirRaw(name) {
980
+ return name === "(根)" ? "" : String(name) + "/";
981
+ }
982
+ function dirNote(name) {
983
+ if (DIR_NOTE_KEY[name]) return t(DIR_NOTE_KEY[name]);
984
+ // 工作区目录:DSH 把路径编码成 --C-Users-...-- (分隔符变 -),给他一句人话
985
+ if (/^--.+--$/.test(String(name))) return t("dirWorkspaceNote");
986
+ return "";
987
+ }
988
+
989
+ // 选中项跨“切页面 / 卡片卸载重挂”保留:侧栏换页会卸载再挂载,组件内 state 会回到初始值。
990
+ let rpickKeep = null;
991
+ let pickSelKeep = null;
992
+ // 悬停浮层:模块级 store + 独立组件。悬停只重渲染这一层,不牵动整卡(分段控件因此不会再被连累重排/闪烁)。
993
+ const tipStore = {
994
+ v: null,
995
+ subs: [],
996
+ on: function (fn) { this.subs.push(fn); },
997
+ off: function (fn) { this.subs = this.subs.filter(function (g) { return g !== fn; }); },
998
+ set: function (v) { this.v = v; this.subs.slice().forEach(function (fn) { try { fn(v); } catch (e) { /* 单个订阅者出错不影响其它 */ } }); },
999
+ };
1000
+ // 提示文案压成一行、过长截断(界面只要简短明确,细节看失败原因行与日志)
1001
+ function shortTip(text) {
1002
+ const s0 = String(text === undefined || text === null ? "" : text).replace(/\s+/g, " ").trim();
1003
+ return s0.length > 42 ? s0.slice(0, 42) + "\u2026" : s0;
1004
+ }
1005
+ // 浮层定位:以鼠标为中心、默认在其上方 12px;贴边就翻到指针侧边(近边恒定 12px),最后才钳进视口。
1006
+ function tipPlace(t, w, h) {
1007
+ const pad = 8;
1008
+ const gap = 12;
1009
+ const vw = (typeof window !== "undefined" && window.innerWidth) || 1024;
1010
+ const vh = (typeof window !== "undefined" && window.innerHeight) || 768;
1011
+ let left = w ? t.x - w / 2 : t.x + gap;
1012
+ let top = h ? t.y - h - gap : t.y + gap;
1013
+ if (w) {
1014
+ if (left < pad) left = t.x + gap;
1015
+ if (left + w > vw - pad) left = t.x - w - gap;
1016
+ if (left < pad) left = pad;
1017
+ if (left + w > vw - pad) left = Math.max(pad, vw - w - pad);
1018
+ }
1019
+ if (h) {
1020
+ if (top < pad) top = t.y + gap;
1021
+ if (top + h > vh - pad) top = Math.max(pad, vh - h - pad);
1022
+ if (top < pad) top = pad;
1023
+ }
1024
+ return { left: left, top: top };
1025
+ }
1026
+ let tipRAF = 0;
1027
+ let tipLast = { x: 0, y: 0 };
1028
+ function tipPush(text, x, y, immediate) {
1029
+ if (!text) { tipStore.set(null); return; }
1030
+ if (immediate) { tipLast = { x: x, y: y }; tipStore.set({ text: text, x: x, y: y }); return; }
1031
+ if (Math.abs(x - tipLast.x) < 2 && Math.abs(y - tipLast.y) < 2) return;
1032
+ tipLast = { x: x, y: y };
1033
+ if (tipRAF) return;
1034
+ const schedule = typeof requestAnimationFrame === "function" ? requestAnimationFrame : function (cb) { return setTimeout(cb, 16); };
1035
+ tipRAF = schedule(function () { tipRAF = 0; tipStore.set({ text: text, x: tipLast.x, y: tipLast.y }); });
1036
+ }
1037
+ function TipLayer() {
1038
+ const [, bump] = react.useState(0);
1039
+ const boxRef = react.useRef(null);
1040
+ const size = react.useRef({ w: 0, h: 0 });
1041
+ const t = tipStore.v; // 直接读 store:渲染即最新,不依赖 setState 传值
1042
+ const notify = function () { bump(function (n) { return n + 1; }); };
1043
+ if (tipStore.subs.indexOf(notify) < 0) tipStore.on(notify); // 渲染期懒注册(宿主不跑 effect 时也能订阅)
1044
+ react.useLayoutEffect(function () {
1045
+ const el = boxRef.current;
1046
+ if (!el) return;
1047
+ const w = el.offsetWidth || 0;
1048
+ const h = el.offsetHeight || 0;
1049
+ if (!w || (size.current.w === w && size.current.h === h)) return;
1050
+ size.current = { w: w, h: h };
1051
+ notify();
1052
+ });
1053
+ react.useEffect(function () {
1054
+ if (!t) return undefined;
1055
+ const clear = function () { tipStore.set(null); };
1056
+ if (typeof window !== "undefined") {
1057
+ window.addEventListener("scroll", clear, true);
1058
+ window.addEventListener("resize", clear);
1059
+ }
1060
+ return function () {
1061
+ if (typeof window !== "undefined") {
1062
+ window.removeEventListener("scroll", clear, true);
1063
+ window.removeEventListener("resize", clear);
1064
+ }
1065
+ };
1066
+ }, [!!t]);
1067
+ if (!t || !t.text) return null;
1068
+ const pos = tipPlace(t, size.current.w, size.current.h);
1069
+ return react_jsx_runtime.jsx("span", { className: "dshcb-hoverTip", ref: boxRef,
1070
+ style: { left: pos.left + "px", top: pos.top + "px" }, children: t.text }, "rowtip");
1071
+ }
1072
+
1073
+ function CloudBackupCard() {
1074
+ const [status, setStatus] = react.useState(null);
1075
+ // ① 一次性结果 / 失败原因 → showTip 浮层,几秒后自动消失,不占版面
1076
+ const [tip, setTip] = react.useState(null);
1077
+ const tipSeq = react.useRef(0);
1078
+ const tipTimer = react.useRef({ handle: null, remain: 0, startedAt: 0 });
1079
+ const showTip = function (text, kind) {
1080
+ if (!text) return;
1081
+ tipSeq.current += 1;
1082
+ const id = tipSeq.current;
1083
+ setTip({ text: String(text).replace(/\s+/g, " ").trim(), kind: kind || "info", id: id });
1084
+ const ms = kind === "err" ? 4000 : kind === "ok" ? 3000 : 2400;
1085
+ tipTimer.current.remain = ms;
1086
+ tipTimer.current.startedAt = Date.now();
1087
+ clearTimeout(tipTimer.current.handle);
1088
+ tipTimer.current.handle = setTimeout(function () {
1089
+ setTip(function (cur) { return cur && cur.id === id ? null : cur; });
1090
+ }, ms);
1091
+ };
1092
+ const tipHold = function (on) {
1093
+ const t = tipTimer.current;
1094
+ if (on) {
1095
+ if (!t.handle) return;
1096
+ clearTimeout(t.handle);
1097
+ t.handle = null;
1098
+ t.remain = Math.max(600, t.remain - (Date.now() - t.startedAt));
1099
+ } else if (t.remain > 0) {
1100
+ t.startedAt = Date.now();
1101
+ t.handle = setTimeout(function () { setTip(null); }, t.remain);
1102
+ }
1103
+ };
1104
+ const setError = function (m) { if (m) showTip(m, "err"); };
1105
+ // 兼容自检只报异常:宿主版本超出声明范围(或声明本身不可解析)时用浮层提示一次,正常时面板上不出现。
1106
+ const compatSaid = react.useRef(false);
1107
+ react.useEffect(function () {
1108
+ const c = status && status.compat;
1109
+ if (!c || compatSaid.current || c.ok === true) return;
1110
+ const r = String(c.declared || "");
1111
+ if (c.ok === false) {
1112
+ compatSaid.current = true;
1113
+ showTip(r ? t("compatBad").replace("{v}", String(c.runtime || "?")).replace("{r}", r) : t("compatNone"), "err");
1114
+ } else if (c.reason === "bad-range") {
1115
+ compatSaid.current = true;
1116
+ showTip(t("compatBadRange").replace("{r}", r), "err");
1117
+ }
1118
+ }, [status && status.compat ? String(status.compat.ok) + "|" + String(status.compat.reason) : ""]);
1119
+ const [error] = react.useState(null);
1120
+ const [busy, setBusy] = react.useState(false);
1121
+ // 连接类动作(断连/验证/扫码/免扫码)各自计忙:不占用「立即备份」的 busy,避免误显示「处理中…」
1122
+ const [authBusy, setAuthBusy] = react.useState("");
1123
+ const [qr, setQr] = react.useState(null);
1124
+ const [qrState, setQrState] = react.useState("new"); // new | scanned | done | expired
1125
+ const [left, setLeft] = react.useState(0);
1126
+ const [bstate, setBstate] = react.useState({ running: false, note: "" });
1127
+ const [snaps, setSnaps] = react.useState(null); // { items:[], totals:{} }
1128
+ // 下载收尾后会接着跑还原 / 预览:那些回调闭包来自发起时的那次渲染,
1129
+ // 直接用 snaps 会看到「还没下载」的旧状态,于是又弹一次下载确认
1130
+ const snapsRef = react.useRef(null);
1131
+ snapsRef.current = snaps;
1132
+ const snapCache = react.useRef(null); // 上次成功的结果(切面板先渲染,不白屏)
1133
+ const [slowList, setSlowList] = react.useState(false); // 加载提示延迟出现:有缓存时不再闪字
1134
+ react.useEffect(function () {
1135
+ if (snaps) { setSlowList(false); return; }
1136
+ const id = setTimeout(function () { setSlowList(true); }, 180);
1137
+ return function () { clearTimeout(id); };
1138
+ }, [!!snaps]);
1139
+ const treeCache = react.useRef({}); // stamp -> { root, nodes }:展开时先给上次结果
1140
+ const [rpick, setRpickState] = react.useState(rpickKeep); // 选中的 stamp(还原目标;跨重挂载保留)
1141
+ const setRpick = function (v) {
1142
+ const next = typeof v === "function" ? v(rpickKeep) : v;
1143
+ rpickKeep = next;
1144
+ setRpickState(next);
1145
+ };
1146
+ const [rexpand, setRexpand] = react.useState(null); // 展开目录树的 stamp(点同一行可收起)
1147
+ const [rtarget, setRtarget] = react.useState(""); // 还原目标目录
1148
+ const [rconfirm, setRconfirm] = react.useState(true); // 默认勾选:目标为当前 DSH_HOME 时仍会先弹宿主风格确认框
1149
+ const [rstate, setRstate] = react.useState({ busy: "", note: "", result: null });
1150
+ const [rsProg, setRsProg] = react.useState(null); // 还原进度 { done, total, cancelled }:还原期间轮询 /status
1151
+ const [batch, setBatch] = react.useState(false);
1152
+ const [bsel, setBsel] = react.useState([]);
1153
+ const [batchAt, setBatchAt] = react.useState("");
1154
+ const [pickSel, setPickSelState] = react.useState(pickSelKeep); // { stamp, on }:还原前勾选(默认全选,跨重挂载保留)
1155
+ const setPickSel = function (v) {
1156
+ const next = typeof v === "function" ? v(pickSelKeep) : v;
1157
+ pickSelKeep = next;
1158
+ setPickSelState(next);
1159
+ };
1160
+ const [pullPaused, setPullPaused] = react.useState(false); // 下载暂停(后端同样保留进度)
1161
+ const [viewBusy, setViewBusy] = react.useState(false);
1162
+ const [qrBig, setQrBig] = react.useState(false);
1163
+ const [rhist, setRhist] = react.useState(null);
1164
+ // 还原提示只在“用户这次真的点了还原”之后出现,打开面板不显示;30 秒后自动收起,也可手动关掉
1165
+ const [lrNote, setLrNote] = react.useState(null);
1166
+ const lrTimer = react.useRef(null);
1167
+ const [histOpen, setHistOpen] = react.useState(false); // 面板内放大二维码(手机好扫) // 切视图时后台刷新中
1168
+ function copyText(txt) {
1169
+ try {
1170
+ if (typeof navigator !== "undefined" && navigator.clipboard && navigator.clipboard.writeText) {
1171
+ navigator.clipboard.writeText(txt).catch(function () { copyTextFallback(txt); });
1172
+ return true;
1173
+ }
1174
+ } catch (e) {}
1175
+ return copyTextFallback(txt);
1176
+ }
1177
+ function copyTextFallback(txt) {
1178
+ try {
1179
+ const ta = document.createElement("textarea");
1180
+ ta.value = txt;
1181
+ ta.setAttribute("readonly", "readonly");
1182
+ ta.style.position = "fixed";
1183
+ ta.style.left = "-9999px";
1184
+ document.body.appendChild(ta);
1185
+ ta.select();
1186
+ const okk = document.execCommand && document.execCommand("copy");
1187
+ document.body.removeChild(ta);
1188
+ return !!okk;
1189
+ } catch (e) { return false; }
1190
+ }
1191
+
1192
+ function openLoginInBrowser() {
1193
+ const url = loginPageUrl();
1194
+ if (!url) return;
1195
+ try {
1196
+ window.open(url, "_blank", "noopener,noreferrer");
1197
+ } catch (e) { /* 静默:真打不开可用「复制链接」 */ }
1198
+ startWatch(); // 打开登录页就开始等:登录一完成就自动导入
1199
+ }
1200
+ const watchRef = react.useRef(null);
1201
+ const [watch, setWatch] = react.useState(null);
1202
+ function stopWatch(reason) {
1203
+ const w = watchRef.current;
1204
+ if (!w) return;
1205
+ watchRef.current = null;
1206
+ if (w.timer) clearTimeout(w.timer);
1207
+ // 超时:把「等待中」原地换成一句提示,并留一个取消按钮,而不是悄悄消失
1208
+ setWatch(reason === "timeout" ? { timeout: true } : null);
1209
+ }
1210
+ function startWatch() {
1211
+ if (watchRef.current) return;
1212
+ const st = { since: Date.now(), deadline: Date.now() + 90000, tries: 0, timer: null };
1213
+ watchRef.current = st;
1214
+ setWatch({ since: st.since, tries: 0 });
1215
+ const tick = async function () {
1216
+ const cur = watchRef.current;
1217
+ if (!cur) return;
1218
+ cur.tries += 1;
1219
+ setWatch({ since: cur.since, tries: cur.tries });
1220
+ try {
1221
+ const r = await call("/auth/watch-local", { since: cur.since });
1222
+ if (r && r.found) {
1223
+ const imp = await call("/auth/import-local", { since: cur.since });
1224
+ if (imp && imp.imported) {
1225
+ stopWatch();
1226
+ setError(null);
1227
+ setQrState("done");
1228
+ setQr(null);
1229
+ showTip(t("watchAutoDone"), "ok");
1230
+ await refresh();
1231
+ return;
1232
+ }
1233
+ }
1234
+ } catch (e) { /* 探测失败不打断等待 */ }
1235
+ if (Date.now() > cur.deadline) { stopWatch("timeout"); return; }
1236
+ cur.timer = setTimeout(tick, 2000);
1237
+ };
1238
+ st.timer = setTimeout(tick, 1200);
1239
+ }
1240
+ const WEB_LOGIN_URL = "https://www.alipan.com/sign/in";
1241
+ function loginPageUrl() { return WEB_LOGIN_URL; }
1242
+ const [sbusy, setSbusy] = react.useState(""); // "" | list | prune-plan | prune-run
1243
+ const [rowBusy, setRowBusy] = react.useState(""); // 行内「重试」只让这一行转,不动整表
1244
+ const [prune, setPrune] = react.useState({ plan: null, note: "" });
1245
+ const [infoOpen, setInfoOpen] = react.useState(false); // 「连接状态…凭据加密」抽屉(默认收起)
1246
+ const [menu, setMenu] = react.useState(false); // 「更多 ⋮」下拉菜单
1247
+ // 弹窗(对齐宿主 Modal 样式):askDlg 返回 Promise<boolean>,遮罩/取消/Esc 一律 false
1248
+ const [dlg, setDlg] = react.useState(null);
1249
+ // 排队:同一时刻只显示一个弹窗。若弹窗未关又有人要问,后来的排在队尾,
1250
+ // 前一个答完再显示——否则单槽覆盖会让先前的调用方永远 await。
1251
+ const dlgQueue = react.useRef([]);
1252
+ const askDlg = function (spec) {
1253
+ return new Promise(function (resolve) {
1254
+ const q = dlgQueue.current;
1255
+ const idle = q.length === 0;
1256
+ q.push({ spec: spec, resolve: resolve });
1257
+ if (idle) setDlg(spec);
1258
+ });
1259
+ };
1260
+ const answerDlg = function (ok) {
1261
+ const q = dlgQueue.current;
1262
+ const head = q.shift();
1263
+ if (head) { try { head.resolve(!!ok); } catch (e) { /* 忽略:调用方已卸载 */ } }
1264
+ setDlg(q.length ? q[0].spec : null);
1265
+ };
1266
+ react.useEffect(function () {
1267
+ if (!dlg) return;
1268
+ const onKey = function (ev) { if (ev.key === "Escape") answerDlg(false); };
1269
+ document.addEventListener("keydown", onKey);
1270
+ return function () { document.removeEventListener("keydown", onKey); };
1271
+ }, [dlg]);
1272
+ // 卸载兜底:组件销毁时若弹窗仍挂着,把 Promise 收掉,避免调用方永久 await
1273
+ react.useEffect(function () {
1274
+ return function () {
1275
+ if (pullPollRef.current) { try { clearInterval(pullPollRef.current); } catch (e) { /* 忽略 */ } pullPollRef.current = null; }
1276
+ const q = dlgQueue.current;
1277
+ dlgQueue.current = [];
1278
+ q.forEach(function (it) { try { it.resolve(false); } catch (e) { /* 忽略:调用方已卸载 */ } });
1279
+ };
1280
+ }, []);
1281
+ react.useEffect(function () {
1282
+ if (!menu) return;
1283
+ const onDown = function (ev) {
1284
+ const el = ev.target;
1285
+ if (el && el.closest && el.closest(".dshcb-morewrap")) return;
1286
+ setMenu(false);
1287
+ };
1288
+ document.addEventListener("pointerdown", onDown, true);
1289
+ return function () { document.removeEventListener("pointerdown", onDown, true); };
1290
+ }, [menu]);
1291
+ const [schedBusy, setSchedBusy] = react.useState(false);
1292
+ const [schedDraft, setSchedDraft] = react.useState(null); // 乐观本地值:点击立刻跟手,服务端回来再对齐
1293
+ const schedNextDraftState = react.useState(null); // 乐观的下次自动备份时间
1294
+ const schedNextDraft = schedNextDraftState[0], setSchedNextDraft = schedNextDraftState[1];
1295
+ const schedSeq = react.useRef(0); // 快速连点保护:只认最后一次请求的结果
1296
+ const [tree, setTree] = react.useState({ stamp: null, loading: false, root: null, nodes: [], error: "" });
1297
+ const [pullInfo, setPullInfo] = react.useState(null); // { done, total, bytes }:下载状态(轮询 /status)
1298
+ const loadSnapsRetry = react.useRef(null);
1299
+ const attachedRef = react.useRef(false); // 正在显示「别人的」在途下载进度
1300
+ const pendingPullRef = react.useRef(null); // 因已有下载被挡下的那次请求,等当前下载结束后自动开始 // 预热/自动对齐的静默重试定时器
1301
+
1302
+ const refresh = react.useCallback(async function () {
1303
+ try { setStatus(await call("/status")); setError(null); }
1304
+ catch (e) { setError(String((e && e.message) || e)); }
1305
+ }, []);
1306
+
1307
+ react.useEffect(function () {
1308
+ ensureCss(); refresh(); loadSnaps(false);
1309
+ // 预热云端缓存(静默,失败不影响本地视图)
1310
+ const warm = setTimeout(function () {
1311
+ loadSnaps(true).catch(function () {});
1312
+ loadSnapsRetry.current = setTimeout(function () { loadSnaps(true).catch(function () {}); }, 2600);
1313
+ }, 400);
1314
+ // 状态自动更新:面板可见时每 20 秒对齐一次(走缓存,不打云端)
1315
+ const auto = (typeof setInterval === "function") ? setInterval(function () {
1316
+ try {
1317
+ if (typeof document !== "undefined" && document.visibilityState && document.visibilityState !== "visible") return;
1318
+ } catch (e) {}
1319
+ refresh().catch(function () {});
1320
+ loadSnaps(false).catch(function () {});
1321
+ }, 20000) : null;
1322
+ // 在途下载的接管:进度是后端单例,重开面板/换页回来同样可见
1323
+ const tick = function () {
1324
+ try {
1325
+ if (typeof document !== "undefined" && document.visibilityState && document.visibilityState !== "visible") return;
1326
+ } catch (e) {}
1327
+ call("/status").then(function (st) {
1328
+ const p = st && st.pull;
1329
+ if (p && (p.active || p.paused)) {
1330
+ attachedRef.current = true;
1331
+ setPullPaused(!!p.paused);
1332
+ setPullInfo({ stamp: p.stamp || null, done: p.done || 0, total: p.total || 0, bytes: p.bytes || 0,
1333
+ needBytes: p.needBytes || 0, all: p.all || 0, present: p.present || 0, paused: !!p.paused,
1334
+ scope: p.scope || 0, scopeFiles: p.scopeFiles || 0, ready: p.ready || 0 });
1335
+ return;
1336
+ }
1337
+ if (!attachedRef.current) return;
1338
+ attachedRef.current = false;
1339
+ setPullInfo(null);
1340
+ const q = pendingPullRef.current;
1341
+ pendingPullRef.current = null;
1342
+ if (q) { doPull(q); } else { loadSnaps({ fresh: false }).catch(function () {}); }
1343
+ }).catch(function () {});
1344
+ };
1345
+ const watchTimer = (typeof setInterval === "function") ? setInterval(tick, 1500) : null;
1346
+ tick(); // 先立即对一次:打开面板就能看到已经在跑的下载,不用等 1.5 秒
1347
+ return function () { clearTimeout(warm); if (loadSnapsRetry.current) clearTimeout(loadSnapsRetry.current); if (auto) clearInterval(auto); if (watchTimer) clearInterval(watchTimer); };
1348
+ }, [refresh]);
1349
+
1350
+ react.useEffect(function () {
1351
+ if (!qr) return undefined;
1352
+ let stopped = false;
1353
+ let inflight = false; // 慢响应保护:上一次请求未返回前不再发起下一次
1354
+ let nextMs = POLL_MS;
1355
+ const tickOnce = async function () {
1356
+ if (stopped) return;
1357
+ setLeft(Math.max(0, Math.ceil((qr.expiresAt - Date.now()) / 1000)));
1358
+ if (Date.now() > qr.expiresAt) { setQrState("expired"); setQr(null); return; }
1359
+ try {
1360
+ const r = await call("/auth/qr/poll", { sessionId: qr.sessionId });
1361
+ if (Number.isFinite(r && r.nextPollMs) && r.nextPollMs > 0) {
1362
+ nextMs = Math.min(Math.max(Number(r.nextPollMs), 600), 4000);
1363
+ }
1364
+ if (stopped) return;
1365
+ if (r.status === "connected" || r.status === "confirmed") { setQrState("done"); setQr(null); await refresh(); return; }
1366
+ if (r.status === "scanned") setQrState("scanned");
1367
+ else if (r.status === "connecting") {
1368
+ setQrState("connecting");
1369
+ if (r.attempt) setQr(function (q) { return q ? Object.assign({}, q, { attempt: r.attempt }) : q; });
1370
+ }
1371
+ else if (r.status === "failed") {
1372
+ setQrState("failed");
1373
+ setError((r.reason || t("qrFailed")) + (r.diagPath ? " · " + t("qrDiagAt") + r.diagPath : "") + (r.bizExtRawPath ? " · " + r.bizExtRawPath : ""));
1374
+ setQr(null);
1375
+ return;
1376
+ }
1377
+ else if (r.status === "expired") { setQrState("expired"); setQr(null); return; }
1378
+ } catch (e) { setError(String((e && e.message) || e)); }
1379
+ };
1380
+ const tick = async function () {
1381
+ if (stopped || inflight) return;
1382
+ inflight = true;
1383
+ try { await tickOnce(); } finally { inflight = false; }
1384
+ };
1385
+ let timer = null;
1386
+ const loop = async function () {
1387
+ await tick();
1388
+ if (!stopped) timer = setTimeout(loop, nextMs);
1389
+ };
1390
+ loop();
1391
+ return function () { stopped = true; if (timer) clearTimeout(timer); };
1392
+ }, [qr && qr.sessionId, refresh]);
1393
+
1394
+ const startQr = async function () {
1395
+ setAuthBusy("qr");
1396
+ try {
1397
+ const r = await call("/auth/qr/start", {});
1398
+ setError(null);
1399
+ setQrState("new");
1400
+ setQr({
1401
+ sessionId: r.sessionId, qr: r.qr, url: r.qrUrl || null,
1402
+ page: r.pageUrlAbs || r.pageUrl, pageAbs: r.pageUrlAbs || "" || null, oauth: r.oauthUrl || null,
1403
+ expiresAt: Date.now() + (r.expiresInSec || 180) * 1000,
1404
+ });
1405
+ } catch (e) { setError(String((e && e.message) || e)); setQrState("error"); }
1406
+ finally { setAuthBusy(""); }
1407
+ };
1408
+
1409
+ const doImportLocal = async function () {
1410
+ setAuthBusy("import");
1411
+ try {
1412
+ await call("/auth/import-local", {});
1413
+ setError(null);
1414
+ setQrState("done");
1415
+ setQr(null);
1416
+ await refresh();
1417
+ } catch (e) { setError(String((e && e.message) || e)); }
1418
+ finally { setAuthBusy(""); }
1419
+ };
1420
+
1421
+ const doBackup = async function () {
1422
+ setBusy(true); setBstate({ running: true, note: "" });
1423
+ try {
1424
+ const r = await call("/backup/run", { confirm: true });
1425
+ const res = (r && r.result) || {};
1426
+ const u = res.upload;
1427
+ const refused = res.ok === false ? (t("backupSkip") + (res.reason || "unknown")) : null;
1428
+ // 同步云盘关闭时,上传被有意跳过 → 明确告诉用户“只存在本机”,别让人以为备份没做
1429
+ const skipped = res.ok !== false && syncOn === false ? t("savedLocalOnly") : "";
1430
+ setError(refused);
1431
+ setBstate({ running: false, note: skipped || (u ? (u.ok ? "" : String(u.error || "")) : "") });
1432
+ await refresh();
1433
+ if (res.ok !== false && res.snapshot) {
1434
+ const st = res.snapshot;
1435
+ const cloudOkRow = !(u && u.ok === false);
1436
+ setSnaps(function (cur) {
1437
+ const items = (cur && cur.items) || [];
1438
+ if (items.some(function (y) { return y.stamp === st; })) return cur;
1439
+ const row = { stamp: st, state: cloudOkRow ? "uploaded" : "pending", inCloud: cloudOkRow, hasCache: true,
1440
+ files: res.files || null, bytes: res.bytes || null, createdAt: null, uploadedAt: null, cacheBytes: 0 };
1441
+ return { items: [row].concat(items), totals: (cur && cur.totals) || {}, cloud: (cur && cur.cloud) || null,
1442
+ cloudOk: cur ? cur.cloudOk : true };
1443
+ });
1444
+ setRpick(function (p) { return p || st; });
1445
+ loadSnaps({ fresh: true }).catch(function () {});
1446
+ }
1447
+ if (refused) setError(refused);
1448
+ } catch (e) {
1449
+ setError(String((e && e.message) || e));
1450
+ setBstate({ running: false, note: "" });
1451
+ } finally { setBusy(false); }
1452
+ };
1453
+
1454
+ const doOpenLogs = async function () {
1455
+ try {
1456
+ const r = await call("/logs/open", {});
1457
+ showTip((r && r.dir) ? (t("logsOpened") + ":" + r.dir) : t("logsOpened"), "ok");
1458
+ } catch (e) {
1459
+ showTip(String((e && e.message) || e), "err");
1460
+ }
1461
+ };
1462
+ const doVerify = async function () {
1463
+ setAuthBusy("verify");
1464
+ try { await call("/auth/verify", {}); setError(null); await refresh(); }
1465
+ catch (e) { setError(String((e && e.message) || e)); }
1466
+ finally { setAuthBusy(""); }
1467
+ };
1468
+
1469
+ const doDisconnect = async function () {
1470
+ setAuthBusy("disconnect");
1471
+ try { await call("/auth/logout", { confirm: true }); setQr(null); await refresh(); }
1472
+ catch (e) { setError(String((e && e.message) || e)); }
1473
+ finally { setAuthBusy(""); }
1474
+ };
1475
+
1476
+ // remote:调用方的目标视图;opts.fresh = 跳过服务端 45s 清单缓存(切换视图 / 变更后必用)
1477
+ const loadSnaps = async function (opts) {
1478
+ const fresh = !!(opts && opts.fresh);
1479
+ try {
1480
+ const r = await call("/backups" + (fresh ? "?fresh=1" : ""));
1481
+ const obj = { items: r.items || [], totals: r.totals || {}, cloud: r.cloud || null, cloudOk: r.cloudOk !== false && !(r.cloud && r.cloud.ok === false) };
1482
+ snapCache.current = obj;
1483
+ setSnaps(obj);
1484
+ // 可还原 = 云端有或本机有缓存;默认取最新一条,退回首条
1485
+ const usable = obj.items.filter(function (x) { return x.hasCache || x.inCloud; });
1486
+ const first = usable[0] || obj.items[0];
1487
+ // 必须函数式判断:loadSnaps 会被 20s 自动对齐用“挂载时”的闭包调用,直接读 rpick 会拿到 null 并覆盖用户的选择
1488
+ if (first) setRpick(function (p) {
1489
+ const alive = p && obj.items.some(function (x) { return x.stamp === p; });
1490
+ return alive ? p : first.stamp;
1491
+ });
1492
+ return true;
1493
+ } catch (e) { setError(String((e && e.message) || e)); return false; }
1494
+ };
1495
+
1496
+ // 只有「云端有、本地缓存已清」的快照才需要先下载;到点击那一刻才问,界面上不常驻提示
1497
+ const pendAct = react.useRef(""); // 下载完成后要接着做的事:run | preview
1498
+ const pullPollRef = react.useRef(null); // 下载进度轮询:卸载时要能清掉
1499
+ const needDownload = function (stamp) {
1500
+ const y = (((snapsRef.current && snapsRef.current.items) || [])).filter(function (it) { return it.stamp === stamp; })[0];
1501
+ return !!(y && y.hasCache === false && y.inCloud === true);
1502
+ };
1503
+ const gateDownload = async function (act) {
1504
+ if (!rpick || !needDownload(rpick)) return true;
1505
+ const go = await askDlg({ title: t("dlAskTitle"), lead: t("dlAskLead"), confirm: t("dlAskOk"), cancel: t("dlAskNo") });
1506
+ if (!go) return false;
1507
+ pendAct.current = act;
1508
+ doPull(rpick);
1509
+ return false;
1510
+ };
1511
+ // 云端拒绝时(授权失效 / 凭据不完整):就地给一个重新登录入口
1512
+ const doRelogin = function () { openLoginInBrowser(); };
1513
+
1514
+ const doPreview = async function (skipGate) {
1515
+ if (!rpick) { setError(t("restorePickFirst")); return; }
1516
+ if (!skipGate && !(await gateDownload("preview"))) return;
1517
+ setRstate({ busy: "preview", note: "", result: null });
1518
+ try {
1519
+ const r = await call("/restore/preview", { stamp: rpick, targetRoot: rtarget || undefined, overwrite: rconfirm });
1520
+ const p = r.preview || {};
1521
+ setRstate({ busy: "", note: t("restoreTarget") + ": " + r.targetRoot + "\n"
1522
+ + "total " + p.total + " / write " + p.willWrite + " / skip " + p.willSkip
1523
+ + " / overwrite " + p.willOverwrite + " / " + t("restoreMiss") + " " + p.missingBlobs
1524
+ + " / " + fmtSize(p.bytes), result: null });
1525
+ setError(null);
1526
+ } catch (e) { setError(String((e && e.message) || e)); setRstate({ busy: "", note: "", result: null }); }
1527
+ };
1528
+
1529
+ const normPath = function (p) { return String(p || "").trim().replace(/[\\/]+$/, "").toLowerCase(); };
1530
+ const dshHome = function () { return (status && status.restore && status.restore.dshHome) || ""; };
1531
+ const hitsHome = function () {
1532
+ const h = dshHome();
1533
+ if (!h) return false;
1534
+ const typed = normPath(rtarget);
1535
+ return typed ? typed === normPath(h) : true;
1536
+ };
1537
+
1538
+ const [withPlugins, setWithPlugins] = react.useState(true); // 默认勾选:快照里带插件时一并装回
1539
+
1540
+ const doPluginPrompt = async function () {
1541
+ if (!rpick) return;
1542
+ try {
1543
+ const r = await call("/plugins/prompt?stamp=" + encodeURIComponent(rpick));
1544
+ if (!r || !r.text) { setError(t("pluginPromptFail") + " " + ((r && r.error) || "")); return; }
1545
+ // 先让用户看到内容再决定:弹窗里可滚动阅读,确认按钮即「复制」
1546
+ const go = await askDlg({ title: t("promptTitle"), lead: t("promptLead"), text: r.text, confirm: t("dlgCopy") });
1547
+ if (!go) return;
1548
+ const copied = await copyText(r.text);
1549
+ showTip(copied ? t("promptCopied") : t("pluginPromptFail") + "(请手动复制)", copied ? "ok" : "err");
1550
+ } catch (e) { setError(t("pluginPromptFail") + String((e && e.message) || e)); }
1551
+ };
1552
+
1553
+ // 还原期间只轮询 /status:面板此时被这次还原占着,别再发别的请求
1554
+ react.useEffect(function () {
1555
+ if (rstate.busy !== "run") { setRsProg(null); return undefined; }
1556
+ let stop = false;
1557
+ const tick = async function () {
1558
+ try {
1559
+ const st2 = await call("/status");
1560
+ if (!stop) setRsProg((st2 && st2.restore && st2.restore.progress) || null);
1561
+ } catch (e) { /* 读不到进度不影响还原本身 */ }
1562
+ };
1563
+ tick();
1564
+ const tm = setInterval(function () { tick(); }, 700);
1565
+ return function () { stop = true; clearInterval(tm); };
1566
+ }, [rstate.busy]);
1567
+
1568
+ // 取消:只请求停止后续写入,正在写的那一个照写完;已写入的保留,不再自动回滚
1569
+ const doCancelRestore = async function () {
1570
+ setRsProg(function (p) { return Object.assign({ cancelled: true }, p || {}); });
1571
+ try { await call("/restore/cancel", {}); } catch (e) { setError(String((e && e.message) || e)); }
1572
+ };
1573
+
1574
+ const doRestore = async function (skipGate) {
1575
+ if (!rpick) { setError(t("restorePickFirst")); return; }
1576
+ if (!skipGate && !(await gateDownload("run"))) return;
1577
+ // 后端对 DSH_HOME 目标强制 confirm:true(lib/index.js restore/run);这里先弹宿主风格确认框,确认后才带上该字段
1578
+ const home = hitsHome();
1579
+ if (home) {
1580
+ const go = await askDlg({
1581
+ title: t("homeAskTitle"),
1582
+ lead: t("homeAskLead"),
1583
+ summary: t("homeAskTo") + ": " + dshHome(),
1584
+ lines: [t("homeAskL1"), t("homeAskL2")],
1585
+ skip: "",
1586
+ confirm: t("homeAskYes"),
1587
+ });
1588
+ if (!go) { setRstate({ busy: "", note: "", result: null }); setError(null); return; }
1589
+ }
1590
+ setRstate({ busy: "run", note: "", result: null });
1591
+ try {
1592
+ const r = await call("/restore/run", { stamp: rpick, targetRoot: rtarget || undefined, overwrite: rconfirm,
1593
+ rels: pickRels(rpick), confirm: home ? true : undefined, plugins: withPlugins === true });
1594
+ const x = r.result || {};
1595
+ setRstate({ busy: "", note: "", result: x });
1596
+ setError(null);
1597
+ if (x.stopped) showTip(t("rsCancelled"), "info");
1598
+ await loadSnaps({ fresh: true });
1599
+ await refresh(); // 立刻把“上次还原 / 需重启”读回来,不必等 20 秒的自动对齐
1600
+ try {
1601
+ const st2 = await call("/status");
1602
+ showLrNote((st2 && st2.backup && st2.backup.lastRestore) || null, !!(st2 && st2.backup && st2.backup.needsRestart));
1603
+ } catch (e) { showLrNote({ at: new Date().toISOString(), stamp: rpick, restored: x.restored || 0, skipped: x.skipped || 0, plugins: x.plugins || null, targetRoot: x.targetRoot || "" }); }
1604
+ } catch (e) { setError(String((e && e.message) || e)); setRstate({ busy: "", note: "", result: null }); }
1605
+ };
1606
+
1607
+ // 自重启:后端只负责排计划与接管端口,这里把“点了之后到进程退出”这段时间交代清楚
1608
+ const doRestartHost = async function () {
1609
+ if (rstate.busy) return;
1610
+ setRstate(function (r) { return Object.assign({}, r, { busy: "restart" }); });
1611
+ try {
1612
+ const r = await call("/restart", { confirm: true });
1613
+ const portTxt = (r && r.port) ? (" · " + t("restartPort") + r.port) : "";
1614
+ showTip(t("restartDone") + portTxt, "ok");
1615
+ } catch (e) {
1616
+ setRstate(function (r) { return Object.assign({}, r, { busy: "" }); });
1617
+ setError(String((e && e.message) || e));
1618
+ }
1619
+ };
1620
+
1621
+ const doPull = async function (stamp) {
1622
+ const which = (typeof stamp === "string" && stamp) || rpick;
1623
+ if (!which) { setError(t("restorePickFirst")); return; }
1624
+ setRpick(function (p) { return p || which; });
1625
+ setRstate({ busy: "pull", note: "", result: null });
1626
+ setPullPaused(false);
1627
+ setPullInfo({ done: 0, total: 0, bytes: 0 });
1628
+ let stopPoll = false;
1629
+ let idlePolls = 0;
1630
+ let attached = false; // 被已有下载挡下时:接管进度,别清掉刚设好的进度行
1631
+ let live = false; // 后端还在下载:轮询要继续跑,别在 finally 里把它掐掉
1632
+ const pollTimer = pullPollRef.current = (typeof setInterval === "function")
1633
+ ? setInterval(async function () {
1634
+ if (stopPoll) return;
1635
+ try {
1636
+ const st2 = await call("/status");
1637
+ const p = st2 && st2.pull;
1638
+ if (p && (p.active || p.paused)) {
1639
+ idlePolls = 0;
1640
+ setPullPaused(!!p.paused);
1641
+ setPullInfo({ stamp: p.stamp || which, done: p.done || 0, total: p.total || 0, bytes: p.bytes || 0,
1642
+ needBytes: p.needBytes || 0, all: p.all || 0, present: p.present || 0, paused: !!p.paused,
1643
+ scope: p.scope || 0, scopeFiles: p.scopeFiles || 0, ready: p.ready || 0 });
1644
+ return;
1645
+ }
1646
+ // 后端已经不在下载了:进度与忙碌态就地收尾,避免界面停在「下载中」
1647
+ idlePolls += 1;
1648
+ if (idlePolls >= 3) {
1649
+ stopPoll = true;
1650
+ pullPollRef.current = null; if (pollTimer) clearInterval(pollTimer);
1651
+ setPullInfo(null);
1652
+ // 下载已结束:把列表与按钮状态刷回正常(工具条与「立即还原」按 rstate 恢复)
1653
+ setRstate(function (r) { return r && r.busy === "pull" ? { busy: "", note: r.note || "", result: r.result || null } : r; });
1654
+ try { await loadSnaps({ fresh: false }); } catch (e) { /* 刷新失败不影响 */ }
1655
+ // 下载是为某个动作服务的:下完就接着做,不让用户再点一次
1656
+ const act = pendAct.current; pendAct.current = "";
1657
+ if (act === "run") { try { await doRestore(true); } catch (e) { /* 已报错 */ } }
1658
+ else if (act === "preview") { try { await doPreview(true); } catch (e) { /* 已报错 */ } }
1659
+ }
1660
+ } catch (e) { /* 轮询失败不影响主流程 */ }
1661
+ }, 1200)
1662
+ : null;
1663
+ try {
1664
+ const rels = pickRels(which);
1665
+ if (rels && !rels.length) { setRstate({ busy: "", note: "", result: null }); setError(t("selEmpty")); return; }
1666
+ const r = await call("/restore/from-cloud", { stamp: which, rels });
1667
+ const p = r.pull || {};
1668
+ // 暂停:后端已经停下并保留进度,界面保持“可继续”
1669
+ if (p.paused) {
1670
+ setPullPaused(true);
1671
+ setPullInfo({ stamp: which, done: p.downloaded || 0, total: p.total || 0, bytes: p.bytes || 0,
1672
+ needBytes: p.needBytes || 0, all: p.all || 0, present: p.present || 0, paused: true,
1673
+ scope: p.scope || 0, scopeFiles: p.scopeFiles || 0, ready: p.ready || 0 });
1674
+ setRstate({ busy: "", note: "", result: null });
1675
+ setError(null);
1676
+ return;
1677
+ }
1678
+ // 部分块没下来:如实报错(别显示成“下载完成”)
1679
+ if (p.ok === false && p.error) {
1680
+ pendAct.current = "";
1681
+ setRstate({ busy: "", note: "", result: null });
1682
+ setError(String(p.error));
1683
+ await loadSnaps({ fresh: true });
1684
+ return;
1685
+ }
1686
+ live = true; // 请求返回 ≠ 下载结束:等轮询确认后端停下再收尾
1687
+ const dl = p.downloaded || 0;
1688
+ const head = dl === 0
1689
+ ? which + " · " + t("pullNoNeed") // 本地已完整:说清楚不是没下载
1690
+ : which + " · " + t("pullGot") + " " + dl + " " + t("pullBlobs") + " / " + fmtSize(p.bytes);
1691
+ const srow = ((snaps && snaps.items) || []).filter(function (x) { return x.stamp === which; })[0];
1692
+ const snapTxt = (srow && srow.bytes)
1693
+ ? (" · " + t("pullSnapTotal") + " " + fmtSize(srow.bytes) + (srow.files ? " / " + srow.files + " " + t("pullFiles") : ""))
1694
+ : "";
1695
+ setRstate({ busy: "", note: dl === 0 ? t("pullNoNeed") : (t("pullGot") + " " + dl + " " + t("pullBlobs")
1696
+ + " \u00b7 " + fmtSize(p.bytes) + " \u00b7 " + (p.seconds || 0) + "s" + snapTxt), result: null });
1697
+ setError(null);
1698
+ await loadSnaps({ fresh: true });
1699
+ } catch (e) {
1700
+ const msg = String((e && e.message) || e);
1701
+ if (msg.indexOf("\u5df2\u6709\u4e0b\u8f7d\u5728\u8fdb\u884c") >= 0 || msg.indexOf("已有下载在进行") >= 0) {
1702
+ // 已经有下载在跑:接管它的进度,并把这次请求排队(否则用户只看到一条 409,什么也做不了)
1703
+ attached = true;
1704
+ pendingPullRef.current = which;
1705
+ attachedRef.current = true;
1706
+ setError(null);
1707
+ setRstate({ busy: "pull", note: "", result: null });
1708
+ try {
1709
+ const st3 = await call("/status");
1710
+ const p3 = st3 && st3.pull;
1711
+ if (p3 && (p3.active || p3.paused)) {
1712
+ setPullPaused(!!p3.paused);
1713
+ setPullInfo({ stamp: p3.stamp || null, done: p3.done || 0, total: p3.total || 0, bytes: p3.bytes || 0,
1714
+ needBytes: p3.needBytes || 0, all: p3.all || 0, present: p3.present || 0, paused: !!p3.paused,
1715
+ scope: p3.scope || 0, scopeFiles: p3.scopeFiles || 0, ready: p3.ready || 0 });
1716
+ }
1717
+ } catch (e3) { /* 接管失败就交给全局轮询 */ }
1718
+ return;
1719
+ }
1720
+ setError(msg); setRstate({ busy: "", note: "", result: null });
1721
+ }
1722
+ finally { if (!live) { stopPoll = true; pullPollRef.current = null; if (pollTimer) clearInterval(pollTimer); if (!attached) setPullInfo(null); } }
1723
+ };
1724
+
1725
+ // 展开第一层目录树(只读 manifest,懒加载)
1726
+ // 插件数量:目录树里有就用树的,否则用列表项(随快照清单/云盘索引带回来的计数)——
1727
+ // 这样“选中那一刻”就能显示插件行,不必等目录树加载完,也不会因树的请求失败而消失
1728
+ const plugCountOf = function (stamp) {
1729
+ if (!stamp) return 0;
1730
+ if (tree && tree.stamp === stamp && Array.isArray(tree.plugins) && tree.plugins.length) return tree.plugins.length;
1731
+ const it = (snaps && snaps.items ? snaps.items : []).filter(function (y) { return y.stamp === stamp; })[0];
1732
+ return it && Number.isFinite(it.plugins) ? it.plugins : 0;
1733
+ };
1734
+
1735
+ const doLoadTree = async function (stamp, fromCloud) {
1736
+ if (!stamp) return;
1737
+ const prev = treeCache.current[stamp];
1738
+ setTree({ stamp: stamp, loading: true, root: prev ? prev.root : null,
1739
+ nodes: prev ? prev.nodes : [], error: "", cached: !!prev });
1740
+ try {
1741
+ const r = await call("/restore/tree?stamp=" + encodeURIComponent(stamp) + "&depth=2" + (fromCloud ? "&remote=1" : ""));
1742
+ const val = { root: r.top || null, nodes: (r.top && r.top.children) || [], plugins: Array.isArray(r.plugins) ? r.plugins : [], host: r.runtime || null };
1743
+ treeCache.current[stamp] = val;
1744
+ setTree({ stamp: stamp, loading: false, root: val.root, nodes: val.nodes, error: "", plugins: val.plugins, host: val.host });
1745
+ const selAll = {};
1746
+ (val.nodes || []).forEach(function (n) { selAll[n.name] = true; });
1747
+ const kept = (pickSelKeep && pickSelKeep.stamp === stamp && pickSelKeep.on) ? pickSelKeep.on : null;
1748
+ setPickSel({ stamp: stamp, on: kept || selAll });
1749
+ setError(null);
1750
+ } catch (e) {
1751
+ const keep = treeCache.current[stamp];
1752
+ setTree({ stamp: stamp, loading: false, root: keep ? keep.root : null,
1753
+ nodes: keep ? keep.nodes : [], error: String((e && e.message) || e) });
1754
+ }
1755
+ };
1756
+
1757
+ // 勾选:树节点 = 顶层目录;默认全选,这样“下载/还原”默认就是整份
1758
+ const rowOf = function (stamp) {
1759
+ const items = snaps && snaps.items ? snaps.items : [];
1760
+ for (const x of items) if (x && x.stamp === stamp) return x;
1761
+ return null;
1762
+ };
1763
+
1764
+ const plugBreakdown = function (stamp) {
1765
+ const open = tree && tree.stamp === stamp && Array.isArray(tree.plugins) && tree.plugins.length ? tree.plugins : null;
1766
+ if (open) {
1767
+ const per = {};
1768
+ let packed = 0;
1769
+ for (const p of open) {
1770
+ if (p && p.state === "packed") packed += 1;
1771
+ for (const pf of ((p && p.profiles) || [])) per[pf] = (per[pf] || 0) + 1;
1772
+ }
1773
+ return { n: open.length, packed: packed, per: per };
1774
+ }
1775
+ const row = rowOf(stamp);
1776
+ if (row && row.pluginProfiles) {
1777
+ return { n: Number.isFinite(row.plugins) ? row.plugins : 0,
1778
+ packed: Number.isFinite(row.pluginPacked) ? row.pluginPacked : null,
1779
+ per: row.pluginProfiles };
1780
+ }
1781
+ const n = plugCountOf(stamp);
1782
+ return n > 0 ? { n: n, packed: null, per: null } : null;
1783
+ };
1784
+
1785
+ // 插件安装失败时把首个原因给出来(CLI 只回一句 Command failed,真正原因在 pnpm 诊断里)
1786
+ function plFailTip(pl) {
1787
+ const bad = (pl && pl.failed) || [];
1788
+ if (!bad.length) return "";
1789
+ return bad.map(function (f) { return String((f && f.name) || "") + ":" + String((f && (f.detail || f.error)) || ""); }).join("\n");
1790
+ }
1791
+
1792
+ const plugText = function (stamp) {
1793
+ const bd = plugBreakdown(stamp);
1794
+ if (!bd) return null;
1795
+ const n = String(bd.n);
1796
+ const keys = bd.per ? Object.keys(bd.per) : [];
1797
+ if (!keys.length) return t("pluginCount").replace("{n}", n);
1798
+ const parts = keys.map(function (k) { return k + " " + bd.per[k]; }).join(" · ");
1799
+ return t("pluginCountMany").replace("{p}", parts).replace("{n}", n);
1800
+ };
1801
+
1802
+ const plugNoteText = function (stamp) {
1803
+ const bd = plugBreakdown(stamp);
1804
+ if (!bd || bd.packed == null) return t("plugNote");
1805
+ return bd.packed > 0
1806
+ ? t("plugNotePack").replace("{p}", String(bd.packed)).replace("{s}", String(bd.n - bd.packed))
1807
+ : t("plugNote");
1808
+ };
1809
+
1810
+ const pickNames = function (stamp) {
1811
+ if (!pickSel || pickSel.stamp !== stamp) return null;
1812
+ return Object.keys(pickSel.on || {}).filter(function (k) { return pickSel.on[k]; });
1813
+ };
1814
+ const pickRels = function (stamp) {
1815
+ const names = pickNames(stamp);
1816
+ if (!names) return undefined; // 树还没展开:按整份处理
1817
+ return names;
1818
+ };
1819
+ const setPickAll = function (stamp, nodes, on) {
1820
+ const map = {};
1821
+ (nodes || []).forEach(function (n) { map[n.name] = !!on; });
1822
+ setPickSel({ stamp: stamp, on: map });
1823
+ };
1824
+ const togglePick = function (stamp, name) {
1825
+ setPickSel(function (prev) {
1826
+ const base = (prev && prev.stamp === stamp && prev.on) ? Object.assign({}, prev.on) : {};
1827
+ base[name] = !base[name];
1828
+ return { stamp: stamp, on: base };
1829
+ });
1830
+ };
1831
+ const treeHead = function (stamp, nodes) {
1832
+ const names = pickNames(stamp) || [];
1833
+ const all = (nodes || []).length;
1834
+ return react_jsx_runtime.jsxs("div", { className: "dshcb-tnHead", children: [
1835
+ react_jsx_runtime.jsx("span", { className: "dshcb-tnSel",
1836
+ children: t("selCount").replace("{n}", String(names.length)).replace("{m}", String(all)) }),
1837
+ react_jsx_runtime.jsxs("span", { className: "dshcb-tnActs", children: [
1838
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-link",
1839
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); setPickAll(stamp, nodes, true); },
1840
+ children: t("selAll") }),
1841
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-link",
1842
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); setPickAll(stamp, nodes, false); },
1843
+ children: t("selNone") }),
1844
+ ] }),
1845
+ ] }, "tnhead");
1846
+ };
1847
+ const doPausePull = async function () {
1848
+ try { await call("/restore/pause", {}); setPullPaused(true); }
1849
+ catch (e) { setError(String((e && e.message) || e)); }
1850
+ };
1851
+
1852
+ const dropRows = function (stamps) {
1853
+ const gone = new Set(stamps || []);
1854
+ if (!gone.size) return;
1855
+ setSnaps(function (prev) {
1856
+ if (!prev) return prev;
1857
+ return Object.assign({}, prev, { items: (prev.items || []).filter(function (x) { return !gone.has(x.stamp); }) });
1858
+ });
1859
+ setRpick(function (p) { return p && gone.has(p) ? null : p; });
1860
+ setRexpand(function (e) { return e && gone.has(e) ? null : e; });
1861
+ gone.forEach(function (st) { delete treeCache.current[st]; });
1862
+ };
1863
+
1864
+ const doRefreshSnaps = async function (opts) {
1865
+ // 只重试某一行时,只让那一行显示忙碌;整表刷新(工具条)才用全局 busy
1866
+ const only = (opts && opts.stamp) || "";
1867
+ if (only) setRowBusy(only); else setSbusy("list");
1868
+ let good = false;
1869
+ try { good = await loadSnaps({ fresh: true }); }
1870
+ catch (e) { setError(String((e && e.message) || e)); }
1871
+ finally { if (only) setRowBusy(""); else setSbusy(""); }
1872
+ // 读不到就不能报「已刷新」:错误留在原地,用户才知道是刷新失败
1873
+ if (good) { setError(null); if (!only) showTip(t("listRefreshed"), "ok"); }
1874
+ };
1875
+
1876
+ // 原生确认已换成宿主风格的弹窗(askDlg);取消/遮罩/Esc 一律视为不同意
1877
+ // 体积按量级换单位:小于 1 MB 用 KB,小于 1 KB 用 B(小目录不会显示成 0.0 MB)
1878
+ const fmtSize = function (n) {
1879
+ const b = Number(n) || 0;
1880
+ if (b < 1024) return b + " B";
1881
+ if (b < 1048576) { const kb = b / 1024; return (kb < 10 ? kb.toFixed(1) : String(Math.round(kb))) + " KB"; }
1882
+ return (b / 1048576).toFixed(1) + " MB";
1883
+ };
1884
+
1885
+ // 删除一份备份:云端进回收站 + 本地缓存一起清(一次确认,符合“一份备份”的心智)
1886
+ // 批量删除:进入多选 → 勾选 → 一次确认 → 逐份删(失败即停,已删不回滚)
1887
+ const doBatchOn = function () { setBatch(true); setBsel([]); setError(null); };
1888
+ const doBatchOff = function () { setBatch(false); setBsel([]); };
1889
+ const toggleBsel = function (stamp) {
1890
+ setBsel(function (cur) {
1891
+ const i = cur.indexOf(stamp);
1892
+ return i >= 0 ? cur.filter(function (s2) { return s2 !== stamp; }) : cur.concat([stamp]);
1893
+ });
1894
+ };
1895
+ const batchBytes = function () {
1896
+ const items = (snaps && snaps.items) || [];
1897
+ let total = 0;
1898
+ for (let i = 0; i < bsel.length; i++) {
1899
+ const it = items.find(function (x) { return x.stamp === bsel[i]; });
1900
+ if (it) total += Number(it.bytes) || 0;
1901
+ }
1902
+ return total;
1903
+ };
1904
+ const doBatchDelete = async function () {
1905
+ if (!bsel.length) return;
1906
+ const pick = bsel.slice();
1907
+ setSbusy("bdel");
1908
+ let idx = 0;
1909
+ try {
1910
+ const plans = [];
1911
+ for (let i = 0; i < pick.length; i++) {
1912
+ const r = await call("/backups/delete", { stamp: pick[i], dryRun: true });
1913
+ plans.push({ stamp: pick[i], plan: (r && r.plan) || {} });
1914
+ }
1915
+ const lastN = plans.filter(function (p) { return p.plan.lastCloudCopy === true; }).length;
1916
+ const lines = plans.map(function (p) {
1917
+ const row = (snaps && snaps.items ? snaps.items : []).find(function (x) { return x.stamp === p.stamp; }) || null;
1918
+ return p.stamp + " · " + fmtSize(p.plan.bytes != null ? p.plan.bytes : (row ? row.bytes : null));
1919
+ });
1920
+ const go = await askDlg({
1921
+ title: t("batchTitle").replace("{n}", String(plans.length)),
1922
+ lead: t("batchLead"),
1923
+ summary: lastN ? t("batchLast").replace("{n}", String(lastN)) : "",
1924
+ lines: lines,
1925
+ skip: "",
1926
+ confirm: t("dlgDelete"),
1927
+ });
1928
+ if (!go) { setSbusy(""); return; }
1929
+ let done = 0;
1930
+ for (idx = 0; idx < plans.length; idx++) {
1931
+ const p = plans[idx];
1932
+ setBatchAt(t("batchDeleting").replace("{i}", String(idx + 1)).replace("{n}", String(plans.length)));
1933
+ await call("/backups/delete", { stamp: p.stamp, dryRun: false, allowLast: p.plan.lastCloudCopy === true });
1934
+ done++;
1935
+ dropRows([p.stamp]);
1936
+ setBsel(function (cur) { return cur.filter(function (s2) { return s2 !== p.stamp; }); });
1937
+ }
1938
+ setError(null);
1939
+ const msg = t("batchDone").replace("{n}", String(done));
1940
+ showTip(msg, "ok");
1941
+ await loadSnaps({ fresh: true });
1942
+ await refresh();
1943
+ setBatch(false);
1944
+ setBsel([]);
1945
+ } catch (e) {
1946
+ const m = String((e && e.message) || e);
1947
+ const stop = t("batchFailStop").replace("{i}", String(idx + 1)).replace("{err}", m);
1948
+ setError(m);
1949
+ showTip(stop, "err");
1950
+ } finally { setBatchAt(""); setSbusy(""); }
1951
+ };
1952
+
1953
+ const doDelete = async function (stamp) {
1954
+ if (!stamp) return;
1955
+ setSbusy("del"); setRpick(stamp);
1956
+ try {
1957
+ const planRes = await call("/backups/delete", { stamp: stamp, dryRun: true });
1958
+ const pl = (planRes && planRes.plan) || {};
1959
+ const cacheMb = fmtSize(pl.cacheBytes);
1960
+ const last = pl.lastCloudCopy === true;
1961
+ const lines = [stamp, t("delBackupCloud")];
1962
+ if (pl.hasCache) lines.push(t("delBackupCache").replace("{mb}", cacheMb));
1963
+ const go = await askDlg({
1964
+ title: t("delBackupTitle"),
1965
+ lead: t("delBackupLead"),
1966
+ summary: last ? t("delBackupLast") : "",
1967
+ lines: lines,
1968
+ skip: "",
1969
+ confirm: t("dlgDelete"),
1970
+ });
1971
+ if (!go) { setSbusy(""); return; }
1972
+ const r = await call("/backups/delete", { stamp: stamp, dryRun: false, allowLast: last });
1973
+ dropRows([stamp]);
1974
+ showTip(t("delDone") + " " + stamp + (r && r.cacheDeleted ? " · " + t("cacheCleanTag") : ""), "ok");
1975
+ setError(null);
1976
+ await loadSnaps({ fresh: true });
1977
+ await refresh();
1978
+ } catch (e) {
1979
+ const m = String((e && e.message) || e);
1980
+ setError(m); showTip(m, "err");
1981
+ } finally { setSbusy(""); }
1982
+ };
1983
+
1984
+ // 清理本地缓存:只动本机为还原下载的副本,云端备份不受影响
1985
+ const doClearCache = async function () {
1986
+ setSbusy("cache");
1987
+ try {
1988
+ const pre = await call("/maintenance/cache", { dryRun: true });
1989
+ const st = (pre && pre.stats) || {};
1990
+ const keepN = 3;
1991
+ const cand = Math.max(0, (Number(st.copies) || 0) - keepN);
1992
+ if (!cand) { showTip(t("cacheCleanNone"), "info"); setSbusy(""); return; }
1993
+ const go = await askDlg({
1994
+ title: t("cacheCleanTitle"),
1995
+ lead: t("cacheCleanLead"),
1996
+ summary: t("cacheCleanKeep").replace("{n}", String(keepN)),
1997
+ lines: [(Number(st.copies) || 0) + " -> " + cand + " · " + fmtSize(st.bytes)],
1998
+ skip: "",
1999
+ confirm: t("cacheCleanBtn"),
2000
+ });
2001
+ if (!go) { setSbusy(""); return; }
2002
+ const r = await call("/maintenance/cache", { dryRun: false, keep: keepN });
2003
+ const nDel = (r && Array.isArray(r.deleted)) ? r.deleted.length : 0;
2004
+ showTip(t("cacheCleanDone").replace("{n}", String(nDel)).replace("{mb}", fmtSize(r && r.freed)), "ok");
2005
+ setError(null);
2006
+ await loadSnaps({ fresh: true });
2007
+ } catch (e) { const cm = String((e && e.message) || e); setError(cm); showTip(cm, "err"); }
2008
+ finally { setSbusy(""); }
2009
+ };
2010
+
2011
+ const doUpload = async function (stamp) {
2012
+ if (!stamp) return;
2013
+ setSbusy("upload"); setRpick(stamp);
2014
+ try {
2015
+ await call("/backups/upload", { stamp: stamp });
2016
+ showTip(t("uploadDone") + " " + stamp, "ok");
2017
+ setError(null);
2018
+ await loadSnaps({ fresh: true });
2019
+ await refresh();
2020
+ } catch (e) { const cm = String((e && e.message) || e); setError(cm); showTip(cm, "err"); }
2021
+ finally { setSbusy(""); }
2022
+ };
2023
+
2024
+ const saveSched = async function (patch) {
2025
+ setSchedDraft(function (prev) { return Object.assign({}, prev, patch); });
2026
+ if (patch.intervalMinutes !== undefined || patch.enabled !== undefined) {
2027
+ const cfgNow = ((status && status.backup && status.backup.config) || {});
2028
+ const minsNext = Number(patch.intervalMinutes !== undefined ? patch.intervalMinutes
2029
+ : (schedDraft && schedDraft.intervalMinutes !== undefined ? schedDraft.intervalMinutes : cfgNow.intervalMinutes)) || 60;
2030
+ const onNext = patch.enabled !== undefined ? !!patch.enabled
2031
+ : (schedDraft && schedDraft.enabled !== undefined ? !!schedDraft.enabled : cfgNow.enabled !== false);
2032
+ setSchedNextDraft(onNext ? { at: Date.now() + minsNext * 60000, base: (status && status.schedule && status.schedule.nextAt) || null } : null);
2033
+ } // 先滑到新位置,不等网络
2034
+ setSchedBusy(true);
2035
+ schedSeq.current += 1;
2036
+ const seq = schedSeq.current;
2037
+ try {
2038
+ const cfg = ((status && status.backup && status.backup.config) || {});
2039
+ await call("/backup/config", Object.assign({
2040
+ enabled: cfg.enabled !== false, intervalMinutes: Number(cfg.intervalMinutes) || 60,
2041
+ }, patch));
2042
+ if (seq !== schedSeq.current) return;
2043
+ setError(null);
2044
+ await refresh();
2045
+ if (seq === schedSeq.current) setSchedDraft(null); // 服务端值已落地,交回权威值
2046
+ } catch (e) {
2047
+ if (seq === schedSeq.current) { setSchedDraft(null); setSchedNextDraft(null); setError(String((e && e.message) || e)); }
2048
+ } finally { if (seq === schedSeq.current) setSchedBusy(false); }
2049
+ };
2050
+
2051
+ const doVerifyRestore = async function () {
2052
+ if (!rpick) { setError(t("restorePickFirst")); return; }
2053
+ setRstate({ busy: "verify", note: "", result: null });
2054
+ try {
2055
+ const r = await call("/restore/verify", { stamp: rpick, targetRoot: rtarget || undefined });
2056
+ const v = r.verify || {};
2057
+ setRstate({ busy: "", note: "same " + v.same + " / diff " + v.diff + " / " + t("restoreMiss") + " " + v.missing
2058
+ + (v.ok ? " ✓" : " ✗"), result: null });
2059
+ setError(null);
2060
+ } catch (e) { setError(String((e && e.message) || e)); setRstate({ busy: "", note: "", result: null }); }
2061
+ };
2062
+
2063
+ const noteBN = bstate && bstate.note;
2064
+ react.useEffect(function () {
2065
+ if (!noteBN) return;
2066
+ showTip(noteBN, "info");
2067
+ setBstate(function (cur) { return { running: !!cur.running, note: "" }; });
2068
+ }, [noteBN]);
2069
+ const noteRN = rstate && rstate.note;
2070
+ const resRN = rstate && rstate.result;
2071
+ react.useEffect(function () {
2072
+ if (!noteRN && !resRN) return;
2073
+ const wsM = resRN && resRN.mergedWorkspace;
2074
+ const pgS = resRN && resRN.pluginSummary;
2075
+ const pgNote = (pgS && (pgS.skipped || pgS.failed))
2076
+ ? " \u00b7 " + ((pgS.skippedBlob || 0) > 0
2077
+ ? t("rgPlSkipMix").replace("{n}", String(pgS.skipped || 0)).replace("{s}", String(pgS.skippedScoped || 0)).replace("{b}", String(pgS.skippedBlob || 0))
2078
+ : t("rgPlSkip").replace("{n}", String(pgS.skipped || 0)).replace("{p}", (pgS.others || []).join(", ") || "-"))
2079
+ : "";
2080
+ const rsNote = (resRN && resRN.restored > 0) ? " \u00b7 " + t("rgRestart") : "";
2081
+ const txt = noteRN || ("\u8fd8\u539f\u5b8c\u6210 \u00b7 \u5199\u5165 " + ((resRN && resRN.restored) || 0)
2082
+ + " \u00b7 \u8df3\u8fc7 " + ((resRN && resRN.skipped) || 0)
2083
+ + " \u00b7 \u8986\u76d6 " + ((resRN && resRN.overwritten) || 0)
2084
+ + ((resRN && resRN.skippedDiff > 0) ? " \u00b7 " + t("restoreSkippedMix").replace("{d}", String(resRN.skippedDiff)) : "")
2085
+ + (wsM ? " \u00b7 " + t("wsMergedNote").replace("{a}", String(wsM.added || 0)).replace("{k}", String(wsM.kept || 0)).replace("{j}", String(wsM.sessionsAdded || 0)) : "")
2086
+ + pgNote + rsNote);
2087
+ if (!(resRN && resRN.stopped)) showTip(txt, resRN && resRN.ok === false ? "err" : "ok");
2088
+ setRstate(function (cur) { return { busy: "", note: "", result: null }; });
2089
+ }, [noteRN, resRN]);
2090
+ // 清理/删除/上传的收尾说明统一进消息层,不再另外弹 toast(同一件事只说一次)
2091
+
2092
+ const auth = status && status.auth;
2093
+ const connected = !!(auth && auth.connected);
2094
+ const account = (auth && auth.account) || {};
2095
+ // 状态点四态:ok 蓝(已连接)/ busy 琥珀(刷新·备份进行中)/ err 红(连接失败)/ off 灰(未连接)
2096
+ const connState = connected
2097
+ ? ((sbusy || busy || authBusy || bstate.running || schedBusy || rstate.busy) ? "s-busy" : "s-ok")
2098
+ : (error ? "s-err" : "s-off");
2099
+
2100
+
2101
+ function Ico(name, size) {
2102
+ const s = size || 15;
2103
+ const P = {
2104
+ cloudBackup: [
2105
+ "M7 14.6a3.7 3.7 0 0 1-.4-7.36A5.2 5.2 0 0 1 16.6 6.7 3.4 3.4 0 0 1 16.9 14.6",
2106
+ "M12 11.8v7.4M9.7 16.9 12 19.2 14.3 16.9",
2107
+ ],
2108
+ cloudDown: [
2109
+ "M7 15.1a3.6 3.6 0 0 1-.4-7.15A5.05 5.05 0 0 1 16.3 7.2 3.3 3.3 0 0 1 16.6 15.1",
2110
+ "M12 12.2v6.6M9.8 16.6 12 18.8 14.2 16.6",
2111
+ ],
2112
+ cloudUp: [
2113
+ "M7 15.1a3.6 3.6 0 0 1-.4-7.15A5.05 5.05 0 0 1 16.3 7.2 3.3 3.3 0 0 1 16.6 15.1",
2114
+ "M12 18.8v-6.6M9.8 14.4 12 12.2l2.2 2.2",
2115
+ ],
2116
+ chevDown: "M6 9.5 12 15.5 18 9.5",
2117
+ chevRight: "M9.5 6 15.5 12 9.5 18",
2118
+ trash: "M4.5 7.5h15M9.5 7.5V5.2h5v2.3M7 7.5l.8 12h8.4L17 7.5M10.6 11v5.6M13.4 11v5.6",
2119
+ refresh: "M19.6 12a7.6 7.6 0 1 1-2.5-5.6M19.9 4.9v5.2h-5.2",
2120
+ docSearch: "M13.6 3.6H7.2A1.9 1.9 0 0 0 5.3 5.5v13A1.9 1.9 0 0 0 7.2 20.4h4.1M13.6 3.6 18.9 8.9v3.4M13.6 3.6v5.3h5.3M15.7 20.9a3.4 3.4 0 1 0 0-6.8 3.4 3.4 0 0 0 0 6.8ZM18.4 20.2l2.3 2.3",
2121
+ folder: "M3.7 7.7A1.9 1.9 0 0 1 5.6 5.8h3.2l1.7 1.9h7.9a1.9 1.9 0 0 1 1.9 1.9v6.4a1.9 1.9 0 0 1-1.9 1.9H5.6a1.9 1.9 0 0 1-1.9-1.9V7.7Z",
2122
+ check: "M20 6.4 9.6 17 4.6 12",
2123
+ warn: "M12 3.8 21.2 19.9H2.8L12 3.8ZM12 9.6v4.7M12 17.3h.01",
2124
+ close: "M5.9 5.9 18.1 18.1M18.1 5.9 5.9 18.1",
2125
+ info: ["M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Z", "M12 11.2v5.2", "M12 7.6h.01"],
2126
+ };
2127
+ if (name === "dots") {
2128
+ return react_jsx_runtime.jsxs("svg", { width: s, height: s, viewBox: "0 0 24 24", className: "dshcb-ico", "aria-hidden": "true",
2129
+ children: [
2130
+ react_jsx_runtime.jsx("circle", { cx: 12, cy: 5.4, r: 1.7, fill: "currentColor" }),
2131
+ react_jsx_runtime.jsx("circle", { cx: 12, cy: 12, r: 1.7, fill: "currentColor" }),
2132
+ react_jsx_runtime.jsx("circle", { cx: 12, cy: 18.6, r: 1.7, fill: "currentColor" }),
2133
+ ] });
2134
+ }
2135
+ const d = P[name] || "";
2136
+ const kids = Array.isArray(d)
2137
+ ? d.map(function (x, i) { return react_jsx_runtime.jsx("path", { d: x }, i); })
2138
+ : react_jsx_runtime.jsx("path", { d: d });
2139
+ return react_jsx_runtime.jsx("svg", {
2140
+ width: s, height: s, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
2141
+ strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round",
2142
+ className: "dshcb-ico", "aria-hidden": "true", children: kids,
2143
+ });
2144
+ }
2145
+
2146
+ function Seg(props) {
2147
+ const items = props.items || [];
2148
+ const value = props.value;
2149
+ const onPick = props.onPick;
2150
+ const disabled = !!props.disabled;
2151
+ const box = react.useRef(null);
2152
+ const last = react.useRef(null); // 上次量到的几何,避免重复 setState
2153
+ const [geo, setGeo] = react.useState(null); // { left, width }:当前选项的位置与宽度
2154
+ const [canAnim, setCanAnim] = react.useState(false); // 只有“用户真的切换选项”才滑动;布局重测不动画(否则悬停时会闪)
2155
+ // value 短暂不在 items 里(配置还没回来 / 下载期间刷新)时沿用上次位置,避免滑块跳回第一个位置“闪”
2156
+ const found = items.findIndex(function (it) { return it.value === value; });
2157
+ const lastIdx = react.useRef(0);
2158
+ if (found >= 0) lastIdx.current = found;
2159
+ const idx = found >= 0 ? found : lastIdx.current;
2160
+ const prevValue = react.useRef(value);
2161
+ react.useEffect(function () {
2162
+ if (prevValue.current !== value) { prevValue.current = value; setCanAnim(true); }
2163
+ }, [value]);
2164
+ // 几何测量:值没变就不 setState(避免每一帧重渲染);容器或选项尺寸变化时也重新贴合
2165
+ const measure = function (animate) {
2166
+ const el = box.current;
2167
+ if (!el) return;
2168
+ const node = el.querySelectorAll("button")[idx];
2169
+ if (!node) return;
2170
+ const next = { left: node.offsetLeft, width: node.offsetWidth };
2171
+ const prev = last.current;
2172
+ if (prev && prev.left === next.left && prev.width === next.width) return;
2173
+ last.current = next;
2174
+ setCanAnim(!!animate);
2175
+ setGeo(next);
2176
+ };
2177
+ const measureRef = react.useRef(measure);
2178
+ measureRef.current = measure;
2179
+ const seen = react.useRef(false);
2180
+ react.useEffect(function () {
2181
+ const first = !seen.current; // 首次定位直接落位,不滑动
2182
+ seen.current = true;
2183
+ const run = function () { measureRef.current(!first); }; // 选项变了 → 滑动过去
2184
+ const relayout = function () { measureRef.current(false); }; // 只是布局重排 → 直接贴合,不动画(悬停时不会闪)
2185
+ run();
2186
+ window.addEventListener("resize", relayout);
2187
+ let ro = null;
2188
+ if (typeof ResizeObserver === "function" && box.current) {
2189
+ ro = new ResizeObserver(relayout);
2190
+ ro.observe(box.current);
2191
+ const btns = box.current.querySelectorAll("button");
2192
+ for (let i = 0; i < btns.length; i += 1) ro.observe(btns[i]);
2193
+ }
2194
+ return function () {
2195
+ window.removeEventListener("resize", relayout);
2196
+ if (ro) ro.disconnect();
2197
+ };
2198
+ }, [idx, items.length, disabled]);
2199
+ return react_jsx_runtime.jsxs("div", {
2200
+ className: "dshcb-seg" + (disabled ? " dis" : "") + (props.small ? " sm" : ""), ref: box,
2201
+ children: [
2202
+ geo ? react_jsx_runtime.jsx("span", {
2203
+ className: "dshcb-segthumb" + (canAnim ? "" : " notrans"),
2204
+ style: { transform: "translateX(" + geo.left + "px)", width: geo.width + "px" },
2205
+ }, "thumb") : null,
2206
+ ].concat(items.map(function (it) {
2207
+ const on = it.value === value;
2208
+ return react_jsx_runtime.jsx("button", {
2209
+ type: "button", className: "dshcb-segi" + (on ? " on" : ""),
2210
+ disabled: disabled, onClick: function () { if (!disabled) onPick(it.value); },
2211
+ children: it.label,
2212
+ }, String(it.value));
2213
+ })),
2214
+ });
2215
+ }
2216
+
2217
+ // 悬停提示走模块级小 store(见 TipLayer):悬停只重渲染浮层,不牵动整卡与分段控件
2218
+ function tipProps(text) {
2219
+ const str = shortTip(text);
2220
+ if (!str) return {};
2221
+ return {
2222
+ onMouseEnter: function (e) { tipPush(str, e.clientX, e.clientY, true); },
2223
+ onMouseMove: function (e) { tipPush(str, e.clientX, e.clientY, false); },
2224
+ onMouseDown: function () { tipStore.set(null); },
2225
+ onMouseLeave: function () { tipStore.set(null); },
2226
+ };
2227
+ }
2228
+ function tool(label, icon, fn, on, disabled, warn) {
2229
+ return react_jsx_runtime.jsxs("button", {
2230
+ type: "button", className: "dshcb-tool" + (on ? " on" : "") + (warn ? " warn" : ""),
2231
+ disabled: !!disabled || !!rstate.busy || !!sbusy, onClick: fn,
2232
+ children: [Ico(icon, 15), react_jsx_runtime.jsx("span", { children: label })],
2233
+ });
2234
+ }
2235
+
2236
+ function menuItem(label, fn, danger, busy) {
2237
+ return react_jsx_runtime.jsx("button", {
2238
+ type: "button", className: "dshcb-mi" + (danger ? " danger" : ""),
2239
+ disabled: !!busy || !!authBusy, onClick: fn, children: busy ? t("busy") : label,
2240
+ });
2241
+ }
2242
+
2243
+ // 还原提示与「还原记录」共用同一套字段:时间 · 快照 ID · 写入 · 跳过 · 装回插件 · 跳过插件
2244
+ // 记录里的插件段既可能是名单数组(真还原写入),也可能是计数(早先记录/兜底),两种都要能显示
2245
+ const plCount = function (v) { return Array.isArray(v) ? v.length : (Number.isFinite(v) ? v : 0); };
2246
+ const lrRowText = function (lr) {
2247
+ const h = lr || {};
2248
+ const pl = h.plugins || null;
2249
+ const bits = [fmtStamp(h.at), h.stamp || "-", t("lrWritten") + " " + (h.restored || 0), t("lrSkipped") + " " + (h.skipped || 0)];
2250
+ if ((h.failed || 0) > 0) bits.push(t("lrFailed") + " " + h.failed);
2251
+ if (pl) {
2252
+ bits.push(t("lrPluginsOk") + " " + plCount(pl.installed));
2253
+ bits.push(t("lrPlSkip").replace("{n}", String(plCount(pl.skipped))));
2254
+ if (plCount(pl.skippedBlob) > 0) bits.push(t("lrPlBlob").replace("{b}", String(plCount(pl.skippedBlob))));
2255
+ if (plCount(pl.failed) > 0) bits.push(t("lrPluginsFail") + " " + plCount(pl.failed));
2256
+ }
2257
+ return bits.join(" · ");
2258
+ };
2259
+ const showLrNote = function (lr, keepOpen) {
2260
+ if (!lr) return;
2261
+ setLrNote(lr);
2262
+ if (lrTimer.current) clearTimeout(lrTimer.current);
2263
+ // 这次还原还没重启 DSH:把这一行留在原位(重启后 needsRestart 自然变回 false),别让它先自己溜走
2264
+ if (keepOpen) { lrTimer.current = null; return; }
2265
+ lrTimer.current = setTimeout(function () { setLrNote(null); }, 30 * 1000);
2266
+ };
2267
+ const doHistory = async function () {
2268
+ if (histOpen) { setHistOpen(false); return; }
2269
+ try {
2270
+ const r = await call("/restore/history");
2271
+ setRhist((r && r.items) || []);
2272
+ } catch (e) { setRhist([]); }
2273
+ setHistOpen(true);
2274
+ };
2275
+
2276
+ const bk = (status && status.backup) || {};
2277
+ const needsRestart = bk.needsRestart === true;
2278
+ const rsTotal = (rsProg && Number(rsProg.total)) || 0;
2279
+ const rsDone = (rsProg && Number(rsProg.done)) || 0;
2280
+ // 还原请求返回前不能显示 100%:收尾阶段(登记表合并 / 落盘)不产生步进,
2281
+ // 显示满格会让「正在还原」看上去卡住不动
2282
+ const rsPct = rsTotal > 0 ? Math.max(1, Math.min(99, Math.round((rsDone / rsTotal) * 100))) : 0;
2283
+ const rsCancelling = !!(rsProg && rsProg.cancelled);
2284
+ const last = bk.last || null;
2285
+ const bkcfg = bk.config || {};
2286
+ const sch = (status && status.schedule) || {};
2287
+ const schedDraftOn = !!schedDraft && schedDraft.enabled !== undefined ? !!schedDraft.enabled : null;
2288
+ const schedOn = schedDraftOn === null ? (bkcfg.enabled !== false) : schedDraftOn;
2289
+ const syncDraftOn = !!schedDraft && schedDraft.autoUpload !== undefined ? !!schedDraft.autoUpload : null;
2290
+ const syncOn = syncDraftOn === null ? (bkcfg.autoUpload !== false) : syncDraftOn;
2291
+ const sideDraftOn = !!schedDraft && schedDraft.sidebarEntry !== undefined ? !!schedDraft.sidebarEntry : null;
2292
+ const sideOn = sideDraftOn === null ? (bkcfg.sidebarEntry !== false) : sideDraftOn;
2293
+ const schedMinSrv = Number(sch.intervalMinutes || bkcfg.intervalMinutes || 60);
2294
+ // 有乐观值时优先显示它,切 tab 立即生效(否则要等后端 tick)
2295
+ const srvNextAt = sch.nextAt || null;
2296
+ const schedNextAt = (schedNextDraft && srvNextAt === schedNextDraft.base) ? new Date(schedNextDraft.at).toISOString() : srvNextAt;
2297
+ const schedMin = (schedDraft && schedDraft.intervalMinutes !== undefined)
2298
+ ? Number(schedDraft.intervalMinutes) : schedMinSrv;
2299
+ const intervalOptions = [60, 360, 1440];
2300
+ const curInterval = intervalOptions.indexOf(schedMin) >= 0 ? schedMin : 60;
2301
+ const acctName = account.user_name || account.nick_name || account.user_id || "—";
2302
+ const snapList = (snaps && (snaps.merged || snaps.local)) || [];
2303
+ const lastText = last
2304
+ ? (fmtStamp(last.at) + " · " + (last.files || 0) + " " + t("backupFiles") + " / " + fmtSize(last.bytes)
2305
+ + (last.upload
2306
+ ? (last.upload.ok === true ? " · " + t("backupUploaded")
2307
+ : last.upload.ok === false ? " · " + t("backupUploadFail")
2308
+ : " · " + t("backupUploadSkipped"))
2309
+ : ""))
2310
+ : t("never");
2311
+ const sumLine = t("rowConnect") + " " + (connected ? t("connected") : t("notConnected"))
2312
+ + (connected ? " · " + t("rowAccount") + " " + acctName : "");
2313
+
2314
+ const qrPanel = qr ? react_jsx_runtime.jsxs("div", {
2315
+ className: "dshcb-qrbox",
2316
+ children: [
2317
+ react_jsx_runtime.jsx("div", { className: "dshcb-qrhead", children: t("qrTitle") }),
2318
+ react_jsx_runtime.jsx("img", { className: "dshcb-qr" + (qrBig ? " big" : ""), src: qr.qr, alt: "QR", width: qrBig ? 320 : 208, height: qrBig ? 320 : 208, title: qrBig ? "\u70b9\u4e00\u4e0b\u6062\u590d\u5927\u5c0f" : "\u70b9\u4e00\u4e0b\u653e\u5927", onClick: function () { setQrBig(!qrBig); } }),
2319
+ react_jsx_runtime.jsx("div", { className: "dshcb-qrstate" + (qrState === "scanned" || qrState === "connecting" ? " ok" : ""),
2320
+ children: qrState === "scanned" ? t("qrScanned")
2321
+ : qrState === "connecting" ? (t("qrConnecting") + (qr && qr.attempt ? " \u00b7 " + t("qrTry") + " " + qr.attempt + "/12" : ""))
2322
+ : t("qrNew") }),
2323
+ react_jsx_runtime.jsx("div", { className: "dshcb-qrhint", children: t("qrExpireIn") + " " + left + " " + t("seconds") }),
2324
+ react_jsx_runtime.jsx("div", { className: "dshcb-qrrow", children: [
2325
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-linkbtn", onClick: function () { setQrBig(!qrBig); }, children: qrBig ? t("qrZoomOut") : t("qrZoom") }),
2326
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-linkbtn", onClick: openLoginInBrowser, title: loginPageUrl(), children: t("openBrowserLogin") }),
2327
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-linkbtn", onClick: function () { const u = loginPageUrl(); if (!u) return; const c = copyText(u); showTip(c ? t("linkCopied") : (t("linkCopyManual") + u), c ? "ok" : "err"); }, children: t("copyLink") }),
2328
+ ] }),
2329
+
2330
+ watch ? react_jsx_runtime.jsxs("div", { className: "dshcb-watch", children: watch.timeout ? [
2331
+ react_jsx_runtime.jsx("span", { children: t("watchTimeout") }),
2332
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-linkbtn", onClick: function () { setWatch(null); }, children: t("watchDismiss") }),
2333
+ ] : [
2334
+ react_jsx_runtime.jsx("span", { className: "dshcb-spin" }),
2335
+ react_jsx_runtime.jsx("span", { children: t("watchWait") }),
2336
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-linkbtn", onClick: function () { stopWatch(); }, children: t("watchCancel") }),
2337
+ ] }) : null,
2338
+
2339
+ react_jsx_runtime.jsx("div", { className: "dshcb-qrhint", children: t("qrNote") }),
2340
+ ],
2341
+ }) : null;
2342
+ const headPanel = react_jsx_runtime.jsxs("div", { className: "dshcb-head", children: [
2343
+ react_jsx_runtime.jsxs("div", { className: "dshcb-headL", children: [
2344
+ Ico("cloudBackup", 22),
2345
+ react_jsx_runtime.jsx("span", { className: "dshcb-h1", children: t("title") }),
2346
+ react_jsx_runtime.jsx("span", { className: "dshcb-ver", children: status && status.version ? ("v" + status.version) : t("phaseLoading") }),
2347
+ ] }),
2348
+ react_jsx_runtime.jsxs("div", { className: "dshcb-headR", children: [
2349
+ react_jsx_runtime.jsxs("span", { className: "dshcb-state " + connState, children: [
2350
+ react_jsx_runtime.jsx("i", { className: "dshcb-dot" }),
2351
+ connected ? t("connected") : t("notConnected"),
2352
+ ] }),
2353
+ react_jsx_runtime.jsxs("div", { className: "dshcb-morewrap", children: [
2354
+ react_jsx_runtime.jsxs("button", { type: "button", className: "dshcb-more",
2355
+ onClick: function () { setMenu(!menu); }, children: [t("more"), Ico("dots", 14)] }),
2356
+ menu ? react_jsx_runtime.jsxs("div", { className: "dshcb-menu", children: [
2357
+ // 顺序按效果图:断开连接 / 刷新状态 / 验证连接
2358
+ connected ? menuItem(t("disconnect"), function () { setMenu(false); doDisconnect(); }, false, authBusy === "disconnect") : null,
2359
+ menuItem(t("refresh"), function () { setMenu(false); refresh(); }),
2360
+ !connected ? menuItem(t("importLocal"), function () { setMenu(false); doImportLocal(); }, false, authBusy === "import") : null,
2361
+ connected ? menuItem(t("verify"), function () { setMenu(false); doVerify(); }, false, authBusy === "verify") : null,
2362
+ menuItem(t("openLogs"), function () { setMenu(false); doOpenLogs(); }),
2363
+ ] }) : null,
2364
+ ] }),
2365
+ ] }),
2366
+ ] });
2367
+
2368
+ // ② 授权信息(可折叠表格)
2369
+ const renewText = !connected ? "—" : t("renewOn");
2370
+
2371
+ const authRows = [
2372
+ [t("rowConnect"), connected ? t("connected") : t("notConnected"), connected ? "" : "warn"],
2373
+ [t("rowAccount"), acctName, ""],
2374
+ [t("rowDrive"), (auth && auth.drive_id) || "—", ""],
2375
+ [t("rowFolder"), (status && status.folder && status.folder.name) || (status && status.appFolder) || "—", ""],
2376
+ [t("rowRefresh"), renewText, ""],
2377
+ [t("rowLastBackup"), bstate.running ? t("backupRunning") : lastText,
2378
+ last && last.upload && last.upload.ok === false ? "warn" : ""],
2379
+ [t("verified"), (status && status.lastVerifiedAt) || t("never"), ""],
2380
+ [t("rowHost"), (function () {
2381
+ const h = (status && status.backup && status.backup.host) || null;
2382
+ if (!h) return "—";
2383
+ return h.shape === "desktop" ? t("hostDesktop")
2384
+ : h.shape === "web" ? t("hostWeb") : t("hostGeneric");
2385
+ })(), ""],
2386
+ [t("rowStateDir"), (status && status.stateDir) || "—", ""],
2387
+ [t("rowCrypto"), (status && status.secretBackend) || "—", ""],
2388
+ ];
2389
+ const authPanel = react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2390
+ react_jsx_runtime.jsxs("button", { type: "button", className: "dshcb-sech",
2391
+ "aria-expanded": infoOpen ? "true" : "false",
2392
+ onClick: function () { setInfoOpen(!infoOpen); },
2393
+ children: [
2394
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechT", children: t("secAuth") }),
2395
+ infoOpen ? null : react_jsx_runtime.jsx("span", { className: "dshcb-sechS", children: sumLine }),
2396
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechIco", children: Ico(infoOpen ? "chevDown" : "chevRight", 16) }),
2397
+ ] }),
2398
+ infoOpen ? react_jsx_runtime.jsx("div", { className: "dshcb-table", children: authRows.map(function (r, i) {
2399
+ return react_jsx_runtime.jsxs("div", { className: "dshcb-tr", children: [
2400
+ react_jsx_runtime.jsx("span", { className: "dshcb-tk", children: r[0] }),
2401
+ react_jsx_runtime.jsx("span", { className: "dshcb-tv" + (r[2] ? " dshcb-" + r[2] : ""), children: r[1] }),
2402
+ ] }, "tr-" + i);
2403
+ }) }) : null,
2404
+ ] });
2405
+
2406
+ const syncPanel = connected ? react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2407
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sech", children: [
2408
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechT", children: t("syncTitle") }),
2409
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sechR", children: [
2410
+ react_jsx_runtime.jsx(Seg, {
2411
+ items: [{ label: t("syncOff"), value: "off" }, { label: t("syncOn"), value: "on" }],
2412
+ value: syncOn ? "on" : "off",
2413
+ onPick: function (v) { saveSched({ autoUpload: v === "on" }); },
2414
+ disabled: !!schedBusy, small: true,
2415
+ }),
2416
+ ] }),
2417
+ ] }),
2418
+ react_jsx_runtime.jsx("div", { className: "dshcb-line", children: [
2419
+ react_jsx_runtime.jsx("span", { className: "dshcb-lineText", children: syncOn ? t("syncOnLine") : t("syncOffLine") }),
2420
+ ] }),
2421
+ ] }) : null;
2422
+
2423
+ // 未连接时不显示入口设置:这一行的意义是「连上之后想在哪儿看到它」
2424
+ const sidePanel = !connected ? null : react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2425
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sech", children: [
2426
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechT", children: t("sideEntry") }),
2427
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sechR", children: [
2428
+ react_jsx_runtime.jsx(Seg, {
2429
+ items: [{ label: t("syncOff"), value: "off" }, { label: t("syncOn"), value: "on" }],
2430
+ value: sideOn ? "on" : "off",
2431
+ onPick: function (v) { const on = v === "on"; setSideEntryOn(on); saveSched({ sidebarEntry: on }); },
2432
+ disabled: !!schedBusy, small: true,
2433
+ }),
2434
+ ] }),
2435
+ ] }),
2436
+ react_jsx_runtime.jsx("div", { className: "dshcb-line", children: [
2437
+ react_jsx_runtime.jsx("span", { className: "dshcb-lineText", children: sideOn ? t("sideEntryOn") : t("sideEntryOff") }),
2438
+ ] }),
2439
+ ] });
2440
+
2441
+ const schedPanel = connected ? react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2442
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sech", children: [
2443
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechT", children: t("schedTitle") }),
2444
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sechR", children: [
2445
+ react_jsx_runtime.jsx(Seg, {
2446
+ items: intervalOptions.map(function (m) { return { label: (m / 60) + t("schedHours"), value: m }; }),
2447
+ value: curInterval, onPick: function (m) { saveSched({ intervalMinutes: Number(m), enabled: true }); },
2448
+ disabled: !schedOn,
2449
+ }),
2450
+ react_jsx_runtime.jsx(Seg, {
2451
+ items: [{ label: t("schedOffShort"), value: "off" }, { label: t("schedOnShort"), value: "on" }],
2452
+ value: schedOn ? "on" : "off", onPick: function (v) { saveSched({ enabled: v === "on" }); },
2453
+ }),
2454
+ ] }),
2455
+ ] }),
2456
+ react_jsx_runtime.jsxs("div", { className: "dshcb-line", children: [
2457
+ react_jsx_runtime.jsx("span", { className: "dshcb-lineText", children: schedOn
2458
+ ? (t("schedOnLine") + t("schedNextLine") + ":" + (schedNextAt ? fmtStamp(schedNextAt) : t("schedPending"))
2459
+ + (sch.running ? " · " + t("backupRunning") : ""))
2460
+ : t("schedOffHint") }),
2461
+ react_jsx_runtime.jsx("button", {
2462
+ type: "button", className: "dshcb-btn d2", disabled: !!busy || !!bstate.running, onClick: doBackup,
2463
+ children: busy ? t("busy") : bstate.running ? t("backupRunning") : t("backupNow") }),
2464
+ ] }),
2465
+ ] }) : null;
2466
+
2467
+ // ④ 最近备份:工具条 + 快照列表 + 还原操作
2468
+
2469
+ // 消息层:所有「需要用户知道的状况」都由状态派生、只在这一处渲染,不落库、不重复提示
2470
+ // 云端首次读取失败常常发生在登录 / 续期刚起步的那几秒(面板挂载后本身还会自动重试),
2471
+ // 失败要持续住 CLOUD_GRACE_MS 才提示,避免登录/续期起步阶段的瞬时读取失败误报
2472
+ const cloudFailing = !!(snaps && snaps.cloudOk === false);
2473
+ const [cloudGraceDone, setCloudGraceDone] = react.useState(false);
2474
+ const [laneHidden, setLaneHidden] = react.useState({});
2475
+ react.useEffect(function () {
2476
+ if (!cloudFailing) { if (cloudGraceDone) setCloudGraceDone(false); return; }
2477
+ if (cloudGraceDone) return;
2478
+ const tm = setTimeout(function () { setCloudGraceDone(true); }, CLOUD_GRACE_MS);
2479
+ return function () { clearTimeout(tm); };
2480
+ }, [cloudFailing, cloudGraceDone]);
2481
+ const rsBusyCard = (rstate.busy === "run" ? react_jsx_runtime.jsxs("div", { className: "dshcb-rsCard", children: [
2482
+ react_jsx_runtime.jsx("span", { className: "dshcb-rsTxt", children: rsCancelling ? t("rsStopping") : t("rsBusyText") }),
2483
+ react_jsx_runtime.jsx("span", { className: rsTotal > 0 ? "dshcb-rsBar" : "dshcb-rsBar dshcb-rsBar--indet", children:
2484
+ react_jsx_runtime.jsx("i", { style: rsTotal > 0 ? { width: rsPct + "%" } : null }) }),
2485
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn ghost", disabled: rsCancelling,
2486
+ onClick: doCancelRestore, children: rsCancelling ? t("rsStopping") : t("rsCancel") }),
2487
+ ] }) : null);
2488
+ const rsDoneCard = ((needsRestart && lrNote) ? react_jsx_runtime.jsxs("div", { className: "dshcb-rsCard", children: [
2489
+ react_jsx_runtime.jsxs("span", { className: "dshcb-rsTxt", children: [
2490
+ t("rsDoneText").replace("{s}", String(lrNote.stamp || rpick || "")),
2491
+ t("rsDoneSep"),
2492
+ react_jsx_runtime.jsx("span", { className: "dshcb-rsNeed", children: t("rsNeedApply") }),
2493
+ ] }),
2494
+ react_jsx_runtime.jsx("span", { className: "dshcb-rsGap" }),
2495
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn d2", disabled: rstate.busy === "restart",
2496
+ onClick: doRestartHost, children: rstate.busy === "restart" ? t("restarting") : t("restartNow") }),
2497
+ ] }) : null);
2498
+ const laneMsgs = [];
2499
+ if (cloudFailing && cloudGraceDone) {
2500
+ const kind = (snaps.cloud && snaps.cloud.errorKind) || "network";
2501
+ const cached = !!(snaps.cloud && snaps.cloud.cached);
2502
+ // pending:登录 / 续期还没就绪(凭据里暂时没有令牌),这不是故障状态,等自动重试即可,不打扰用户
2503
+ const spec = (kind === "pending")
2504
+ ? null
2505
+ : ((kind === "auth")
2506
+ ? { lv: "blocker", tk: "cloudAuthTitle", dk: "cloudAuthHint", act: t("cloudRelogin"), on: doRelogin }
2507
+ : ((kind === "config")
2508
+ ? { lv: "blocker", tk: "cloudConfigTitle", dk: "cloudConfigHint", act: t("cloudRelogin"), on: doRelogin }
2509
+ : { lv: "warn", tk: "cloudDownTitle", dk: "cloudDownHint", act: t("cloudDownRetry"), on: function () { doRefreshSnaps(); } }));
2510
+ if (spec) laneMsgs.push({ key: "cloud", level: spec.lv, title: t(spec.tk),
2511
+ detail: t(spec.dk),
2512
+ extra: cached ? t("cloudCachedTag") : "", act: spec.act, onAct: spec.on });
2513
+ }
2514
+ if (prune.note) laneMsgs.push({ key: "prune", level: "info", title: prune.note, onClose: function () { setPrune({ plan: null, note: "" }); } });
2515
+ if (lrNote && !needsRestart) laneMsgs.push({ key: "lr", level: ((lrNote.failed || 0) > 0 || lrNote.ok === false) ? "warn" : "info",
2516
+ title: t("lrTitle") + " " + lrRowText(lrNote) + (lrNote.firstError ? "(" + lrNote.firstError + ")" : ""),
2517
+ restart: needsRestart, onClose: function () { setLrNote(null); } });
2518
+ const laneKeyOf = function (m, i) { return m.key + "-" + i + ":" + String(m.title || ""); };
2519
+ // 下载进度也是一张卡片:和还原卡片同处「最近备份」与列表之间
2520
+ const pullCard = (pullInfo ? react_jsx_runtime.jsxs("div", { className: "dshcb-rsCard dshcb-pullRow", children: [
2521
+ react_jsx_runtime.jsx("span", { className: "dshcb-pullTxt", children:
2522
+ // 主百分比 = 本次要下载的块完成度(与“还剩几块”始终自洽);字节数与快照完整度作为补充信息
2523
+ t("pullProg") + " "
2524
+ + (pullInfo.total > 0 ? pullInfo.done + " / " + pullInfo.total + " " + t("pullBlobs")
2525
+ + " (" + Math.round((pullInfo.done / pullInfo.total) * 100) + "%)" : "…")
2526
+ + (pullInfo.needBytes > 0 ? " · " + fmtSize(pullInfo.bytes) + " / "
2527
+ + fmtSize(pullInfo.needBytes) : "")
2528
+ + (pullInfo.all > 0 ? " · " + t("pullWhole") + " " + Math.min((pullInfo.present || 0) + (pullInfo.done || 0), pullInfo.all) + " / " + pullInfo.all : "")
2529
+ + (pullInfo.scope > 0 ? " · " + t("pullScopeBlocks").replace("{s}", String(pullInfo.scope)).replace("{r}", String(pullInfo.ready || 0)) : "") }),
2530
+ pullInfo.paused
2531
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-badge muted", children: t("pullPausedTag") })
2532
+ : null,
2533
+ pullInfo.paused
2534
+ ? react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn ghost",
2535
+ onClick: function () { doPull(pullInfo.stamp || rpick); }, children: t("pullResume") })
2536
+ : react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn ghost",
2537
+ onClick: doPausePull, children: t("pullPause") }),
2538
+ ] }) : null);
2539
+
2540
+ const laneItems = laneMsgs.map(function (m, i) { return { m: m, k: laneKeyOf(m, i) }; });
2541
+ const laneAutoSig = laneItems.filter(function (x) { return !x.m.act && !x.m.restart; }).map(function (x) { return x.k; }).join("|");
2542
+ react.useEffect(function () {
2543
+ setLaneHidden({});
2544
+ if (!laneAutoSig) return;
2545
+ const tm = setTimeout(function () {
2546
+ const next = {};
2547
+ laneAutoSig.split("|").forEach(function (k) { next[k] = true; });
2548
+ setLaneHidden(next);
2549
+ }, LANE_TTL_MS);
2550
+ return function () { clearTimeout(tm); };
2551
+ }, [laneAutoSig]);
2552
+ const laneShown = laneItems.filter(function (x) { return !laneHidden[x.k]; });
2553
+ const lane = (laneShown.length || pullCard || rsBusyCard || rsDoneCard) ? react_jsx_runtime.jsx("div", { className: "dshcb-lane", children: laneShown.map(function (x) {
2554
+ const m = x.m;
2555
+ const mk = x.k;
2556
+ return react_jsx_runtime.jsxs("div", { className: "dshcb-msg dshcb-msg--" + m.level, key: mk, children: [
2557
+ react_jsx_runtime.jsxs("span", { className: "dshcb-msgMain", children: [
2558
+ react_jsx_runtime.jsx("span", { className: "dshcb-msgT", children: m.title }),
2559
+ m.detail ? react_jsx_runtime.jsx("span", { className: "dshcb-msgD", children: m.detail }) : null,
2560
+ m.extra ? react_jsx_runtime.jsx("span", { className: "dshcb-msgD", children: m.extra }) : null,
2561
+ ] }),
2562
+ react_jsx_runtime.jsxs("span", { className: "dshcb-msgAct", children: [
2563
+ m.restart ? react_jsx_runtime.jsx("span", { className: "dshcb-needRestart", children: "· " + t("rsRestartChip") }) : null,
2564
+ m.restart ? react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn d2", disabled: rstate.busy === "restart",
2565
+ onClick: doRestartHost, children: rstate.busy === "restart" ? t("restarting") : t("restartNow") }) : null,
2566
+ m.act ? react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn d2", disabled: !!viewBusy, onClick: m.onAct, children: m.act }) : null,
2567
+ m.onClose ? react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-msgClose", title: t("lrHideNote"), onClick: m.onClose, children: "✕" }) : null,
2568
+ ] }),
2569
+ ] }, mk);
2570
+ }).concat([pullCard, rsBusyCard, rsDoneCard]) }) : null;
2571
+
2572
+ const renderSnapRow = function (x) {
2573
+ const on = rpick === x.stamp;
2574
+ const exp = rexpand === x.stamp; // 目录树展开态(与「选中」分离:收起不清空还原目标)
2575
+ const human = (x.created_at ? fmtStamp(x.created_at) : x.stamp);
2576
+ // 云端视图的行:只知道云端有;副标题标明「本地也有 / 仅云端」
2577
+ const meta = x.broken ? t("restoreNoManifest")
2578
+ : (joinNum(t("restoreFiles"), x.files || 0) + " · " + joinNum(t("sizeWord"), fmtSize(x.bytes))
2579
+ + (x.missingBlobs ? " · " + x.missingBlobs + " " + t("restoreMiss") : ""));
2580
+ const badge = x.state === "uploaded"
2581
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-badge", children: t("stateUploaded") })
2582
+ : (x.state === "unknown"
2583
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-badge muted", children: t("stateUnknown") })
2584
+ : (x.state === "nosync"
2585
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-badge muted", children: t("stateNoSync") })
2586
+ : (x.state === "failed"
2587
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-badge err", ...tipProps(x.uploadError ? String(x.uploadError) : t("stateFailed")), children: t("stateFailed") })
2588
+ : react_jsx_runtime.jsx("span", { className: "dshcb-badge warn", children: t("statePending") }))));
2589
+ return react_jsx_runtime.jsxs("div", {
2590
+ key: x.stamp, className: "dshcb-item" + ((batch ? bsel.indexOf(x.stamp) >= 0 : on) ? " on" : "") + (exp && !batch ? " open" : "") + (batch ? " dshcb-batch" : ""),
2591
+ onClick: function () {
2592
+ if (batch) { toggleBsel(x.stamp); return; }
2593
+ if (rexpand === x.stamp) { setRexpand(null); return; } // 再点同一行 = 收起列表
2594
+ setRexpand(x.stamp);
2595
+ if (rpick !== x.stamp) setRpick(x.stamp);
2596
+ // 本地有缓存就读本地;只有“云端有、本地缓存已清”的行才去云端取目录树
2597
+ doLoadTree(x.stamp, x.hasCache === false && x.inCloud === true);
2598
+ },
2599
+ children: [
2600
+ react_jsx_runtime.jsxs("span", { className: "dshcb-rowMain", children: [
2601
+ react_jsx_runtime.jsx("span", {
2602
+ className: "dshcb-radio" + ((batch ? bsel.indexOf(x.stamp) >= 0 : on) ? " on" : ""),
2603
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); if (batch) { toggleBsel(x.stamp); return; } setRpick(x.stamp); },
2604
+ children: (batch ? bsel.indexOf(x.stamp) >= 0 : on) ? Ico("check", 12) : null }),
2605
+ react_jsx_runtime.jsx("span", { className: "dshcb-fico", children: Ico("folder", 22) }),
2606
+ react_jsx_runtime.jsxs("span", { className: "dshcb-itxt", children: [
2607
+ react_jsx_runtime.jsxs("span", { className: "dshcb-ititle", children: [
2608
+ react_jsx_runtime.jsxs("span", { className: "dshcb-itname", children: [human + " ",
2609
+ react_jsx_runtime.jsx("span", { className: "dshcb-itag", children: t("snapWord") })] }),
2610
+ badge,
2611
+ ] }),
2612
+ react_jsx_runtime.jsxs("span", { className: "dshcb-isub", children: ["ID:" + x.stamp, "\u00A0\u00A0\u00A0", meta] }),
2613
+ ] }),
2614
+ react_jsx_runtime.jsx(TipLayer, {}, "rowtip"),
2615
+ batch ? null : react_jsx_runtime.jsxs("span", { className: "dshcb-iacts", children: [
2616
+ // 「下载」只在“云端有、本地没缓存”时才有意义(本地已有缓存时它只是重复下载)
2617
+ (x.state === "uploaded" && x.hasCache === false) || (pullInfo && pullInfo.stamp === x.stamp) ? react_jsx_runtime.jsxs("button", { type: "button", className: "dshcb-tool",
2618
+ disabled: !!rstate.busy || !!sbusy || !!(pullInfo && pullInfo.stamp === x.stamp),
2619
+ ...tipProps(t("pullItem")),
2620
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); setRpick(x.stamp); doPull(x.stamp); },
2621
+ children: [Ico("cloudDown", 15), react_jsx_runtime.jsx("span", { children:
2622
+ (pullInfo && pullInfo.stamp === x.stamp) ? t("restorePulling")
2623
+ : (rstate.busy === "pull" && rpick === x.stamp ? t("busy") : t("pullItem")) })] }) : null,
2624
+ // 本地已有副本、但云端枚举不可用的行:同样给行内「上传」入口(就在「删除」旁边)
2625
+ // 失败过的叫「重传」(原因进 title),其余叫「上传」
2626
+ (x.state === "pending" || x.state === "failed" || x.state === "unknown") ? react_jsx_runtime.jsxs("button", { type: "button", className: "dshcb-tool" + (x.state === "failed" ? " warn" : ""),
2627
+ ...tipProps(x.uploadError ? String(x.uploadError) : (x.state === "failed" ? t("retryUpload") : t("uploadBtn"))),
2628
+ disabled: !!rstate.busy || !!sbusy,
2629
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); setRpick(x.stamp); doUpload(x.stamp); },
2630
+ children: [Ico("cloudUp", 15), react_jsx_runtime.jsx("span", { children: sbusy === "upload" && rpick === x.stamp ? t("busy") : (x.state === "failed" ? t("retryUpload") : t("uploadBtn")) })] }) : null,
2631
+ react_jsx_runtime.jsxs("button", { type: "button", className: "dshcb-tool",
2632
+ disabled: !!rstate.busy || !!sbusy,
2633
+ ...tipProps(t("delBackupLead")),
2634
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); setRpick(x.stamp); doDelete(x.stamp); },
2635
+ children: [Ico("trash", 15), react_jsx_runtime.jsx("span", { children: sbusy === "del" && rpick === x.stamp ? t("busy") : t("delBackupBtn") })] }),
2636
+ ] }),
2637
+ react_jsx_runtime.jsx("span", { className: "dshcb-ichev" + (exp ? " open" : ""), children: Ico(exp ? "chevDown" : "chevRight", 16) }),
2638
+ ] }),
2639
+ (exp && tree.stamp === x.stamp && tree.error) ? react_jsx_runtime.jsx("div", { className: "dshcb-tree dshcb-treeLoad dshcb-errLine", children: t("restoreLoadFail") + tree.error }) : null,
2640
+ (exp && tree.stamp === x.stamp && tree.loading) ? react_jsx_runtime.jsx("div", { className: "dshcb-tree dshcb-treeLoad", children: [
2641
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelbar", style: { width: "42%" } }),
2642
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelbar dshcb-skelbar2", style: { width: "84%" } }),
2643
+ ] }) : null,
2644
+ (exp && tree.stamp === x.stamp && tree.nodes.length) ? react_jsx_runtime.jsx("div", { className: "dshcb-tree", children: [treeHead(x.stamp, tree.nodes)].concat(tree.nodes.map(function (n) {
2645
+ const sub = [dirRaw(n.name), dirNote(n.name)].filter(Boolean).join(" — ");
2646
+ const onSel = !!(pickSel && pickSel.stamp === x.stamp && pickSel.on && pickSel.on[n.name]);
2647
+ return react_jsx_runtime.jsxs("div", { className: "dshcb-tn" + (onSel ? " on" : ""),
2648
+ onClick: function (ev) { if (ev && ev.stopPropagation) ev.stopPropagation(); togglePick(x.stamp, n.name); }, children: [
2649
+ react_jsx_runtime.jsx("span", { className: "dshcb-radio" + (onSel ? " on" : ""),
2650
+ children: onSel ? Ico("check", 12) : null }),
2651
+ react_jsx_runtime.jsxs("span", { className: "dshcb-tnBody", children: [
2652
+ react_jsx_runtime.jsx("div", { className: "dshcb-tnName", children: dirLabel(n.name) }),
2653
+ sub ? react_jsx_runtime.jsx("div", { className: "dshcb-tnSub", children: sub }) : null,
2654
+ ] }),
2655
+ react_jsx_runtime.jsx("span", { className: "dshcb-tnMeta",
2656
+ children: (n.files || 0) + " " + t("restoreFiles") + " · " + fmtSize(n.bytes) }),
2657
+ ] }, n.name);
2658
+ })) }) : null,
2659
+ ],
2660
+ });
2661
+ };
2662
+
2663
+ // 单一列表:备份 = 云端的一份快照(真源);本地只是缓存,不单独成列表。
2664
+ const rows = (snaps && snaps.items) || [];
2665
+ const totals = (snaps && snaps.totals) || {};
2666
+ const emptyRow = function (text, key) {
2667
+ return react_jsx_runtime.jsx("div", { className: "dshcb-grpEmpty", children: text }, "empty-" + key);
2668
+ };
2669
+ // 骨架屏占位行:短条 + 长条,流光扫过;只在“真的在等数据”时出现
2670
+ const skelRows = function (n, keyPrefix) {
2671
+ const out = [];
2672
+ for (let si = 0; si < (n || 2); si++) {
2673
+ const k = (keyPrefix || "skel") + si;
2674
+ out.push(react_jsx_runtime.jsx("div", { className: "dshcb-item dshcb-skelrow", key: k, children: [
2675
+ react_jsx_runtime.jsx("span", { className: "dshcb-radio" }),
2676
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelico" }),
2677
+ react_jsx_runtime.jsx("span", { className: "dshcb-itxt", children: [
2678
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelbar", style: { width: "46%" } }),
2679
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelbar dshcb-skelbar2", style: { width: "72%" } }),
2680
+ ] }),
2681
+ ] }, k));
2682
+ }
2683
+ return out;
2684
+ };
2685
+ const snapItems = [];
2686
+ if (viewBusy) snapItems.push(react_jsx_runtime.jsxs("div", { className: "dshcb-listHint", children: [react_jsx_runtime.jsx("span", { className: "dshcb-spin" }, "spin-view"), t("viewBusy")] }, "view-busy"));
2687
+ const coldList = !rows.length && !(snaps && (snaps.items || []).length);
2688
+ const loadingList = coldList && sbusy === "list";
2689
+ if (loadingList) snapItems.push.apply(snapItems, skelRows(3, "skel"));
2690
+ if (coldList && !loadingList) {
2691
+ // 云端读不到 ≠ 没有备份:只有云端可用时才敢说“暂无备份”
2692
+ const cloudDownNoData = !!(snaps && snaps.cloudOk === false);
2693
+ snapItems.push(emptyRow(cloudDownNoData ? t("listUnavailable") : t("emptyList"), cloudDownNoData ? "warn" : "none"));
2694
+ }
2695
+ rows.forEach(function (x) { snapItems.push(renderSnapRow(x)); });
2696
+ const cloudDown = !!(snaps && snaps.cloudOk === false);
2697
+ const summary = cloudDown
2698
+ ? t("listSummaryNosync").replace("{n}", String((rows || []).length))
2699
+ : (t("listSummary").replace("{n}", String(totals.backups || 0))
2700
+ + ((totals.pending || 0) ? t("listSummaryPending").replace("{k}", String(totals.pending)) : "")
2701
+ + ((totals.failed || 0) ? t("listSummaryFailed").replace("{m}", String(totals.failed)) : ""));
2702
+
2703
+ const recentPanel = connected ? react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2704
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sech", children: [
2705
+ react_jsx_runtime.jsxs("span", { className: "dshcb-sechT", children: [
2706
+ t("secRecent"),
2707
+ react_jsx_runtime.jsxs("span", { className: "dshcb-tipHost", tabIndex: 0, children: [
2708
+ react_jsx_runtime.jsx("span", { className: "dshcb-infoIco", children: Ico("info", 13) }),
2709
+ react_jsx_runtime.jsx("span", { className: "dshcb-tip", role: "tooltip", children: t("recentInfoTip") }),
2710
+ ] }),
2711
+ react_jsx_runtime.jsx("span", { className: "dshcb-sechMeta", children: summary }),
2712
+ ] }),
2713
+ react_jsx_runtime.jsxs("div", { className: "dshcb-sechR dshcb-tools", children: batch ? [
2714
+ react_jsx_runtime.jsx("span", { className: "dshcb-tool dshcb-batchSum", children: bsel.length
2715
+ ? t("batchCount").replace("{n}", String(bsel.length)).replace("{mb}", fmtSize(batchBytes()))
2716
+ : t("batchNone") }),
2717
+ tool(sbusy === "bdel" ? (batchAt || t("busy")) : t("batchDeleteBtn"), "trash", doBatchDelete, false, !!sbusy || !bsel.length, bsel.length > 0),
2718
+ tool(t("batchCancel"), "close", doBatchOff, false, sbusy === "bdel"),
2719
+ ] : [
2720
+ tool(t("batchOp"), "check", doBatchOn, false, !!sbusy || !connected),
2721
+ tool(t("cacheCleanBtn"), "trash", doClearCache, false, !!sbusy || !connected),
2722
+ tool(t("snapRefresh"), "refresh", doRefreshSnaps, false, !!sbusy),
2723
+ tool(t("restorePull"), "cloudDown", function () { doPull(); }, false, !!rstate.busy || !rpick),
2724
+ ] }),
2725
+ ] }),
2726
+ lane,
2727
+ !snaps ? (slowList ? react_jsx_runtime.jsx("div", { className: "dshcb-list dshcb-listSkel", children: skelRows(2, "skl") }) : null)
2728
+ : (false ? react_jsx_runtime.jsx("div", { className: "dshcb-list dshcb-listSkel", children: [
2729
+ react_jsx_runtime.jsx("div", { className: "dshcb-skel", key: "s1" }),
2730
+ react_jsx_runtime.jsx("div", { className: "dshcb-skel", key: "s2" }),
2731
+ ] })
2732
+ : (!snapItems.length ? react_jsx_runtime.jsx("div", { className: "dshcb-lineText", style: { marginTop: 12 }, children: t("restoreNone") })
2733
+ : react_jsx_runtime.jsx("div", { className: "dshcb-list", children: snapItems }))),
2734
+ react_jsx_runtime.jsxs("div", { className: "dshcb-picked", children: [
2735
+ t("selId"), rpick
2736
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-pickedId", children: rpick })
2737
+ : ((!snaps || loadingList)
2738
+ ? react_jsx_runtime.jsx("span", { className: "dshcb-pickedId dshcb-pickedWait", children:
2739
+ react_jsx_runtime.jsx("span", { className: "dshcb-skelbar dshcb-pickedBar" }) })
2740
+ : react_jsx_runtime.jsx("span", { className: "dshcb-pickedId dshcb-pickedWait", children: t("selIdNone") })),
2741
+ rpick && plugCountOf(rpick) > 0 ? react_jsx_runtime.jsxs("span", { className: "dshcb-tipHost", tabIndex: 0, children: [
2742
+ react_jsx_runtime.jsx("span", { className: "dshcb-infoIco", children: Ico("info", 13) }),
2743
+ react_jsx_runtime.jsx("span", { className: "dshcb-tip", role: "tooltip", children: String(plugText(rpick) || "") + plugNoteText(rpick) }),
2744
+ ] }) : null,
2745
+ ] }),
2746
+ react_jsx_runtime.jsxs("div", { className: "dshcb-rbar", children: [
2747
+ react_jsx_runtime.jsx("input", { className: "dshcb-input", value: rtarget,
2748
+ placeholder: (status && status.restore && status.restore.dshHome) || t("restoreTargetHint"),
2749
+ onChange: function (e) { setRtarget(e.target.value); } }),
2750
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn", disabled: !!rstate.busy || !rpick, onClick: function () { doPreview(); },
2751
+ children: rstate.busy === "preview" ? t("busy") : t("restorePreview") }),
2752
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn d2", disabled: !!rstate.busy || !rpick, onClick: function () { doRestore(); },
2753
+ children: rstate.busy === "run" ? t("restoreRunning") : t("restoreRun") }),
2754
+ ] }),
2755
+ rpick && plugCountOf(rpick) > 0 ? react_jsx_runtime.jsxs("div", { className: "dshcb-plugRow", children: [
2756
+ react_jsx_runtime.jsxs("label", { className: "dshcb-plugChk", children: [
2757
+ react_jsx_runtime.jsx("input", { type: "checkbox", checked: withPlugins === true, onChange: function (e) { setWithPlugins(e.target.checked); } }),
2758
+ react_jsx_runtime.jsx("span", { children: t("restoreWithPlugins") }),
2759
+ ] }),
2760
+ react_jsx_runtime.jsx("span", { className: "dshcb-or", children: t("plugOr") }),
2761
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-link", onClick: doPluginPrompt, ...tipProps(t("pluginPromptTip")), children: t("pluginPrompt") }),
2762
+ ] }) : null,
2763
+ react_jsx_runtime.jsxs("div", { className: "dshcb-foot", children: [
2764
+ react_jsx_runtime.jsx("input", { type: "checkbox", checked: rconfirm, onChange: function (e) { setRconfirm(e.target.checked); } }),
2765
+ react_jsx_runtime.jsx("span", { children: t("restoreConfirm") }),
2766
+ react_jsx_runtime.jsxs("div", { className: "dshcb-footBtns", children: [
2767
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-link", onClick: doHistory,
2768
+ children: histOpen ? t("lrHistHide") : t("lrHist") }),
2769
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-link", disabled: !!rstate.busy || !rpick, onClick: doVerifyRestore,
2770
+ children: rstate.busy === "verify" ? t("busy") : t("restoreVerify") }),
2771
+ ] }),
2772
+ ] }),
2773
+ (histOpen && rhist) ? react_jsx_runtime.jsxs("div", { className: "dshcb-modalroot", onClick: function () { setHistOpen(false); }, children: [
2774
+ react_jsx_runtime.jsx("div", { className: "dshcb-mask" }),
2775
+ react_jsx_runtime.jsxs("div", { className: "dshcb-dialog dshcb-dlgHist", onClick: function (e) { e.stopPropagation(); }, children: [
2776
+ react_jsx_runtime.jsxs("div", { className: "dshcb-dlgHead", children: [
2777
+ react_jsx_runtime.jsx("h3", { className: "dshcb-dlgTitle", children: t("lrHist") }),
2778
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-dlgClose", title: t("lrHistHide"),
2779
+ onClick: function () { setHistOpen(false); }, children: "✕" }),
2780
+ ] }),
2781
+ react_jsx_runtime.jsx("div", { className: "dshcb-dlgContent", children: react_jsx_runtime.jsx("ul", { className: "dshcb-dlgList dshcb-histList", children: rhist.length
2782
+ ? rhist.map(function (h, i) {
2783
+ const pl = h.plugins || null;
2784
+ // 这之后 DSH 还没重启过:本次还原的改动尚未生效,就地标出来
2785
+ return react_jsx_runtime.jsx("li", { key: String(h.at || "") + "-" + i,
2786
+ title: [h.targetRoot || "", h.firstError || "", plFailTip(pl)].filter(Boolean).join(String.fromCharCode(10)) || undefined,
2787
+ children: lrRowText(h) });
2788
+ })
2789
+ : react_jsx_runtime.jsx("li", { className: "dshcb-histEmptyLi", children: t("lrHistEmpty") }) }) }),
2790
+ ] }),
2791
+ ] }) : null,
2792
+
2793
+ ] }) : null;
2794
+
2795
+ function buildDialog(spec) {
2796
+ return react_jsx_runtime.jsxs("div", {
2797
+ className: "dshcb-modalroot", role: "presentation", children: [
2798
+ react_jsx_runtime.jsx("div", {
2799
+ className: "dshcb-mask", "aria-hidden": "true",
2800
+ onClick: function () { answerDlg(false); },
2801
+ }),
2802
+ react_jsx_runtime.jsxs("div", {
2803
+ className: "dshcb-dialog", role: "dialog", "aria-modal": "true", "aria-label": spec.title || "",
2804
+ children: [
2805
+ react_jsx_runtime.jsxs("div", { className: "dshcb-dlgContent", children: [
2806
+ react_jsx_runtime.jsxs("div", { className: "dshcb-dlgHead", children: [
2807
+ react_jsx_runtime.jsx("h2", { className: "dshcb-dlgTitle", children: spec.title }),
2808
+ react_jsx_runtime.jsx("button", {
2809
+ type: "button", className: "dshcb-dlgClose", "aria-label": t("dlgCloseAria"),
2810
+ onClick: function () { answerDlg(false); }, children: Ico("close", 14),
2811
+ }),
2812
+ ] }),
2813
+ spec.lead ? react_jsx_runtime.jsx("p", { className: "dshcb-dlgLead", children: spec.lead }) : null,
2814
+ (spec.summary || (spec.lines && spec.lines.length) || spec.skip || spec.text) ? react_jsx_runtime.jsxs("div", {
2815
+ className: "dshcb-dlgBody", children: [
2816
+ spec.summary ? react_jsx_runtime.jsxs("div", { className: "dshcb-dlgWarn", children: [
2817
+ react_jsx_runtime.jsx("span", { className: "dshcb-dlgWarnIco", children: Ico("warn", 18) }),
2818
+ react_jsx_runtime.jsx("p", { children: spec.summary }),
2819
+ ] }) : null,
2820
+ (spec.lines && spec.lines.length) ? react_jsx_runtime.jsx("ul", {
2821
+ className: "dshcb-dlgList",
2822
+ children: spec.lines.map(function (ln) { return react_jsx_runtime.jsx("li", { children: ln }, ln); }),
2823
+ }) : null,
2824
+ spec.skip ? react_jsx_runtime.jsx("p", { className: "dshcb-dlgSkip", children: spec.skip }) : null,
2825
+ spec.text ? react_jsx_runtime.jsx("pre", { className: "dshcb-dlgPre", children: spec.text }) : null,
2826
+ ],
2827
+ }) : null,
2828
+ ] }),
2829
+ react_jsx_runtime.jsxs("div", { className: "dshcb-dlgFoot", children: [
2830
+ react_jsx_runtime.jsx("button", {
2831
+ type: "button", className: "dshcb-dbtn outline",
2832
+ onClick: function () { answerDlg(false); }, children: t("pruneCancel"),
2833
+ }),
2834
+ react_jsx_runtime.jsx("button", {
2835
+ type: "button", className: "dshcb-dbtn primary",
2836
+ onClick: function () { answerDlg(true); }, children: spec.confirm || t("dlgDelete"),
2837
+ }),
2838
+ ] }),
2839
+ ],
2840
+ }),
2841
+ ],
2842
+ });
2843
+ }
2844
+
2845
+ // 侧栏入口开关:面板里切换后立刻生效,配置加载后也会同步一次
2846
+ // 只在配置已知时同步入口:未知态(status 还没回来)不动,否则会先挂上再撤掉
2847
+ const sideKnown = sideDraftOn !== null || bkcfg.sidebarEntry !== undefined;
2848
+ react.useEffect(function () { if (sideKnown) setSideEntryOn(sideOn); }, [sideKnown, sideOn]);
2849
+
2850
+ const errPanel = tip ? react_jsx_runtime.jsx("div", {
2851
+ className: "dshcb-toast" + (tip.kind === "err" ? " err" : tip.kind === "ok" ? " ok" : ""),
2852
+ onMouseEnter: function () { if (tipHold) tipHold(true); },
2853
+ onMouseLeave: function () { if (tipHold) tipHold(false); },
2854
+ key: tip.id, children: tip.text }) : null;
2855
+
2856
+ // 确认弹窗:用 createPortal 挂到 body(与宿主 Modal 同法),点遮罩/关闭/Esc 均为取消
2857
+ const dlgNode = dlg
2858
+ ? ((react_dom && react_dom.createPortal && typeof document !== "undefined")
2859
+ ? react_dom.createPortal(buildDialog(dlg), document.body)
2860
+ : buildDialog(dlg))
2861
+ : null;
2862
+
2863
+ return react_jsx_runtime.jsxs("div", {
2864
+ className: "dshcb-card" + ((!status || !!authBusy) ? " dshcb-loading" : ""),
2865
+ children: [
2866
+ headPanel,
2867
+ react_jsx_runtime.jsx("p", { className: "dshcb-sub", children: t("subtitle") }),
2868
+ errPanel,
2869
+ authPanel,
2870
+ syncPanel,
2871
+ sidePanel,
2872
+ schedPanel,
2873
+ recentPanel,
2874
+ qrPanel,
2875
+ !connected ? react_jsx_runtime.jsxs("div", { className: "dshcb-sec", children: [
2876
+ react_jsx_runtime.jsxs("div", { className: "dshcb-actions", children: [
2877
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn d2", disabled: !!busy || !!authBusy, onClick: startQr,
2878
+ children: authBusy === "qr" ? t("busy") : (qrState === "expired" || qrState === "failed") ? t("qrRegen") : t("connect") }),
2879
+ react_jsx_runtime.jsx("button", { type: "button", className: "dshcb-btn", disabled: !!busy || !!authBusy, onClick: doImportLocal,
2880
+ children: authBusy === "import" ? t("busy") : t("importLocal") }),
2881
+ ] }),
2882
+ react_jsx_runtime.jsx("p", { className: "dshcb-lineText", style: { marginTop: 10 }, children: t("importHint") }),
2883
+ ] }) : null,
2884
+ dlgNode,
2885
+ ],
2886
+ });
2887
+ }
2888
+
2889
+ const NAV_CLOUD_PATHS = [
2890
+ "M7 14.6a3.7 3.7 0 0 1-.4-7.36A5.2 5.2 0 0 1 16.6 6.7 3.4 3.4 0 0 1 16.9 14.6",
2891
+ "M12 11.8v7.4M9.7 16.9 12 19.2 14.3 16.9",
2892
+ ];
2893
+
2894
+ function patchSettingsNavIcon() {
2895
+ if (typeof document === "undefined") return;
2896
+ let dialogs;
2897
+ // 宿主真实结构(ui-settings-general/SettingsRoot.tsx):
2898
+ try { dialogs = document.querySelectorAll('[role="dialog"][aria-modal="true"]'); }
2899
+ catch (e) { return; }
2900
+ for (let d = 0; d < dialogs.length; d++) {
2901
+ const cells = dialogs[d].querySelectorAll("nav button");
2902
+ for (let i = 0; i < cells.length; i++) {
2903
+ const b = cells[i];
2904
+ const svg = b.firstElementChild;
2905
+ if (!svg || !svg.tagName || svg.tagName.toLowerCase() !== "svg") continue;
2906
+ const labelNode = b.lastElementChild;
2907
+ const txt = ((labelNode && labelNode.textContent) || b.textContent || "").trim();
2908
+ if (txt !== t("nav")) continue; // 只认自己那一行
2909
+ // 尺寸:宿主 navIcon 是 16px(SettingsRoot.tsx size={16}),按要求再大 2px;
2910
+ // 每次都补设,防止 React 重渲染把宽高写回 16。
2911
+ svg.setAttribute("width", "18");
2912
+ svg.setAttribute("height", "18");
2913
+ if (svg.getAttribute("data-dshcb-nav") === "1") continue; // 内容换过了,只补尺寸
2914
+ svg.setAttribute("data-dshcb-nav", "1");
2915
+ svg.setAttribute("viewBox", "0 0 24 24");
2916
+ svg.setAttribute("fill", "none");
2917
+ svg.setAttribute("stroke", "currentColor");
2918
+ svg.setAttribute("stroke-width", "1.7");
2919
+ svg.setAttribute("stroke-linecap", "round");
2920
+ svg.setAttribute("stroke-linejoin", "round");
2921
+ svg.innerHTML = "";
2922
+ for (let k = 0; k < NAV_CLOUD_PATHS.length; k++) {
2923
+ const p = document.createElementNS("http://www.w3.org/2000/svg", "path");
2924
+ p.setAttribute("d", NAV_CLOUD_PATHS[k]);
2925
+ svg.appendChild(p);
2926
+ }
2927
+ }
2928
+ }
2929
+ }
2930
+
2931
+ // 左侧面板入口 + 面板本体
2932
+ // 面板列表槽里的注册值只负责画图标,行本身的按钮/文案/提示/点击切面板都由宿主完成;
2933
+ // 面板内容注册在 main 槽、key = PANEL_ID,点行时宿主切过去,不再借用设置弹窗。
2934
+ const PANEL_ID = "cloud-backup";
2935
+ const CLOUD_ICON_PATHS = [
2936
+ "M7.2 15.2a4 4 0 0 1 .5-7.96A5.6 5.6 0 0 1 18.1 9.1a3.35 3.35 0 0 1-.7 6.1",
2937
+ "M12 11.6v7.6",
2938
+ "M9.4 16.6 12 19.2l2.6-2.6",
2939
+ ];
2940
+ // null = 还没读到配置(先不挂入口,读到再决定,避免「先出现又消失」);true/false = 已知
2941
+ let panelRowWanted = null;
2942
+ let panelRowDispose = null;
2943
+ let slotApi = null;
2944
+
2945
+ function setSideEntryOn(v) {
2946
+ panelRowWanted = v !== false;
2947
+ applyPanelRow();
2948
+ }
2949
+
2950
+ function applyPanelRow() {
2951
+ try { if (panelRowDispose) { panelRowDispose(); panelRowDispose = null; } }
2952
+ catch (error) { panelRowDispose = null; }
2953
+ if (panelRowWanted !== true || !slotApi) return;
2954
+ try {
2955
+ panelRowDispose = slotApi.register(
2956
+ { name: "sidebar.panellist", id: PANEL_ID, order: 0.5, label: function () { return t("nav"); }, locale: NS },
2957
+ PanelRowGlyph,
2958
+ );
2959
+ } catch (error) {
2960
+ panelRowDispose = null;
2961
+ console.warn("[dsh-cloud-backup] 注册侧栏入口失败:", error);
2962
+ }
2963
+ }
2964
+
2965
+ // 尺寸由宿主给(展开 16 / 收起 18),描边口径与宿主图标保持一致
2966
+ function PanelRowGlyph(props) {
2967
+ const size = (props && props.size) || 18;
2968
+ return react_jsx_runtime.jsx("svg", {
2969
+ width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
2970
+ strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true",
2971
+ children: CLOUD_ICON_PATHS.map(function (d, i) { return react_jsx_runtime.jsx("path", { d: d }, i); }),
2972
+ });
2973
+ }
2974
+
2975
+ // 主面板页:把卡片原样铺在宿主工作区里,页面自己负责留白与滚动
2976
+ function CloudBackupPage() {
2977
+ return react_jsx_runtime.jsx("div", { className: "dshcb-page", children: react_jsx_runtime.jsx(CloudBackupCard, {}) });
2978
+ }
2979
+
2980
+ const inject = ["slots", "locale"];
2981
+
2982
+ function apply(ctx) {
2983
+ ctx.effect(function () {
2984
+ const locale = ctx.locale;
2985
+ if (locale && typeof locale.register === "function") locale.register(NS, DICT);
2986
+ if (locale && typeof locale.bind === "function") {
2987
+ try { t = locale.bind(NS); }
2988
+ catch (error) { console.warn("[dsh-cloud-backup] locale.bind 失败,使用内置中文文案:", error); }
2989
+ }
2990
+ return function () {};
2991
+ }, "cloud-backup: locale dictionary");
2992
+
2993
+ ctx.effect(function () {
2994
+ if (typeof document === "undefined" || typeof MutationObserver === "undefined") return function () {};
2995
+ let pending = 0;
2996
+ const schedule = function () {
2997
+ if (pending) return;
2998
+ pending = setTimeout(function () { pending = 0; try { patchSettingsNavIcon(); } catch (e) {} }, 60);
2999
+ };
3000
+ let obs = null;
3001
+ try {
3002
+ obs = new MutationObserver(schedule);
3003
+ obs.observe(document.body, { childList: true, subtree: true });
3004
+ schedule();
3005
+ } catch (e) {
3006
+ console.warn("[dsh-cloud-backup] 左栏图标修补未启用:", e);
3007
+ }
3008
+ return function () {
3009
+ if (pending) clearTimeout(pending);
3010
+ if (obs) obs.disconnect();
3011
+ };
3012
+ }, "cloud-backup: settings nav icon");
3013
+
3014
+ slotApi = ctx.slots;
3015
+
3016
+ try {
3017
+ ctx.slots.inject("settings.section", function () {
3018
+ return ctx.slots.register(
3019
+ { name: "settings.section", id: "cloud-backup", order: 45, label: function () { return t("nav"); }, locale: NS },
3020
+ CloudBackupCard,
3021
+ );
3022
+ });
3023
+ } catch (error) {
3024
+ console.error("[dsh-cloud-backup] 挂载 settings.section 失败:", error);
3025
+ }
3026
+
3027
+ // 侧栏列表入口(开关关闭时注销该行;面板本体不受影响)
3028
+ try {
3029
+ ctx.slots.inject("sidebar.panellist", function () {
3030
+ applyPanelRow();
3031
+ return function () { panelRowDispose = null; };
3032
+ });
3033
+ } catch (error) {
3034
+ console.error("[dsh-cloud-backup] 挂载 sidebar.panellist 失败:", error);
3035
+ }
3036
+
3037
+ // 入口的初始状态来自配置:读到之前不挂,读到后按 sidebarEntry 决定(读不到按默认开启)
3038
+ call("/status").then(function (r) {
3039
+ const cfg = (r && r.backup && r.backup.config) || {};
3040
+ setSideEntryOn(cfg.sidebarEntry !== false);
3041
+ }).catch(function () { if (panelRowWanted === null) setSideEntryOn(true); });
3042
+
3043
+ // 面板本体:宿主按 key 取 main 槽的内容
3044
+ try {
3045
+ ctx.slots.inject("main", function () {
3046
+ return ctx.slots.register(
3047
+ { name: "main", key: PANEL_ID, locale: NS, inject: function () { return {}; } },
3048
+ CloudBackupPage,
3049
+ );
3050
+ });
3051
+ } catch (error) {
3052
+ console.error("[dsh-cloud-backup] 挂载 main 面板失败:", error);
3053
+ }
3054
+ }
3055
+
3056
+ exports.apply = apply; exports.apply = apply;
3057
+ exports.inject = inject;
3058
+ return module.exports;
3059
+ },
3060
+ });