dsh-multi-device-config-sync 0.0.0-stage → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/assets/icon-256.png +0 -0
- package/client.js +1334 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +19 -0
- package/index.js +52 -0
- package/lib/backup.js +1087 -0
- package/lib/errors.js +67 -0
- package/lib/gist.js +343 -0
- package/lib/plugins.js +469 -0
- package/lib/routes.js +438 -0
- package/lib/store.js +73 -0
- package/lib/sync-install.js +201 -0
- package/lib/tool.js +191 -0
- package/locale/en.json +24 -0
- package/locale/zh.json +24 -0
- package/package.json +66 -4
- package/test/activation.test.mjs +141 -0
- package/test/client-decisions.test.mjs +55 -0
- package/test/client-registration.test.mjs +98 -0
- package/test/config-preview.test.mjs +454 -0
- package/test/first-run.test.mjs +104 -0
- package/test/harness.mjs +176 -0
- package/test/library.test.mjs +169 -0
- package/test/package.test.mjs +162 -0
- package/test/plugins.test.mjs +543 -0
- package/test/rename-compat.test.mjs +255 -0
- package/test/run.mjs +32 -0
- package/test/sync-install.test.mjs +338 -0
package/client.js
ADDED
|
@@ -0,0 +1,1334 @@
|
|
|
1
|
+
/** Settings → Multi-device config sync. Plans and credentials live only for the current interaction. */
|
|
2
|
+
window.__ModuleLoader__.load({
|
|
3
|
+
id: 'dsh-multi-device-config-sync',
|
|
4
|
+
factory(require) {
|
|
5
|
+
const React = require('react')
|
|
6
|
+
const h = React.createElement
|
|
7
|
+
// Package identity changed for npm; the settings section and HTTP API did not.
|
|
8
|
+
const NS = 'dsh-profile-gist-sync-plus'
|
|
9
|
+
const API = '/dsh-profile-gist-sync-plus/api'
|
|
10
|
+
const SECTION_ORDER = 16
|
|
11
|
+
const GUIDE = 'https://github.com/Xeonice/dsh-profile-gist-sync-plus#readme'
|
|
12
|
+
|
|
13
|
+
const DICT = {
|
|
14
|
+
zh: {
|
|
15
|
+
section: '多端配置同步',
|
|
16
|
+
localProfile: '本机配置',
|
|
17
|
+
profileName: '配置名称',
|
|
18
|
+
backupContents: '备份内容',
|
|
19
|
+
contents: '配置文件和插件清单',
|
|
20
|
+
unavailable: '状态不可用',
|
|
21
|
+
help: '帮助',
|
|
22
|
+
openGuide: '在新标签页打开使用指南',
|
|
23
|
+
backup: '备份本机',
|
|
24
|
+
restore: '从备份恢复',
|
|
25
|
+
more: '更多',
|
|
26
|
+
back: '返回首页',
|
|
27
|
+
cancel: '取消',
|
|
28
|
+
next: '查看预览',
|
|
29
|
+
previewAgain: '重新预览',
|
|
30
|
+
previewReceiptSource: '重新预览此来源',
|
|
31
|
+
noneYet: '尚未备份',
|
|
32
|
+
unlinked: '未关联备份目标',
|
|
33
|
+
linked: '已关联备份目标',
|
|
34
|
+
linkedGist: '已关联的 Gist',
|
|
35
|
+
gistSource: 'Gist 备份',
|
|
36
|
+
ready: '备份已就绪',
|
|
37
|
+
copy: '复制备份链接',
|
|
38
|
+
copyLink: '复制链接',
|
|
39
|
+
copied: '已复制',
|
|
40
|
+
manualCopy: '未能自动复制,请手动复制下方链接。',
|
|
41
|
+
link: '备份链接',
|
|
42
|
+
openGist: '打开 Gist',
|
|
43
|
+
privacy: '新建备份不公开列出,持链接者可读。配置文本不会自动脱敏。',
|
|
44
|
+
overwriteHint: '再次备份会覆盖已关联目标中的备份文件。',
|
|
45
|
+
overwriteReview: '更新已关联的备份?',
|
|
46
|
+
visibilityKept: '更新不会更改目标的可见性;原本公开的 Gist 仍然公开。',
|
|
47
|
+
uploadConfirm: '确认更新备份',
|
|
48
|
+
uploadRetry: '重新备份',
|
|
49
|
+
uploadScope: '上传配置和插件清单,不含插件本体或凭据库。请先检查文本文件中是否含有私密信息。',
|
|
50
|
+
uploadTarget: '上传目标',
|
|
51
|
+
newGist: '新建未公开列出的 Gist',
|
|
52
|
+
uploadUncertain: '未能核实这次上传的结果。请先检查本机记录和目标 Gist,不要重复上传。',
|
|
53
|
+
refreshFailed: '未能刷新本机状态。请重新读取状态,不必重复刚才的操作。',
|
|
54
|
+
hostMissing: '当前无法读取本机配置状态。',
|
|
55
|
+
staleHost: '当前服务未提供所需的备份接口。请重启 DSH 后再试。',
|
|
56
|
+
statusRetry: '重新读取本机状态',
|
|
57
|
+
localBusy: '正在读取本机状态…',
|
|
58
|
+
uploadBusy: '正在备份本机…',
|
|
59
|
+
previewBusy: '正在查看这次恢复会更改什么…',
|
|
60
|
+
applyBusy: '正在按预览恢复,请勿重复操作。',
|
|
61
|
+
pluginsBusy: '正在核对本机插件清单…',
|
|
62
|
+
installBusy: '正在安装已核对的插件…',
|
|
63
|
+
undoBusy: '正在撤销配置恢复…',
|
|
64
|
+
busy: '处理中…',
|
|
65
|
+
sourceIntro: '粘贴另一台电脑的备份链接,先看看这台电脑会改什么。',
|
|
66
|
+
newMachineStep1: '也可以输入 Gist ID。查看预览不会写入配置、安装插件或更改上传目标。',
|
|
67
|
+
sourceLabel: '备份链接或 Gist ID',
|
|
68
|
+
sourcePlaceholder: '粘贴 gist.github.com 备份链接或 ID',
|
|
69
|
+
changeSource: '换用其他来源',
|
|
70
|
+
source: '来源',
|
|
71
|
+
targetProfile: '本机 profile',
|
|
72
|
+
previewTitle: '恢复预览',
|
|
73
|
+
configMode: '仅恢复配置',
|
|
74
|
+
configPreview: '仅恢复配置:预览',
|
|
75
|
+
localPreview: '本地文件:恢复预览',
|
|
76
|
+
configScope: '仅写配置,不安装插件。使用完整文件范围,备份中的 .npmrc 等包管理策略文件也可能覆盖本机设置。',
|
|
77
|
+
standardTrust: '仅在信任备份和插件来源时恢复。更改影响此 profile 的所有会话;构建脚本如需批准,请单独核对。',
|
|
78
|
+
configTrust: '仅在信任整份备份时恢复。更改影响此 profile 的所有会话。',
|
|
79
|
+
configFiles: '配置文件',
|
|
80
|
+
changeFiles: '变更 %n 个配置文件',
|
|
81
|
+
fileCount: '%n 个文件',
|
|
82
|
+
add: '新增',
|
|
83
|
+
overwrite: '覆盖',
|
|
84
|
+
merge: '合并',
|
|
85
|
+
identical: '不变',
|
|
86
|
+
retained: '保留或跳过',
|
|
87
|
+
showUnchanged: '未变更的文件',
|
|
88
|
+
pluginsToInstall: '安装 %n 个插件',
|
|
89
|
+
unresolved: '无法自动安装,将跳过',
|
|
90
|
+
noSpec: '未记录可核实的来源',
|
|
91
|
+
installSource: '安装来源',
|
|
92
|
+
alreadyEnable: '已安装,恢复后加入启用清单',
|
|
93
|
+
alreadyOther: '其他已安装的包',
|
|
94
|
+
cannotVerify: '无法核实插件清单,不能确认组合恢复。',
|
|
95
|
+
cannotVerifyHint: '可到「插件」页核对本机安装情况;如只想恢复配置,请从「更多」打开范围不同的独立预览。',
|
|
96
|
+
noChanges: '已是备份中的状态',
|
|
97
|
+
filesSame: '没有配置文件需要更改。',
|
|
98
|
+
filesPluginsSame: '没有配置文件需要更改,也没有插件需要安装。',
|
|
99
|
+
noApplicable: '没有可自动应用的更改。请核对保留或需手动处理的项目。',
|
|
100
|
+
confirmCombined: '恢复并安装 %n 个插件',
|
|
101
|
+
confirmOne: '恢复并安装 1 个插件',
|
|
102
|
+
confirmFiles: '确认恢复配置',
|
|
103
|
+
confirmConfig: '确认仅恢复配置',
|
|
104
|
+
noInstall: '此操作不安装插件。',
|
|
105
|
+
reviewDone: '预览已就绪,尚未执行恢复。',
|
|
106
|
+
restoreDone: '恢复完成',
|
|
107
|
+
restoreUnverified: '上次恢复的结果尚未核实',
|
|
108
|
+
restoreAttention: '配置已恢复,仍有事项需处理',
|
|
109
|
+
changedCount: '已更改 %n 个配置文件',
|
|
110
|
+
installedCount: '已安装 %n 个插件',
|
|
111
|
+
resultDetails: '查看结果',
|
|
112
|
+
warnings: '提醒',
|
|
113
|
+
restart: '重启 DSH 后生效。',
|
|
114
|
+
uncertain: '未取得可核实的结果,部分操作可能已完成。请先核对本机状态和撤销记录,再重新预览。',
|
|
115
|
+
pluginUnknown: '无法核实完整的插件安装结果。',
|
|
116
|
+
pluginResults: '插件安装结果',
|
|
117
|
+
stillMissing: '仍缺少的包',
|
|
118
|
+
installed: '已安装',
|
|
119
|
+
present: '已存在',
|
|
120
|
+
failed: '失败',
|
|
121
|
+
skipped: '跳过',
|
|
122
|
+
pendingBuilds: '待单独批准的构建脚本',
|
|
123
|
+
buildHint: '请到「插件」页核对脚本来源,需要时单独批准;本页不会批准构建。',
|
|
124
|
+
retryHint: '处理这些事项后,重新预览可核实还缺哪些插件。',
|
|
125
|
+
undo: '撤销上次配置恢复',
|
|
126
|
+
undoConfirm: '确认撤销配置',
|
|
127
|
+
undoScope: '还原到这次恢复之前的配置,移除当时新增的文件;之后对这些文件的编辑可能丢失。',
|
|
128
|
+
undoLimit: '撤销只还原配置,不卸载插件。',
|
|
129
|
+
undoWhen: '恢复记录',
|
|
130
|
+
undoNone: '没有可撤销的配置恢复。',
|
|
131
|
+
undoDone: '配置已撤销',
|
|
132
|
+
reverted: '已还原 %n 个文件。',
|
|
133
|
+
local: '本地备份文件',
|
|
134
|
+
localHint: '导入或导出配置 JSON,不必连接 GitHub。',
|
|
135
|
+
import: '选择备份文件',
|
|
136
|
+
export: '导出配置文件',
|
|
137
|
+
chooseAgain: '重新选择文件',
|
|
138
|
+
install: '单独补装插件',
|
|
139
|
+
installHint: '只核对本机 profile 声明的包,不读取云端或恢复配置。',
|
|
140
|
+
installConfirm: '安装已核对的 %n 个插件',
|
|
141
|
+
installOne: '安装已核对的 1 个插件',
|
|
142
|
+
installTrust: '仅安装你信任的来源。插件可能运行代码;本次操作不会批准新的构建脚本。',
|
|
143
|
+
allPresent: '本机清单中声明的包均已安装。',
|
|
144
|
+
installUnknown: '无法核实本机缺少哪些插件。请检查「插件」页。',
|
|
145
|
+
refreshInventory: '重新检查插件',
|
|
146
|
+
inventoryChanged: '本机清单已改变。请核对新的安装来源,再决定是否安装。',
|
|
147
|
+
target: '管理备份目标',
|
|
148
|
+
targetHint: '这里只管理以后上传的位置,不读取或修改云端。恢复时临时填写的来源不会保存为目标。',
|
|
149
|
+
targetNew: '下次备份的目标',
|
|
150
|
+
targetInput: '新的 Gist 链接或 ID',
|
|
151
|
+
targetEmpty: '留空则下次备份新建 Gist',
|
|
152
|
+
targetWarning: '保存后,下次备份将覆盖这个 Gist 中的备份文件。',
|
|
153
|
+
saveTarget: '保存备份目标',
|
|
154
|
+
targetSaved: '备份目标已保存。',
|
|
155
|
+
targetChanged: '本机备份目标或备份选项已改变。请先核对最新范围。',
|
|
156
|
+
diagnostics: '诊断与高级设置',
|
|
157
|
+
diagnosticsHint: '以下为本机记录,不代表已经检查云端。',
|
|
158
|
+
lastUpload: '最近一次上传',
|
|
159
|
+
lastSync: '最近一次云端恢复',
|
|
160
|
+
never: '暂无记录',
|
|
161
|
+
settingsFile: '本机设置文件',
|
|
162
|
+
profileRoot: 'profile 目录',
|
|
163
|
+
includeMachine: '备份和导出时包含本机用量统计(data/usage.json)',
|
|
164
|
+
machineSaved: '已更新备份范围。',
|
|
165
|
+
machineIncluded: '包含本机用量统计。',
|
|
166
|
+
machineExcluded: '不包含本机用量统计。',
|
|
167
|
+
localInventory: '本机文件清单',
|
|
168
|
+
defaultInventory: '基本备份范围(不含可选的用量统计)',
|
|
169
|
+
excluded: '默认排除',
|
|
170
|
+
limits: '大小上限:整份备份 / 单个 Gist 文件',
|
|
171
|
+
droppedDeps: '未上传的本机路径依赖',
|
|
172
|
+
repair: '修复 GitHub 访问',
|
|
173
|
+
tokenLabel: '仅供本次请求的 GitHub 令牌',
|
|
174
|
+
tokenHelp: '可以填写有 gist 权限的令牌;也可在启动环境中设置 DSH_GITHUB_TOKEN / GITHUB_TOKEN 后重启,或在本机执行 gh auth login。更新已有 Gist 还需对它有写权限。',
|
|
175
|
+
tokenPrivacy: '令牌不保存,发送一次后清空;恢复确认不会再次发送。',
|
|
176
|
+
authRetry: '留空重试会使用本机凭据。',
|
|
177
|
+
'reason.no-plugin-manager': '未提供插件管理服务',
|
|
178
|
+
'reason.plugin-manager-error': '读取插件清单失败',
|
|
179
|
+
'note.local-path': '本机路径,无法自动安装',
|
|
180
|
+
'note.workspace-protocol': 'workspace: 声明,无法在这台电脑解析',
|
|
181
|
+
'note.missing-source': '缺少可核实的安装来源',
|
|
182
|
+
'note.unsupported-source': '不支持自动安装此来源',
|
|
183
|
+
'note.invalid-name': '包名无效',
|
|
184
|
+
'note.stale-plan': '安装清单已改变,请重新预览',
|
|
185
|
+
'note.legacy-sync-package': '不自动补装此插件的旧 Git 包,请在「插件」中管理',
|
|
186
|
+
'note.local-sync-package': '同步插件本身请在「插件」中安装或更新',
|
|
187
|
+
'code.legacy-sync-package': '已跳过旧版同步插件,不会从备份安装或启用',
|
|
188
|
+
'code.local-sync-package': '保留本机同步插件的安装来源和启用状态',
|
|
189
|
+
'code.dependency': '依赖目录',
|
|
190
|
+
'code.lockfile': '锁文件',
|
|
191
|
+
'code.hidden-dir': '隐藏目录',
|
|
192
|
+
'code.backup-copy': '备份副本',
|
|
193
|
+
'code.symlink': '符号链接',
|
|
194
|
+
'code.machine-state': '本机用量',
|
|
195
|
+
'code.credential': '凭据库',
|
|
196
|
+
'code.binary': '二进制',
|
|
197
|
+
'code.too-large': '文件过大',
|
|
198
|
+
'code.tool-state': '临时状态',
|
|
199
|
+
'code.local-dependency': '本机路径依赖',
|
|
200
|
+
'code.local-policy': '按本机策略保留,不覆盖',
|
|
201
|
+
'err.bad-source': '请输入 Gist ID,或标准的 https://gist.github.com 备份链接(不要附加参数、片段或凭据)。',
|
|
202
|
+
'err.auth': 'GitHub 未授权本次访问。',
|
|
203
|
+
'err.rate-limit': 'GitHub 已限流,或当前凭据权限不足。可以稍后再试。',
|
|
204
|
+
'err.session-auth': 'DSH 拒绝了本次请求。请检查 DSH 登录状态和访问地址。',
|
|
205
|
+
'err.notfound': '未找到资源。请核对备份链接和访问权限;如果服务刚更新,请重启 DSH。',
|
|
206
|
+
'err.stale-plan': '预览已失效、被使用或本机状态已改变。请重新预览。',
|
|
207
|
+
'err.busy': '另一项恢复或安装正在进行。请稍后重新预览。',
|
|
208
|
+
'err.invalid': '备份或请求无效,请核对后重试。',
|
|
209
|
+
'err.invalidJson': '这不是有效的备份 JSON 文件。',
|
|
210
|
+
'err.too-large': '备份超出大小上限。',
|
|
211
|
+
'err.timeout': '请求超时。',
|
|
212
|
+
'err.network': '无法连接服务。',
|
|
213
|
+
'err.no-profile': 'DSH 未以 profile 启动,没有可读取的本机配置。',
|
|
214
|
+
'err.no-cloud': '尚未关联备份,请输入来源链接。',
|
|
215
|
+
'err.unsafe-path': '备份中含不安全的路径,已拒绝恢复。',
|
|
216
|
+
'err.nothing-to-undo': '没有可撤销的恢复记录。',
|
|
217
|
+
'err.bad-response': '服务没有返回可核实的完整数据。',
|
|
218
|
+
'err.other': '操作未能完成。',
|
|
219
|
+
},
|
|
220
|
+
en: {
|
|
221
|
+
section: 'Multi-device config sync',
|
|
222
|
+
localProfile: 'Local configuration',
|
|
223
|
+
profileName: 'Profile',
|
|
224
|
+
backupContents: 'Backup contents',
|
|
225
|
+
contents: 'Configuration files and plugin manifest',
|
|
226
|
+
unavailable: 'Status unavailable',
|
|
227
|
+
help: 'Help',
|
|
228
|
+
openGuide: 'Open the guide in a new tab',
|
|
229
|
+
backup: 'Back up this machine',
|
|
230
|
+
restore: 'Restore from backup',
|
|
231
|
+
more: 'More',
|
|
232
|
+
back: 'Back to home',
|
|
233
|
+
cancel: 'Cancel',
|
|
234
|
+
next: 'View preview',
|
|
235
|
+
previewAgain: 'Preview again',
|
|
236
|
+
previewReceiptSource: 'Preview this source again',
|
|
237
|
+
noneYet: 'No backup yet',
|
|
238
|
+
unlinked: 'No backup destination linked',
|
|
239
|
+
linked: 'Backup destination linked',
|
|
240
|
+
linkedGist: 'Linked Gist',
|
|
241
|
+
gistSource: 'Gist backup',
|
|
242
|
+
ready: 'Backup ready',
|
|
243
|
+
copy: 'Copy backup link',
|
|
244
|
+
copyLink: 'Copy link',
|
|
245
|
+
copied: 'Copied',
|
|
246
|
+
manualCopy: 'Automatic copy was unavailable. Select and copy the link below.',
|
|
247
|
+
link: 'Backup link',
|
|
248
|
+
openGist: 'Open Gist',
|
|
249
|
+
privacy: 'New backups are unlisted. Anyone with the link can read them. Configuration text is not redacted.',
|
|
250
|
+
overwriteHint: 'Backing up again overwrites the backup file at the linked destination.',
|
|
251
|
+
overwriteReview: 'Update the linked backup?',
|
|
252
|
+
visibilityKept: 'Updating a Gist does not change visibility. A public Gist stays public.',
|
|
253
|
+
uploadConfirm: 'Confirm backup update',
|
|
254
|
+
uploadRetry: 'Retry backup',
|
|
255
|
+
uploadScope: 'Uploads settings and the plugin manifest, not plugin packages or credential stores. Check text files for private information first.',
|
|
256
|
+
uploadTarget: 'Upload destination',
|
|
257
|
+
newGist: 'Create an unlisted Gist',
|
|
258
|
+
uploadUncertain: 'The upload result could not be verified. Check the local record and destination Gist before uploading again.',
|
|
259
|
+
refreshFailed: 'Local status could not be refreshed. Read it again; do not repeat the previous action.',
|
|
260
|
+
hostMissing: 'Local configuration status is unavailable.',
|
|
261
|
+
staleHost: 'The running host does not provide the required backup API. Restart DSH and try again.',
|
|
262
|
+
statusRetry: 'Read local status again',
|
|
263
|
+
localBusy: 'Reading local status…',
|
|
264
|
+
uploadBusy: 'Backing up this machine…',
|
|
265
|
+
previewBusy: 'Checking what this restore would change…',
|
|
266
|
+
applyBusy: 'Applying the reviewed restore. Do not repeat the request.',
|
|
267
|
+
pluginsBusy: 'Checking the local plugin manifest…',
|
|
268
|
+
installBusy: 'Installing the reviewed plugins…',
|
|
269
|
+
undoBusy: 'Undoing the configuration restore…',
|
|
270
|
+
busy: 'Working…',
|
|
271
|
+
sourceIntro: 'Paste the link from the other computer to see what would change here.',
|
|
272
|
+
newMachineStep1: 'A Gist ID also works. A preview does not write settings, install packages or change the upload destination.',
|
|
273
|
+
sourceLabel: 'Backup link or Gist ID',
|
|
274
|
+
sourcePlaceholder: 'Paste a gist.github.com backup link or ID',
|
|
275
|
+
changeSource: 'Use a different source',
|
|
276
|
+
source: 'Source',
|
|
277
|
+
targetProfile: 'Local profile',
|
|
278
|
+
previewTitle: 'Restore preview',
|
|
279
|
+
configMode: 'Restore configuration only',
|
|
280
|
+
configPreview: 'Configuration-only preview',
|
|
281
|
+
localPreview: 'Local file restore preview',
|
|
282
|
+
configScope: 'Restores configuration without installing plugins. Full-file rules apply: package-manager policies such as .npmrc in this backup can overwrite local settings.',
|
|
283
|
+
standardTrust: 'Trust both the backup and package sources before restoring. Changes affect every session in this profile. Review any requested build scripts separately.',
|
|
284
|
+
configTrust: 'Restore only if you trust the entire backup. Changes affect every session in this profile.',
|
|
285
|
+
configFiles: 'Configuration files',
|
|
286
|
+
changeFiles: 'Configuration files to change: %n',
|
|
287
|
+
fileCount: 'Files: %n',
|
|
288
|
+
add: 'Add',
|
|
289
|
+
overwrite: 'Overwrite',
|
|
290
|
+
merge: 'Merge',
|
|
291
|
+
identical: 'Unchanged',
|
|
292
|
+
retained: 'Retained or skipped',
|
|
293
|
+
showUnchanged: 'Unchanged files',
|
|
294
|
+
pluginsToInstall: 'Plugins to install: %n',
|
|
295
|
+
unresolved: 'Cannot install automatically — will skip',
|
|
296
|
+
noSpec: 'No verifiable source recorded',
|
|
297
|
+
installSource: 'Install source',
|
|
298
|
+
alreadyEnable: 'Already installed; will be added to the enabled list',
|
|
299
|
+
alreadyOther: 'Other already-installed packages',
|
|
300
|
+
cannotVerify: 'The plugin inventory could not be verified. Combined restore is unavailable.',
|
|
301
|
+
cannotVerifyHint: 'Check installed packages on the Plugins page. For configuration alone, use the separate, full-scope preview under More.',
|
|
302
|
+
noChanges: 'Already matches this backup',
|
|
303
|
+
filesSame: 'No configuration files need changing.',
|
|
304
|
+
filesPluginsSame: 'No configuration files need changing and no plugins need installing.',
|
|
305
|
+
noApplicable: 'There are no changes that can be applied automatically. Review the retained items or packages that need manual attention.',
|
|
306
|
+
confirmCombined: 'Restore and install %n plugins',
|
|
307
|
+
confirmOne: 'Restore and install 1 plugin',
|
|
308
|
+
confirmFiles: 'Confirm configuration restore',
|
|
309
|
+
confirmConfig: 'Restore configuration only',
|
|
310
|
+
noInstall: 'No plugins will be installed.',
|
|
311
|
+
reviewDone: 'Preview ready. No restore has been performed.',
|
|
312
|
+
restoreDone: 'Restore complete',
|
|
313
|
+
restoreUnverified: 'Last restore result not verified',
|
|
314
|
+
restoreAttention: 'Configuration restored; some items need attention',
|
|
315
|
+
changedCount: 'Configuration files changed: %n',
|
|
316
|
+
installedCount: 'Plugins installed: %n',
|
|
317
|
+
resultDetails: 'View results',
|
|
318
|
+
warnings: 'Warnings',
|
|
319
|
+
restart: 'Restart DSH for changes to take effect.',
|
|
320
|
+
uncertain: 'The result could not be verified. Some changes may already have been applied. Check local status and undo history, then preview again.',
|
|
321
|
+
pluginUnknown: 'The complete plugin installation result could not be verified.',
|
|
322
|
+
pluginResults: 'Plugin installation results',
|
|
323
|
+
stillMissing: 'Packages still missing',
|
|
324
|
+
installed: 'Installed',
|
|
325
|
+
present: 'Already present',
|
|
326
|
+
failed: 'Failed',
|
|
327
|
+
skipped: 'Skipped',
|
|
328
|
+
pendingBuilds: 'Build scripts awaiting separate approval',
|
|
329
|
+
buildHint: 'Review the script sources on the Plugins page and approve separately if appropriate. This page never approves builds.',
|
|
330
|
+
retryHint: 'After addressing these items, preview again to check what is still missing.',
|
|
331
|
+
undo: 'Undo last configuration restore',
|
|
332
|
+
undoConfirm: 'Confirm undo',
|
|
333
|
+
undoScope: 'Return files to their state before this restore, removing files it added. Later edits to those files may be lost.',
|
|
334
|
+
undoLimit: 'Undo restores configuration only. It does not uninstall plugins.',
|
|
335
|
+
undoWhen: 'Restore record',
|
|
336
|
+
undoNone: 'There is no configuration restore to undo.',
|
|
337
|
+
undoDone: 'Configuration restore undone',
|
|
338
|
+
reverted: 'Files reverted: %n.',
|
|
339
|
+
local: 'Local backup file',
|
|
340
|
+
localHint: 'Import or export a configuration JSON file without connecting to GitHub.',
|
|
341
|
+
import: 'Choose a backup file',
|
|
342
|
+
export: 'Export configuration file',
|
|
343
|
+
chooseAgain: 'Choose the file again',
|
|
344
|
+
install: 'Install missing plugins separately',
|
|
345
|
+
installHint: 'Check packages declared in this local profile, without reading the cloud or restoring configuration.',
|
|
346
|
+
installConfirm: 'Install %n reviewed plugins',
|
|
347
|
+
installOne: 'Install 1 reviewed plugin',
|
|
348
|
+
installTrust: 'Install only sources you trust. Plugins can run code; this action does not approve new build scripts.',
|
|
349
|
+
allPresent: 'Every package declared in this profile is already installed.',
|
|
350
|
+
installUnknown: 'Missing local plugins could not be verified. Check the Plugins page.',
|
|
351
|
+
refreshInventory: 'Check plugins again',
|
|
352
|
+
inventoryChanged: 'The local manifest changed. Review the new sources before installing.',
|
|
353
|
+
target: 'Manage backup destination',
|
|
354
|
+
targetHint: 'Choose where future uploads go. This does not read or change the cloud. A temporary restore source is not saved as a destination.',
|
|
355
|
+
targetNew: 'Next backup destination',
|
|
356
|
+
targetInput: 'New Gist link or ID',
|
|
357
|
+
targetEmpty: 'Leave empty to create a Gist on the next backup',
|
|
358
|
+
targetWarning: 'After saving, the next backup overwrites the backup file in this Gist.',
|
|
359
|
+
saveTarget: 'Save backup destination',
|
|
360
|
+
targetSaved: 'Backup destination saved.',
|
|
361
|
+
targetChanged: 'The local backup destination or options changed. Review the current scope first.',
|
|
362
|
+
diagnostics: 'Diagnostics and settings',
|
|
363
|
+
diagnosticsHint: 'These are local records, not a live check of the cloud.',
|
|
364
|
+
lastUpload: 'Most recent upload',
|
|
365
|
+
lastSync: 'Most recent cloud restore',
|
|
366
|
+
never: 'No record',
|
|
367
|
+
settingsFile: 'Local settings file',
|
|
368
|
+
profileRoot: 'Profile directory',
|
|
369
|
+
includeMachine: 'Include this machine’s usage counters (data/usage.json) in backups and exports',
|
|
370
|
+
machineSaved: 'Backup scope updated.',
|
|
371
|
+
machineIncluded: 'Includes this machine’s usage counters.',
|
|
372
|
+
machineExcluded: 'Excludes this machine’s usage counters.',
|
|
373
|
+
localInventory: 'Local file list',
|
|
374
|
+
defaultInventory: 'Base backup scope (without optional usage counters)',
|
|
375
|
+
excluded: 'Excluded by default',
|
|
376
|
+
limits: 'Size limits: whole backup / Gist file',
|
|
377
|
+
droppedDeps: 'Machine-local dependencies left out of the upload',
|
|
378
|
+
repair: 'Restore GitHub access',
|
|
379
|
+
tokenLabel: 'GitHub token for this request only',
|
|
380
|
+
tokenHelp: 'Enter a token with Gist access below, set DSH_GITHUB_TOKEN / GITHUB_TOKEN in the startup environment and restart DSH, or run gh auth login on this machine. Updating an existing Gist requires write access to it.',
|
|
381
|
+
tokenPrivacy: 'The token is not saved and is cleared after one request. Restore confirmation never sends it again.',
|
|
382
|
+
authRetry: 'Leave empty to retry with local credentials.',
|
|
383
|
+
'reason.no-plugin-manager': 'Plugin manager unavailable',
|
|
384
|
+
'reason.plugin-manager-error': 'Plugin inventory could not be read',
|
|
385
|
+
'note.local-path': 'A local path cannot be installed on this machine',
|
|
386
|
+
'note.workspace-protocol': 'A workspace: reference cannot be resolved here',
|
|
387
|
+
'note.missing-source': 'No verifiable installation source',
|
|
388
|
+
'note.unsupported-source': 'This source does not support automatic installation',
|
|
389
|
+
'note.invalid-name': 'Invalid package name',
|
|
390
|
+
'note.stale-plan': 'The install list changed; preview again',
|
|
391
|
+
'note.legacy-sync-package': 'The old Git edition is not installed automatically. Manage it in Plugins.',
|
|
392
|
+
'note.local-sync-package': 'Install or update the sync plugin itself in Plugins.',
|
|
393
|
+
'code.legacy-sync-package': 'Old sync package skipped; it will not be installed or enabled from the backup',
|
|
394
|
+
'code.local-sync-package': 'The installed sync package keeps its local source and activation setting',
|
|
395
|
+
'code.dependency': 'Dependencies',
|
|
396
|
+
'code.lockfile': 'Lockfile',
|
|
397
|
+
'code.hidden-dir': 'Hidden directory',
|
|
398
|
+
'code.backup-copy': 'Backup copy',
|
|
399
|
+
'code.symlink': 'Symbolic link',
|
|
400
|
+
'code.machine-state': 'Machine usage',
|
|
401
|
+
'code.credential': 'Credential store',
|
|
402
|
+
'code.binary': 'Binary',
|
|
403
|
+
'code.too-large': 'File too large',
|
|
404
|
+
'code.tool-state': 'Temporary state',
|
|
405
|
+
'code.local-dependency': 'Machine-local dependency',
|
|
406
|
+
'code.local-policy': 'Retained by local policy; not overwritten',
|
|
407
|
+
'err.bad-source': 'Enter a Gist ID or a standard https://gist.github.com backup link without credentials, query or fragment.',
|
|
408
|
+
'err.auth': 'GitHub did not authorize this request.',
|
|
409
|
+
'err.rate-limit': 'GitHub rate-limited this request, or the credential lacks permission. You can retry later.',
|
|
410
|
+
'err.session-auth': 'DSH refused the request. Check the DSH sign-in and address.',
|
|
411
|
+
'err.notfound': 'Resource not found. Check the link and access. If the host was just updated, restart DSH.',
|
|
412
|
+
'err.stale-plan': 'This preview expired, was used, or the local state changed. Preview again.',
|
|
413
|
+
'err.busy': 'Another restore or installation is running. Preview again when it finishes.',
|
|
414
|
+
'err.invalid': 'The backup or request is not valid. Check it before retrying.',
|
|
415
|
+
'err.invalidJson': 'This file is not valid backup JSON.',
|
|
416
|
+
'err.too-large': 'The backup exceeds the size limit.',
|
|
417
|
+
'err.timeout': 'The request timed out.',
|
|
418
|
+
'err.network': 'The service is unreachable.',
|
|
419
|
+
'err.no-profile': 'DSH was not started with a profile. No local configuration is available.',
|
|
420
|
+
'err.no-cloud': 'No backup is linked. Enter a source link first.',
|
|
421
|
+
'err.unsafe-path': 'An unsafe path in the backup prevented restoration.',
|
|
422
|
+
'err.nothing-to-undo': 'There is no restore record to undo.',
|
|
423
|
+
'err.bad-response': 'The service did not return complete, verifiable data.',
|
|
424
|
+
'err.other': 'The operation could not be completed.',
|
|
425
|
+
},
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Geometry and materials follow the installed Account settings cards. The
|
|
429
|
+
// colored Button pair stays blue with on-color text in both host palettes.
|
|
430
|
+
const CSS = `
|
|
431
|
+
.dpgsp-root {
|
|
432
|
+
--ink:var(--dsw-alias-label-primary); --muted:var(--dsw-alias-label-secondary); --subtle:var(--dsw-alias-label-tertiary,var(--muted));
|
|
433
|
+
--paper:var(--dsw-alias-settings-card-fill,var(--dsw-alias-bg-layer-2)); --stroke:var(--dsw-alias-settings-card-stroke,var(--dsw-alias-border-l2));
|
|
434
|
+
--line:var(--dsw-alias-border-l2); --edge:var(--dsw-alias-border-l3,var(--line)); --hover:var(--dsw-alias-interactive-bg-hover,var(--dsw-alias-bg-layer-1));
|
|
435
|
+
--accent:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary)); --good:var(--dsw-alias-state-success-primary); --warn:var(--dsw-alias-state-warn-primary); --error:var(--dsw-alias-state-error-primary);
|
|
436
|
+
container-type:inline-size; display:flex; flex-direction:column; gap:16px; width:100%; min-width:0; padding:8px 0;
|
|
437
|
+
color:var(--ink); font:inherit; font-size:13px; line-height:22px; overflow-wrap:anywhere;
|
|
438
|
+
}
|
|
439
|
+
.dpgsp-root, .dpgsp-root *, .dpgsp-root *::before, .dpgsp-root *::after { box-sizing:border-box; }
|
|
440
|
+
.dpgsp-root :is(h2,h3,p,ul,dl,dd) { margin:0; }
|
|
441
|
+
.dpgsp-root :is(h2,h3) { font-size:14px; line-height:22px; font-weight:500; }
|
|
442
|
+
.dpgsp-root strong { font-weight:500; }
|
|
443
|
+
.dpgsp-card { width:100%; min-width:0; padding:12px 16px; border:.5px solid var(--stroke); border-radius:var(--dsw-radius-xl,16px); background:var(--paper); }
|
|
444
|
+
.dpgsp-summary, .dpgsp-identity, .dpgsp-status, .dpgsp-line, .dpgsp-source, .dpgsp-actions, .dpgsp-foot, .dpgsp-note, .dpgsp-row, .dpgsp-check { display:flex; align-items:center; }
|
|
445
|
+
.dpgsp-summary { min-height:44px; justify-content:space-between; flex-wrap:wrap; gap:6px 16px; }
|
|
446
|
+
.dpgsp-identity { min-width:0; gap:10px; }
|
|
447
|
+
.dpgsp-mark { display:grid; place-items:center; flex:none; width:32px; height:32px; border-radius:50%; corner-shape:round; color:var(--muted); background:var(--dsw-alias-bg-skeleton,var(--hover)); }
|
|
448
|
+
.dpgsp-icon { display:inline-block; flex:none; vertical-align:middle; }
|
|
449
|
+
.dpgsp-identity > div, .dpgsp-status { min-width:0; }
|
|
450
|
+
.dpgsp-status { justify-content:flex-end; flex-wrap:wrap; gap:4px 8px; color:var(--muted); }
|
|
451
|
+
.dpgsp-status [data-focus=backup-receipt] { color:var(--ink); }
|
|
452
|
+
.dpgsp-status [data-focus=backup-receipt] svg { color:var(--good); }
|
|
453
|
+
.dpgsp-subtitle { color:var(--subtle); }
|
|
454
|
+
.dpgsp-hint, .dpgsp-meta, .dpgsp-note, .dpgsp-intro { color:var(--muted); }
|
|
455
|
+
.dpgsp-note { align-items:flex-start; gap:8px; }
|
|
456
|
+
.dpgsp-note > svg { margin-top:3px; }
|
|
457
|
+
.dpgsp-actions, .dpgsp-foot { justify-content:flex-end; flex-wrap:wrap; gap:8px 10px; }
|
|
458
|
+
.dpgsp-btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; max-width:100%; min-width:min(58px,100%); min-height:36px; padding:6px 14px; border:.5px solid var(--edge); border-radius:var(--dsw-radius-md,12px); background:transparent; color:var(--ink); cursor:pointer; touch-action:manipulation; font:inherit; font-size:14px; line-height:22px; text-align:center; text-decoration:none; white-space:normal; overflow-wrap:anywhere; }
|
|
459
|
+
.dpgsp-btn.dpgsp-primary { --button-fill:var(--dsw-alias-button-info-fill,var(--dsw-alias-button-primary-fill,var(--accent))); --button-l:.56; border-color:transparent; font-weight:500; color:var(--dsw-alias-label-on-color,var(--dsw-alias-label-primary-foreground)); background:var(--button-fill); }
|
|
460
|
+
/* Cap only lightness, retaining the host's hue. The native blue alone is too
|
|
461
|
+
light for 14px white text, especially on the dark palette. */
|
|
462
|
+
@supports (color:oklch(from currentColor min(l,.56) c h)) {
|
|
463
|
+
.dpgsp-btn.dpgsp-primary { background:oklch(from var(--button-fill) min(l,var(--button-l)) c h); }
|
|
464
|
+
}
|
|
465
|
+
.dpgsp-btn.dpgsp-quiet { min-width:0; min-height:32px; padding:4px 6px; border:0; color:var(--muted); font-size:13px; }
|
|
466
|
+
@media (hover:hover) {
|
|
467
|
+
.dpgsp-btn:not(.dpgsp-primary):not(:disabled):hover { background:var(--hover); }
|
|
468
|
+
.dpgsp-btn.dpgsp-primary:not(:disabled):hover { --button-fill:var(--dsw-alias-button-info-hover,var(--dsw-alias-button-primary-hover,var(--accent))); --button-l:.53; }
|
|
469
|
+
.dpgsp-btn.dpgsp-quiet:hover, .dpgsp-help:hover { color:var(--ink); }
|
|
470
|
+
}
|
|
471
|
+
.dpgsp-root :is(button,input):disabled { opacity:.55; cursor:not-allowed; }
|
|
472
|
+
.dpgsp-root :is(button,input,summary,a):focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
|
|
473
|
+
.dpgsp-root :is(h2,h3,span)[tabindex]:focus { outline:none; }
|
|
474
|
+
.dpgsp-body { display:flex; flex-direction:column; min-width:0; }
|
|
475
|
+
.dpgsp-body > * { min-width:0; padding-block:12px; }
|
|
476
|
+
.dpgsp-body > :first-child { padding-top:4px; }
|
|
477
|
+
.dpgsp-body > :last-child { padding-bottom:4px; }
|
|
478
|
+
.dpgsp-body > * + *, .dpgsp-foot, .dpgsp-homefoot, .dpgsp-copy-feedback { border-top:.5px solid var(--line); }
|
|
479
|
+
.dpgsp-foot, .dpgsp-homefoot { margin-top:8px; padding-top:12px; }
|
|
480
|
+
.dpgsp-foot > .dpgsp-note { flex:1 1 230px; }
|
|
481
|
+
.dpgsp-foot > .dpgsp-actions { min-width:0; margin-inline-start:auto; }
|
|
482
|
+
.dpgsp-homefoot { display:grid; align-items:center; grid-template-columns:auto auto minmax(0,1fr); gap:8px 10px; }
|
|
483
|
+
.dpgsp-homefoot .dpgsp-actions { grid-area:1/3; }
|
|
484
|
+
.dpgsp-menuwrap { display:contents; }
|
|
485
|
+
.dpgsp-menuwrap > button { grid-area:1/1; }
|
|
486
|
+
.dpgsp-menuwrap > button[aria-expanded=true] svg { transform:rotate(180deg); }
|
|
487
|
+
/* Disclosure in normal flow: the host's scrolling settings column can reach
|
|
488
|
+
every option, including items below a short viewport. No portal or overlay. */
|
|
489
|
+
.dpgsp-menulist { grid-column:1 / -1; grid-row:2; display:grid; padding-top:6px; border-top:.5px solid var(--line); }
|
|
490
|
+
.dpgsp-menulist .dpgsp-btn { width:100%; min-height:40px; justify-content:flex-start; gap:10px; padding:6px; color:var(--ink); text-align:start; }
|
|
491
|
+
.dpgsp-help { grid-area:1/2; display:inline-flex; align-items:center; gap:3px; width:fit-content; min-height:32px; color:var(--muted); text-decoration:none; }
|
|
492
|
+
.dpgsp-stack, .dpgsp-group, .dpgsp-field, .dpgsp-box, .dpgsp-iteminfo { display:grid; gap:6px; min-width:0; }
|
|
493
|
+
.dpgsp-stack { gap:12px; }
|
|
494
|
+
.dpgsp-field label { font-weight:500; }
|
|
495
|
+
.dpgsp-input { width:100%; min-width:0; min-height:36px; border:.5px solid var(--edge); border-radius:var(--dsw-radius-sm,8px); padding:6px 10px; color:var(--ink); background:var(--dsw-alias-bg-layer-1); font:inherit; font-size:14px; }
|
|
496
|
+
.dpgsp-input::placeholder { color:var(--subtle); }
|
|
497
|
+
.dpgsp-input[aria-invalid=true] { border-color:var(--error); }
|
|
498
|
+
.dpgsp-check { gap:10px; cursor:pointer; }
|
|
499
|
+
.dpgsp-check input { flex:none; accent-color:var(--accent); }
|
|
500
|
+
.dpgsp-line, .dpgsp-source { gap:6px 8px; flex-wrap:wrap; }
|
|
501
|
+
.dpgsp-source { justify-content:space-between; }
|
|
502
|
+
.dpgsp-line > *, .dpgsp-source > * { min-width:0; }
|
|
503
|
+
.dpgsp-box.dpgsp-alert > :first-child, .dpgsp-box.dpgsp-warning > :first-child, .dpgsp-box.dpgsp-success > :first-child { display:flex; align-items:baseline; gap:8px; }
|
|
504
|
+
.dpgsp-box.dpgsp-alert > :first-child::before, .dpgsp-box.dpgsp-warning > :first-child::before, .dpgsp-box.dpgsp-success > :first-child::before { content:''; width:3px; height:1em; flex:none; align-self:center; border-radius:2px; background:var(--warn); }
|
|
505
|
+
.dpgsp-box.dpgsp-alert > :first-child::before { background:var(--error); }
|
|
506
|
+
.dpgsp-box.dpgsp-success > :first-child::before { background:var(--good); }
|
|
507
|
+
.dpgsp-list { list-style:none; padding:0; }
|
|
508
|
+
.dpgsp-row { min-height:40px; min-width:0; padding:6px 0; gap:10px; }
|
|
509
|
+
.dpgsp-row + .dpgsp-row, .dpgsp-facts > div + div { border-top:.5px solid var(--line); }
|
|
510
|
+
.dpgsp-row > .dpgsp-icon, .dpgsp-rowvalue { color:var(--muted); }
|
|
511
|
+
.dpgsp-row .dpgsp-iteminfo { flex:1; gap:0; }
|
|
512
|
+
.dpgsp-rowvalue { min-width:0; text-align:end; }
|
|
513
|
+
.dpgsp-root code { font: .96em/1.55 ui-monospace,SFMono-Regular,Consolas,monospace; white-space:pre-wrap; overflow-wrap:anywhere; unicode-bidi:isolate; }
|
|
514
|
+
.dpgsp-details > summary { min-height:32px; padding:4px 0; color:var(--ink); cursor:pointer; }
|
|
515
|
+
.dpgsp-details[open] > :not(summary) { margin-top:6px; }
|
|
516
|
+
.dpgsp-body > .dpgsp-facts { padding-block:0; }
|
|
517
|
+
.dpgsp-facts > div { display:flex; align-items:baseline; justify-content:space-between; gap:8px 16px; min-height:40px; padding:9px 0; }
|
|
518
|
+
.dpgsp-facts dt { color:var(--muted); }
|
|
519
|
+
.dpgsp-facts dd { min-width:0; text-align:end; }
|
|
520
|
+
.dpgsp-root .dpgsp-link { color:var(--dsw-alias-link,var(--accent)); text-underline-offset:2px; }
|
|
521
|
+
.dpgsp-copy-feedback { margin-top:8px; padding-top:8px; }
|
|
522
|
+
.dpgsp-sr { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; border:0; }
|
|
523
|
+
@container (max-width:470px) {
|
|
524
|
+
.dpgsp-homefoot { grid-template-columns:auto minmax(0,1fr); }
|
|
525
|
+
.dpgsp-homefoot .dpgsp-actions { grid-area:3 / 1 / auto / -1; }
|
|
526
|
+
.dpgsp-foot > .dpgsp-note { flex-basis:100%; }
|
|
527
|
+
}
|
|
528
|
+
@container (max-width:340px) {
|
|
529
|
+
.dpgsp-status { justify-content:flex-start; }
|
|
530
|
+
.dpgsp-facts > div { flex-direction:column; gap:0; }
|
|
531
|
+
.dpgsp-facts dd { text-align:start; }
|
|
532
|
+
.dpgsp-actions { width:100%; }
|
|
533
|
+
.dpgsp-actions > .dpgsp-btn { flex:1 1 100%; }
|
|
534
|
+
}
|
|
535
|
+
`
|
|
536
|
+
|
|
537
|
+
const PATHS = {
|
|
538
|
+
sync: 'M3 8h16m-5-5 5 5-5 5M21 16H5m5 5-5-5 5-5',
|
|
539
|
+
up: 'M12 16V3m-5 5 5-5 5 5M4 15v5h16v-5', down: 'M12 3v13m-5-5 5 5 5-5M4 15v5h16v-5',
|
|
540
|
+
chevron: 'm7 10 5 5 5-5', arrow: 'M4 12h15m-6-6 6 6-6 6',
|
|
541
|
+
file: 'M6 3h7l5 5v13H6zM13 3v6h5M9 13h6m-6 4h4',
|
|
542
|
+
pkg: 'm12 3 8 4.5v9L12 21l-8-4.5v-9L12 3zM4 7.5l8 4.5 8-4.5M12 12v9M8 5.3l8 4.5',
|
|
543
|
+
pc: 'M3 4h18v13H3zM8 21h8m-4-4v4', shield: 'm12 3 8 3v5c0 5-4 8-8 10-4-2-8-5-8-10V6zm0 5v5m0 3v.1',
|
|
544
|
+
info: 'M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0zM12 10.5v6m0-9v.2',
|
|
545
|
+
check: 'M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0zM7.8 12.2l2.6 2.8 5.9-6.2',
|
|
546
|
+
copy: 'M8 8h12v13H8zM16 8V3H4v13h4', external: 'M7 17 17 7M7 7h10v10',
|
|
547
|
+
}
|
|
548
|
+
const icon = (key, size = 17) => h('svg', { className: 'dpgsp-icon', width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.65, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, focusable: false }, h('path', { d: PATHS[key] }))
|
|
549
|
+
const txt = value => typeof value === 'string' && value.trim() !== ''
|
|
550
|
+
const number = value => Number.isSafeInteger(value) && value >= 0
|
|
551
|
+
const names = items => Array.isArray(items) && items.every(item => typeof item === 'string')
|
|
552
|
+
const countText = (t, key, n) => t(key).replace('%n', String(n))
|
|
553
|
+
const fail = code => Object.assign(new Error(code), { code })
|
|
554
|
+
const rowFile = file => txt(file?.path) && number(file.bytes)
|
|
555
|
+
const excludedFile = file => txt(file?.path) && txt(file.code)
|
|
556
|
+
const FILE_STATES = ['add', 'overwrite', 'merge', 'identical']
|
|
557
|
+
const OUTCOMES = { installed: 'installed', 'already-present': 'present', failed: 'failed', skipped: 'skipped' }
|
|
558
|
+
|
|
559
|
+
// Accept the host's bare ID alphabet, or an exact canonical HTTPS Gist path.
|
|
560
|
+
// Never copy/open a raw URL supplied by the network, even on a success receipt.
|
|
561
|
+
const bareId = id => typeof id === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(id)
|
|
562
|
+
function sourceId(raw) {
|
|
563
|
+
const s = typeof raw === 'string' ? raw.trim() : ''
|
|
564
|
+
if (bareId(s)) return s
|
|
565
|
+
return /^https:\/\/gist\.github\.com\/(?:[a-z\d][a-z\d-]{0,38}\/)?([a-z\d_-]{1,64})\/?$/i.exec(s)?.[1] ?? null
|
|
566
|
+
}
|
|
567
|
+
function gistLink(ref) {
|
|
568
|
+
if (!bareId(ref?.id)) return null
|
|
569
|
+
if (typeof ref.htmlUrl === 'string' && sourceId(ref.htmlUrl) === ref.id && /^https:\/\//i.test(ref.htmlUrl)) return ref.htmlUrl.trim()
|
|
570
|
+
return `https://gist.github.com/${ref.id}`
|
|
571
|
+
}
|
|
572
|
+
function formatTime(value) {
|
|
573
|
+
if (!txt(value)) return '—'
|
|
574
|
+
const date = new Date(value)
|
|
575
|
+
return Number.isNaN(date.getTime()) ? '—' : date.toLocaleString()
|
|
576
|
+
}
|
|
577
|
+
function formatBytes(n) {
|
|
578
|
+
return !number(n) ? '—' : n < 1024 ? `${n} B` : n < 1048576 ? `${(n / 1024).toFixed(1)} KiB` : `${(n / 1048576).toFixed(1)} MiB`
|
|
579
|
+
}
|
|
580
|
+
function codeText(t, group, code) {
|
|
581
|
+
const key = `${group}.${code}`
|
|
582
|
+
return Object.hasOwn(DICT.en, key) ? t(key) : typeof code === 'string' ? code : ''
|
|
583
|
+
}
|
|
584
|
+
const errorText = (t, error) => Object.hasOwn(DICT.en, `err.${error?.code}`) ? t(`err.${error.code}`) : t('err.other')
|
|
585
|
+
async function api(path, body, signal) {
|
|
586
|
+
let response
|
|
587
|
+
try {
|
|
588
|
+
response = await fetch(`${API}${path}`, { method: body === undefined ? 'GET' : 'POST', credentials: 'same-origin', redirect: 'error', cache: 'no-store', signal,
|
|
589
|
+
...(body === undefined ? {} : { headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }) })
|
|
590
|
+
} catch (error) { throw signal?.aborted ? error : fail('network') }
|
|
591
|
+
const data = await response.json().catch(() => null)
|
|
592
|
+
if (!response.ok) {
|
|
593
|
+
// An origin/login rejection from DSH is not a reason to ask for a GitHub token.
|
|
594
|
+
const localDenial = data?.code === 'auth' && /^(?:DSH refused|refused: the Host)/i.test(data?.error ?? '')
|
|
595
|
+
throw fail(localDenial ? 'session-auth' : data?.code ?? 'other')
|
|
596
|
+
}
|
|
597
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw fail('bad-response')
|
|
598
|
+
return data
|
|
599
|
+
}
|
|
600
|
+
function validStatus(s) {
|
|
601
|
+
return txt(s?.profile) && number(s.counts?.files) && number(s.counts.bytes)
|
|
602
|
+
&& Array.isArray(s.files) && s.files.every(rowFile) && Array.isArray(s.excluded) && s.excluded.every(excludedFile)
|
|
603
|
+
&& (s.cloud == null || ((s.cloud.gistId === null || typeof s.cloud.gistId === 'string') && typeof s.cloud.includeMachine === 'boolean'))
|
|
604
|
+
&& (s.undo == null || (txt(s.undo.stamp) && number(s.undo.files)))
|
|
605
|
+
}
|
|
606
|
+
function filePlan(p) {
|
|
607
|
+
if (!txt(p?.profile) || !Array.isArray(p.files) || !Array.isArray(p.dropped) || !p.dropped.every(excludedFile)) return false
|
|
608
|
+
const totals = { add: 0, overwrite: 0, merge: 0, identical: 0 }
|
|
609
|
+
for (const f of p.files) {
|
|
610
|
+
if (!txt(f?.path) || !Object.hasOwn(totals, f.status)) return false
|
|
611
|
+
totals[f.status]++
|
|
612
|
+
}
|
|
613
|
+
return FILE_STATES.every(key => totals[key] === p.counts?.[key])
|
|
614
|
+
&& (p.manifest == null || names(p.manifest.bundlesAdded))
|
|
615
|
+
}
|
|
616
|
+
const changes = p => p.counts.add + p.counts.overwrite + p.counts.merge
|
|
617
|
+
const skippedCount = p => Math.max(p.dropped.length, number(p.droppedEntries) ? p.droppedEntries : 0)
|
|
618
|
+
const verifiedInventory = p => p?.available === true && names(p.installed) && Array.isArray(p.missing) && p.missing.every(entry =>
|
|
619
|
+
txt(entry?.name) && typeof entry.resolvable === 'boolean' && (entry.spec == null || typeof entry.spec === 'string')
|
|
620
|
+
&& (entry.resolvable ? txt(entry.installSpec) : entry.installSpec === null))
|
|
621
|
+
const installable = p => verifiedInventory(p) ? p.missing.filter(row => row.resolvable) : []
|
|
622
|
+
const inventoryShape = p => p?.available === false || verifiedInventory(p)
|
|
623
|
+
function validCloudPlan(p, mode, id) {
|
|
624
|
+
if (!bareId(p?.ref?.id) || p.ref.id !== id || !filePlan(p.preview)) return false
|
|
625
|
+
if (mode === 'config') return txt(p.planId) && p.plugins == null
|
|
626
|
+
return p.plugins?.available === false ? p.planId === null : verifiedInventory(p.plugins) && txt(p.planId)
|
|
627
|
+
}
|
|
628
|
+
function actionable(p) {
|
|
629
|
+
return !!p && (p.mode !== 'standard' || verifiedInventory(p.plugins)) && (changes(p.preview) > 0 || installable(p.plugins).length > 0)
|
|
630
|
+
}
|
|
631
|
+
function validRestore(r, plan) {
|
|
632
|
+
if (!filePlan(r?.report) || !number(r.report.restored)) return false
|
|
633
|
+
if (plan.mode === 'local') return true
|
|
634
|
+
if (r.ref?.id !== plan.ref.id || typeof r.restart !== 'boolean' || !names(r.warnings ?? [])) return false
|
|
635
|
+
return plan.mode === 'config' || (typeof r.complete === 'boolean' && typeof r.plugins?.available === 'boolean')
|
|
636
|
+
}
|
|
637
|
+
function verifiedReport(p) {
|
|
638
|
+
return verifiedInventory(p) && Array.isArray(p.results) && p.results.every(row => txt(row?.name) && Object.hasOwn(OUTCOMES, row.outcome) && names(row.pendingBuilds))
|
|
639
|
+
&& Object.keys(OUTCOMES).every(key => number(p.outcomeCounts?.[key]) && p.outcomeCounts[key] === p.results.filter(row => row.outcome === key).length)
|
|
640
|
+
}
|
|
641
|
+
const pendingBuilds = p => [...new Set((Array.isArray(p?.results) ? p.results : []).flatMap(row => names(row?.pendingBuilds) ? row.pendingBuilds : []))]
|
|
642
|
+
const incomplete = p => !verifiedReport(p) || p.missing.length > 0 || p.outcomeCounts.failed > 0 || p.outcomeCounts.skipped > 0 || pendingBuilds(p).length > 0
|
|
643
|
+
function sourceKind(entry, t) {
|
|
644
|
+
const full = entry.installSpec
|
|
645
|
+
const prefixed = full.startsWith(`${entry.name}@`)
|
|
646
|
+
const spec = prefixed ? full.slice(entry.name.length + 1) : full
|
|
647
|
+
if (/^(?:git(?:\+|:|@)|ssh:|github:|gitlab:|bitbucket:)/i.test(spec) || /\.git(?:$|#)/i.test(spec)) return 'Git'
|
|
648
|
+
if (/^https?:\/\//i.test(spec)) return /^https:/i.test(spec) ? 'HTTPS' : 'HTTP'
|
|
649
|
+
if ((prefixed && /^[a-z\d*^~<>=][a-z\d*^~<>=.|+ -]*$/i.test(spec)) || /^npm:/i.test(spec)) return 'npm'
|
|
650
|
+
return t('installSource')
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function compatible(s) {
|
|
654
|
+
const v = /^(\d+)\.(\d+)\.\d+(?:[-+].*)?$/.exec(s?.version ?? '')
|
|
655
|
+
return !!s?.cloud && !!v && (+v[1] > 1 || (+v[1] === 1 && +v[2] >= 3))
|
|
656
|
+
}
|
|
657
|
+
function btn(action, label, onClick, { kind, glyph, ...props } = {}) {
|
|
658
|
+
return h('button', { type: 'button', className: `dpgsp-btn${kind ? ` dpgsp-${kind}` : ''}`, 'data-action': action, onClick, ...props },
|
|
659
|
+
glyph ? icon(glyph, 16) : null, label)
|
|
660
|
+
}
|
|
661
|
+
const box = (kind, ...children) => h('div', { className: `dpgsp-box${kind ? ` dpgsp-${kind}` : ''}` }, ...children)
|
|
662
|
+
const note = (text, glyph = 'info') => h('p', { className: 'dpgsp-note' }, icon(glyph, 15), h('span', null, text))
|
|
663
|
+
const hint = text => h('p', { className: 'dpgsp-hint' }, text)
|
|
664
|
+
const details = (label, ...children) => h('details', { className: 'dpgsp-details' }, h('summary', null, label), ...children)
|
|
665
|
+
const title = text => h('h2', { tabIndex: -1, 'data-focus': 'title' }, text)
|
|
666
|
+
const facts = pairs => h('dl', { className: 'dpgsp-facts' }, pairs.filter(Boolean).map(([k, v]) => h('div', { key: k }, h('dt', null, k), h('dd', null, v))))
|
|
667
|
+
const isolated = value => h('bdi', null, value)
|
|
668
|
+
const mono = value => h('code', { dir: 'ltr' }, value)
|
|
669
|
+
const heading = (text, ...children) => h('section', { className: 'dpgsp-group' }, h('h3', null, text), ...children)
|
|
670
|
+
const rowValue = text => h('span', { className: 'dpgsp-rowvalue' }, text)
|
|
671
|
+
const frame = (content, foot, label) => h('section', { className: 'dpgsp-card', 'aria-label': label }, h('div', { className: 'dpgsp-body' }, content), foot)
|
|
672
|
+
const footer = (buttons, guidance) => h('footer', { className: 'dpgsp-foot' }, guidance ? note(guidance, 'shield') : null,
|
|
673
|
+
buttons.some(Boolean) ? h('div', { className: 'dpgsp-actions' }, ...buttons) : null)
|
|
674
|
+
function list(items, makeRow) {
|
|
675
|
+
return h('ul', { className: 'dpgsp-list' }, items.map((item, i) => h('li', { key: i, className: 'dpgsp-row' }, ...makeRow(item))))
|
|
676
|
+
}
|
|
677
|
+
const fileList = (files, t) => list(files, file => [icon('file'), h('div', { className: 'dpgsp-iteminfo' }, mono(file.path)), rowValue(t(file.status))])
|
|
678
|
+
function FileChanges({ p, t }) {
|
|
679
|
+
const changed = p.files.filter(f => f.status !== 'identical')
|
|
680
|
+
const same = p.files.filter(f => f.status === 'identical')
|
|
681
|
+
return h(React.Fragment, null,
|
|
682
|
+
changed.length ? heading(countText(t, 'changeFiles', changed.length), fileList(changed, t)) : null,
|
|
683
|
+
skippedCount(p) ? heading(`${t('retained')} (${skippedCount(p)})`,
|
|
684
|
+
p.dropped.length ? list(p.dropped, f => [icon('file'), h('div', { className: 'dpgsp-iteminfo' }, mono(f.path), hint(codeText(t, 'code', f.code)))]) : null) : null,
|
|
685
|
+
same.length ? details(`${t('showUnchanged')} (${same.length})`, fileList(same, t)) : null)
|
|
686
|
+
}
|
|
687
|
+
function PackageRows({ p, preview, t }) {
|
|
688
|
+
const yes = installable(p)
|
|
689
|
+
const no = p.missing.filter(row => !row.resolvable)
|
|
690
|
+
const add = new Set(preview?.manifest?.bundlesAdded ?? [])
|
|
691
|
+
const enabling = p.installed.filter(name => add.has(name))
|
|
692
|
+
const other = p.installed.filter(name => !add.has(name))
|
|
693
|
+
const group = (rows, resolvable) => list(rows, entry => {
|
|
694
|
+
const spec = resolvable ? entry.installSpec : entry.spec
|
|
695
|
+
// A Git/HTTPS spec can omit the package name. Display the full literal
|
|
696
|
+
// spec, never turn it into a hyperlink, and never invent a registry.
|
|
697
|
+
return [icon('pkg'), h('div', { className: 'dpgsp-iteminfo' },
|
|
698
|
+
!resolvable || !spec.startsWith(`${entry.name}@`) ? h('strong', null, isolated(entry.name)) : null,
|
|
699
|
+
h('div', null, resolvable ? h('span', { className: 'dpgsp-meta' }, sourceKind(entry, t), ' · ') : null, mono(spec ?? t('noSpec'))),
|
|
700
|
+
resolvable ? null : hint(codeText(t, 'note', entry.note))) ]
|
|
701
|
+
})
|
|
702
|
+
const named = values => list(values, value => [icon('pkg'), mono(value)])
|
|
703
|
+
return h(React.Fragment, null,
|
|
704
|
+
yes.length ? heading(countText(t, 'pluginsToInstall', yes.length), group(yes, true)) : null,
|
|
705
|
+
no.length ? heading(`${t('unresolved')} (${no.length})`, group(no, false)) : null,
|
|
706
|
+
enabling.length ? heading(`${t('alreadyEnable')} (${enabling.length})`, named(enabling)) : null,
|
|
707
|
+
other.length ? details(`${t('alreadyOther')} (${other.length})`, named(other)) : null)
|
|
708
|
+
}
|
|
709
|
+
function PlanBody({ plan, t, changeSource }) {
|
|
710
|
+
const p = plan.preview
|
|
711
|
+
const standard = plan.mode === 'standard'
|
|
712
|
+
const unknown = standard && !verifiedInventory(plan.plugins)
|
|
713
|
+
const missing = standard && !unknown ? plan.plugins.missing : []
|
|
714
|
+
const blocked = skippedCount(p) > 0 || missing.some(row => !row.resolvable)
|
|
715
|
+
const work = actionable(plan)
|
|
716
|
+
return h(React.Fragment, null,
|
|
717
|
+
facts([[t('source'), h('div', { className: 'dpgsp-source' },
|
|
718
|
+
h('div', null, isolated([p.sourceProfile, plan.mode === 'local' ? plan.fileName : plan.ref.id].filter(txt).join(' · ')),
|
|
719
|
+
txt(p.createdAt) ? hint(formatTime(p.createdAt)) : null), changeSource)], [t('targetProfile'), isolated(p.profile)]]),
|
|
720
|
+
standard ? null : box(null, h('p', null, t('configScope'))),
|
|
721
|
+
!work && !unknown ? box(blocked ? 'warning' : null,
|
|
722
|
+
blocked ? h('p', null, t('noApplicable')) : h(React.Fragment, null, h('strong', null, t('noChanges')), hint(t(standard ? 'filesPluginsSame' : 'filesSame')))) : null,
|
|
723
|
+
h(FileChanges, { p, t }),
|
|
724
|
+
unknown ? box('warning', h('strong', null, t('cannotVerify')), hint(codeText(t, 'reason', plan.plugins.reason)), h('p', null, t('cannotVerifyHint'))) : null,
|
|
725
|
+
standard && !unknown ? h(PackageRows, { p: plan.plugins, preview: p, t }) : null)
|
|
726
|
+
}
|
|
727
|
+
function PluginReport({ p, t }) {
|
|
728
|
+
if (!p) return null
|
|
729
|
+
const verified = verifiedReport(p)
|
|
730
|
+
const results = Array.isArray(p.results) ? p.results.filter(row => txt(row?.name)) : []
|
|
731
|
+
const scripts = pendingBuilds(p)
|
|
732
|
+
const remaining = Array.isArray(p.missing) ? p.missing.filter(row => txt(row?.name)) : []
|
|
733
|
+
return h('div', { className: 'dpgsp-group' },
|
|
734
|
+
verified ? hint(Object.entries(OUTCOMES).map(([k, label]) => `${t(label)} ${p.outcomeCounts[k]}`).join(' · '))
|
|
735
|
+
: box('warning', h('strong', null, t('pluginUnknown')), hint(codeText(t, 'reason', p.reason))),
|
|
736
|
+
scripts.length ? box('warning', h('strong', null, t('pendingBuilds')), list(scripts, name => [mono(name)]), hint(t('buildHint'))) : null,
|
|
737
|
+
results.length ? list(results, r => [icon('pkg'), h('div', { className: 'dpgsp-iteminfo' },
|
|
738
|
+
h('span', null, isolated(r.name), ' · ', Object.hasOwn(OUTCOMES, r.outcome) ? t(OUTCOMES[r.outcome]) : t('pluginUnknown')),
|
|
739
|
+
txt(r.message) ? hint(r.outcome === 'skipped' ? codeText(t, 'note', r.message) : r.message) : null)]) : null,
|
|
740
|
+
remaining.length ? h('p', null, `${t('stillMissing')}: `, remaining.map(r => r.name).join(', ')) : null)
|
|
741
|
+
}
|
|
742
|
+
function RestoreReceipt({ receipt, t, undoButton, onRepreview, locked }) {
|
|
743
|
+
if (!receipt) return null
|
|
744
|
+
const resultTitle = (key, glyph) => h('h3', { tabIndex: -1, 'data-focus': 'restore-receipt', className: 'dpgsp-line' }, icon(glyph), t(key))
|
|
745
|
+
if (receipt.mode === 'unknown') return frame(h(React.Fragment, null, resultTitle('restoreUnverified', 'info'),
|
|
746
|
+
facts([[t('source'), receipt.local ? isolated(receipt.source) : t('gistSource')]]), note(t('uncertain')),
|
|
747
|
+
!receipt.local ? details(t('resultDetails'), facts([[t('source'), mono(receipt.source)]])) : null), undoButton ? footer([undoButton]) : null)
|
|
748
|
+
if (receipt.mode === 'undo') return frame(h(React.Fragment, null, resultTitle('undoDone', 'check'),
|
|
749
|
+
h('p', null, countText(t, 'reverted', receipt.reverted), ' ', t('undoLimit'))))
|
|
750
|
+
const { result: r, mode } = receipt
|
|
751
|
+
const attention = !!r.warnings?.length || (mode === 'standard' && (r.complete !== true || incomplete(r.plugins)))
|
|
752
|
+
const scripts = pendingBuilds(r.plugins)
|
|
753
|
+
const missing = verifiedInventory(r.plugins) ? r.plugins.missing : null
|
|
754
|
+
const retry = mode === 'standard' && missing?.length > 0
|
|
755
|
+
const results = Array.isArray(r.plugins?.results) ? r.plugins.results : []
|
|
756
|
+
const failed = results.filter(item => item?.outcome === 'failed').length
|
|
757
|
+
const skipped = results.filter(item => item?.outcome === 'skipped').length
|
|
758
|
+
return frame(h(React.Fragment, null,
|
|
759
|
+
h('header', null, resultTitle(attention ? 'restoreAttention' : 'restoreDone', attention ? 'info' : 'check'),
|
|
760
|
+
hint([countText(t, 'changedCount', changes(r.report)), verifiedReport(r.plugins) ? countText(t, 'installedCount', r.plugins.outcomeCounts.installed) : null,
|
|
761
|
+
receipt.restart ? t('restart') : null].filter(Boolean).join(' · '))),
|
|
762
|
+
facts([[t('source'), mode === 'local' ? isolated(receipt.fileName) : t('gistSource')]]),
|
|
763
|
+
scripts.length ? note(`${t('pendingBuilds')}: ${scripts.join(', ')}. ${t('buildHint')}`, 'shield') : null,
|
|
764
|
+
r.warnings?.length ? box('warning', h('strong', null, t('warnings')), list(r.warnings, w => [w])) : null,
|
|
765
|
+
mode === 'standard' && !verifiedReport(r.plugins) ? hint(t('pluginUnknown')) : null,
|
|
766
|
+
failed || skipped || missing?.length ? h('p', null, [failed ? `${t('failed')} ${failed}` : null, skipped ? `${t('skipped')} ${skipped}` : null, missing?.length ? `${t('stillMissing')} ${missing.length}` : null].filter(Boolean).join(' · ')) : null,
|
|
767
|
+
retry ? hint(t('retryHint')) : null,
|
|
768
|
+
details(t('resultDetails'), h('div', { className: 'dpgsp-stack' },
|
|
769
|
+
mode === 'local' ? null : facts([[t('source'), mono(r.ref.id)]]), h(FileChanges, { p: r.report, t }),
|
|
770
|
+
r.plugins ? heading(t('pluginResults'), h(PluginReport, { p: r.plugins, t })) : null))),
|
|
771
|
+
footer([undoButton, retry ? btn('preview-receipt-source', t('previewReceiptSource'), onRepreview, { disabled: locked }) : null], t('undoLimit')))
|
|
772
|
+
}
|
|
773
|
+
function ProfileStatus({ profile, stateKey, url, t }) {
|
|
774
|
+
const [state, setState] = React.useState('idle')
|
|
775
|
+
const field = React.useRef(null)
|
|
776
|
+
const alive = React.useRef(false)
|
|
777
|
+
React.useEffect(() => { alive.current = true; return () => { alive.current = false } }, [])
|
|
778
|
+
React.useEffect(() => { if (state === 'manual') { field.current?.focus(); field.current?.select() } }, [state])
|
|
779
|
+
const copy = async () => {
|
|
780
|
+
try {
|
|
781
|
+
if (!navigator.clipboard?.writeText) throw Error()
|
|
782
|
+
await navigator.clipboard.writeText(url)
|
|
783
|
+
if (alive.current) setState('copied')
|
|
784
|
+
} catch { if (alive.current) { setState('manual'); field.current?.focus(); field.current?.select() } }
|
|
785
|
+
}
|
|
786
|
+
return h('section', { className: 'dpgsp-card', 'aria-label': t('localProfile') },
|
|
787
|
+
h('div', { className: 'dpgsp-summary' },
|
|
788
|
+
h('div', { className: 'dpgsp-identity' }, h('span', { className: 'dpgsp-mark' }, icon('pc', 18)),
|
|
789
|
+
h('div', null, title(t('localProfile')), profile ? h('p', { className: 'dpgsp-subtitle' }, t('profileName'), ': ', isolated(profile)) : null)),
|
|
790
|
+
h('div', { className: 'dpgsp-status' }, url
|
|
791
|
+
? h('span', { tabIndex: -1, 'data-focus': 'backup-receipt' }, t('ready')) : h('span', { role: 'status' }, t(stateKey)),
|
|
792
|
+
url ? btn('copy', t(state === 'copied' ? 'copied' : 'copyLink'), copy, { glyph: state === 'copied' ? 'check' : 'copy', kind: 'quiet', title: t('copy'), 'aria-label': t('copy') }) : null,
|
|
793
|
+
h('span', { role: 'status', className: 'dpgsp-sr' }, state === 'copied' ? t('copied') : ''))),
|
|
794
|
+
state === 'manual' ? h('div', { className: 'dpgsp-copy-feedback dpgsp-group' }, h('p', { role: 'status' }, t('manualCopy')),
|
|
795
|
+
h('label', { className: 'dpgsp-field' }, t('link'), h('input', { className: 'dpgsp-input', ref: field, readOnly: true, value: url, dir: 'ltr', onFocus: e => e.target.select() }))) : null)
|
|
796
|
+
}
|
|
797
|
+
function LocalInventory({ status: s, t }) {
|
|
798
|
+
return details(t('localInventory'), h('div', { className: 'dpgsp-stack' },
|
|
799
|
+
heading(`${t('defaultInventory')} (${s.files.length})`, list(s.files, f => [icon('file'), h('div', { className: 'dpgsp-iteminfo' }, mono(f.path)), rowValue(formatBytes(f.bytes))])),
|
|
800
|
+
heading(`${t('excluded')} (${s.excluded.length})`, list(s.excluded, f => [h('div', { className: 'dpgsp-iteminfo' }, mono(f.path), hint(codeText(t, 'code', f.code)))]))))
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function Panel({ ctx, t }) {
|
|
804
|
+
React.useSyncExternalStore(fn => ctx.locale.subscribe(fn), () => ctx.locale.getSnapshot())
|
|
805
|
+
const uid = React.useId()
|
|
806
|
+
const root = React.useRef(null)
|
|
807
|
+
const mounted = React.useRef(false)
|
|
808
|
+
const flight = React.useRef(null)
|
|
809
|
+
const selected = React.useRef(null)
|
|
810
|
+
const focusNext = React.useRef(null)
|
|
811
|
+
const opener = React.useRef('restore')
|
|
812
|
+
const fileInput = React.useRef(null)
|
|
813
|
+
const tokenInput = React.useRef(null)
|
|
814
|
+
const moreButton = React.useRef(null)
|
|
815
|
+
const menuList = React.useRef(null)
|
|
816
|
+
const menuEntry = React.useRef(null)
|
|
817
|
+
const [page, setPage] = React.useState({ name: 'home' })
|
|
818
|
+
const [status, setStatus] = React.useState(null)
|
|
819
|
+
const [statusError, setStatusError] = React.useState(null)
|
|
820
|
+
const [uploadCheck, setUploadCheck] = React.useState(null)
|
|
821
|
+
const [busy, setBusy] = React.useState(null)
|
|
822
|
+
const [issue, setIssue] = React.useState(null)
|
|
823
|
+
const [menu, setMenu] = React.useState(false)
|
|
824
|
+
const [sourceDraft, setSourceDraft] = React.useState('')
|
|
825
|
+
const [targetDraft, setTargetDraft] = React.useState('')
|
|
826
|
+
const [backupReceipt, setBackupReceipt] = React.useState(null)
|
|
827
|
+
const [restoreReceipt, setRestoreReceipt] = React.useState(null)
|
|
828
|
+
const [installReceipt, setInstallReceipt] = React.useState(null)
|
|
829
|
+
const [announcement, setAnnouncement] = React.useState('')
|
|
830
|
+
|
|
831
|
+
// One cancellable read or non-repeatable write at a time. A ref closes the
|
|
832
|
+
// gap between a button event and React committing its disabled state.
|
|
833
|
+
async function run(label, write, task, onError) {
|
|
834
|
+
if (flight.current || !mounted.current) return
|
|
835
|
+
const job = { write, controller: new AbortController() }
|
|
836
|
+
const active = () => mounted.current && flight.current === job
|
|
837
|
+
const call = async (path, body) => {
|
|
838
|
+
if (!active()) throw fail('cancelled')
|
|
839
|
+
const data = await api(path, body, job.controller.signal)
|
|
840
|
+
if (!active()) throw fail('cancelled')
|
|
841
|
+
return data
|
|
842
|
+
}
|
|
843
|
+
flight.current = job
|
|
844
|
+
setBusy(label)
|
|
845
|
+
setIssue(null)
|
|
846
|
+
setAnnouncement('')
|
|
847
|
+
try { await task(call, active) }
|
|
848
|
+
catch (error) {
|
|
849
|
+
if (active()) {
|
|
850
|
+
if (onError) onError(error)
|
|
851
|
+
else setIssue({ error })
|
|
852
|
+
}
|
|
853
|
+
} finally {
|
|
854
|
+
if (active()) { flight.current = null; setBusy(null) }
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function releaseRead() {
|
|
858
|
+
const job = flight.current
|
|
859
|
+
if (job?.write) return false
|
|
860
|
+
if (job) { flight.current = null; job.controller.abort(); setBusy(null) }
|
|
861
|
+
return true
|
|
862
|
+
}
|
|
863
|
+
function takeToken() {
|
|
864
|
+
const input = tokenInput.current
|
|
865
|
+
const value = input?.value.trim() ?? ''
|
|
866
|
+
if (input) input.value = ''
|
|
867
|
+
return value ? { token: value } : {}
|
|
868
|
+
}
|
|
869
|
+
function move(next, focus = 'title') {
|
|
870
|
+
// A source or token never lives in a subsequent independent workflow.
|
|
871
|
+
if (tokenInput.current) tokenInput.current.value = ''
|
|
872
|
+
selected.current = null
|
|
873
|
+
setIssue(null)
|
|
874
|
+
setMenu(false)
|
|
875
|
+
setSourceDraft('')
|
|
876
|
+
setTargetDraft('')
|
|
877
|
+
setAnnouncement('')
|
|
878
|
+
focusNext.current = focus
|
|
879
|
+
setPage(next)
|
|
880
|
+
}
|
|
881
|
+
function home(focus = opener.current) {
|
|
882
|
+
if (releaseRead()) move({ name: 'home' }, focus)
|
|
883
|
+
}
|
|
884
|
+
async function readStatus(call) {
|
|
885
|
+
const s = await call('/status')
|
|
886
|
+
if (!validStatus(s)) throw fail('bad-response')
|
|
887
|
+
setStatus(s)
|
|
888
|
+
setStatusError(null)
|
|
889
|
+
setUploadCheck(null)
|
|
890
|
+
return s
|
|
891
|
+
}
|
|
892
|
+
// This is deliberately isolated from the mutation's try/catch: a failed
|
|
893
|
+
// local refresh is NOT a failed upload/restore or a reason to replay it.
|
|
894
|
+
async function afterWrite(call, active) {
|
|
895
|
+
setBusy('localBusy')
|
|
896
|
+
try { await readStatus(call) } catch (error) { if (active()) setStatusError(error) }
|
|
897
|
+
}
|
|
898
|
+
function retryStatus() {
|
|
899
|
+
return run('localBusy', false, async call => {
|
|
900
|
+
const s = await readStatus(call)
|
|
901
|
+
if (page.name === 'undo') move({ name: 'undo', snapshot: s.undo })
|
|
902
|
+
else if (page.name === 'backup' || page.name === 'home') move({ name: 'home' }, compatible(s) ? 'backup' : 'title')
|
|
903
|
+
}, setStatusError)
|
|
904
|
+
}
|
|
905
|
+
React.useEffect(() => {
|
|
906
|
+
mounted.current = true
|
|
907
|
+
// Mount only reads the local summary. No automatic cloud request,
|
|
908
|
+
// token lookup, package inventory, install, or settings write.
|
|
909
|
+
void run('localBusy', false, readStatus, setStatusError)
|
|
910
|
+
return () => {
|
|
911
|
+
mounted.current = false
|
|
912
|
+
if (!flight.current?.write) flight.current?.controller.abort()
|
|
913
|
+
flight.current = null
|
|
914
|
+
selected.current = null
|
|
915
|
+
if (tokenInput.current) tokenInput.current.value = ''
|
|
916
|
+
}
|
|
917
|
+
}, [])
|
|
918
|
+
React.useEffect(() => {
|
|
919
|
+
const name = focusNext.current
|
|
920
|
+
if (!name) return
|
|
921
|
+
const element = root.current?.querySelector(`[data-focus="${name}"]`)
|
|
922
|
+
if (element?.disabled && busy) return
|
|
923
|
+
const target = element && !element.disabled ? element : root.current?.querySelector('[data-focus="title"]')
|
|
924
|
+
if (target) { focusNext.current = null; target.focus() }
|
|
925
|
+
}, [page, busy, status, issue])
|
|
926
|
+
const cloud = status?.cloud
|
|
927
|
+
const targetId = cloud?.gistId ?? null
|
|
928
|
+
const includeMachine = cloud?.includeMachine === true
|
|
929
|
+
const stale = !compatible(status) || statusError !== null || uploadCheck !== null
|
|
930
|
+
const locked = stale || busy !== null
|
|
931
|
+
const rootAction = (which, action) => () => {
|
|
932
|
+
if (locked || flight.current) return
|
|
933
|
+
opener.current = which
|
|
934
|
+
action()
|
|
935
|
+
}
|
|
936
|
+
const repairable = e => e?.code === 'auth' || e?.code === 'rate-limit'
|
|
937
|
+
const consumedPlanError = e => !['stale-plan', 'busy'].includes(e?.code)
|
|
938
|
+
const notice = (key, extra = {}) => setIssue({ key, ...extra })
|
|
939
|
+
|
|
940
|
+
function sourcePage(mode) {
|
|
941
|
+
if (releaseRead()) move({ name: 'source', mode }, 'source')
|
|
942
|
+
}
|
|
943
|
+
function displayPlan(p) {
|
|
944
|
+
move({ name: 'preview', mode: p.mode, id: p.ref?.id, fileName: p.fileName, plan: p })
|
|
945
|
+
selected.current = p
|
|
946
|
+
setAnnouncement('reviewDone')
|
|
947
|
+
}
|
|
948
|
+
function prepare(mode, id, token = {}) {
|
|
949
|
+
if (stale || flight.current || !bareId(id)) return
|
|
950
|
+
move({ name: 'preview', mode, id })
|
|
951
|
+
return run('previewBusy', false, async call => {
|
|
952
|
+
const data = await call(mode === 'config' ? '/config/preview' : '/sync/preview', { id, ...token })
|
|
953
|
+
if (!validCloudPlan(data, mode, id)) throw fail('bad-response')
|
|
954
|
+
displayPlan({ ...data, mode })
|
|
955
|
+
}, error => setIssue({ error, repair: repairable(error) }))
|
|
956
|
+
}
|
|
957
|
+
function openRestore(mode) {
|
|
958
|
+
if (bareId(targetId)) return prepare(mode, targetId)
|
|
959
|
+
sourcePage(mode)
|
|
960
|
+
}
|
|
961
|
+
function sourceSubmit(e) {
|
|
962
|
+
e.preventDefault()
|
|
963
|
+
if (locked || flight.current) return
|
|
964
|
+
const id = sourceId(sourceDraft)
|
|
965
|
+
if (!id) { focusNext.current = 'source'; setIssue({ error: fail('bad-source') }); return }
|
|
966
|
+
return prepare(page.mode, id)
|
|
967
|
+
}
|
|
968
|
+
function confirmPlan() {
|
|
969
|
+
const p = selected.current
|
|
970
|
+
if (locked || flight.current || !p || p !== page.plan || !actionable(p)) return
|
|
971
|
+
selected.current = null // one-shot; even a lost response needs a new preview
|
|
972
|
+
move({ name: 'preview', mode: p.mode, id: p.ref?.id, fileName: p.fileName })
|
|
973
|
+
return run('applyBusy', true, async (call, active) => {
|
|
974
|
+
const route = p.mode === 'local' ? '/restore' : p.mode === 'config' ? '/config/restore' : '/sync/install'
|
|
975
|
+
const r = await call(route, { planId: p.planId, confirm: true })
|
|
976
|
+
if (!validRestore(r, p)) throw fail('bad-response')
|
|
977
|
+
setRestoreReceipt({ mode: p.mode, result: r, fileName: p.fileName, restart: p.mode === 'local' ? changes(r.report) > 0 : r.restart })
|
|
978
|
+
move({ name: 'home' }, 'restore-receipt')
|
|
979
|
+
await afterWrite(call, active)
|
|
980
|
+
}, error => {
|
|
981
|
+
const uncertain = consumedPlanError(error)
|
|
982
|
+
if (uncertain) setRestoreReceipt({ mode: 'unknown', local: p.mode === 'local', source: p.ref?.id ?? p.fileName })
|
|
983
|
+
setIssue({ error, uncertain })
|
|
984
|
+
})
|
|
985
|
+
}
|
|
986
|
+
function chooseFile(event) {
|
|
987
|
+
const file = event.currentTarget.files?.[0]
|
|
988
|
+
event.currentTarget.value = ''
|
|
989
|
+
if (!file || locked || flight.current) return
|
|
990
|
+
move({ name: 'preview', mode: 'local', fileName: file.name })
|
|
991
|
+
return run('previewBusy', false, async (call, active) => {
|
|
992
|
+
// Matches the host's JSON import transport ceiling; the host validates
|
|
993
|
+
// the actual document and backup byte limits before making a plan.
|
|
994
|
+
if (file.size > 4 * 1024 * 1024) throw fail('too-large')
|
|
995
|
+
const text = await file.text()
|
|
996
|
+
if (!active()) return
|
|
997
|
+
let backup
|
|
998
|
+
try { backup = JSON.parse(text) } catch { throw fail('invalidJson') }
|
|
999
|
+
const r = await call('/preview', { backup, reviewed: true })
|
|
1000
|
+
if (!txt(r.planId) || !filePlan(r.preview)) throw fail('bad-response')
|
|
1001
|
+
displayPlan({ mode: 'local', fileName: file.name, planId: r.planId, preview: r.preview })
|
|
1002
|
+
})
|
|
1003
|
+
}
|
|
1004
|
+
function beginUpload(expectedId, expectedMachine, token = {}) {
|
|
1005
|
+
if (locked || flight.current) return
|
|
1006
|
+
let sent = false
|
|
1007
|
+
return run('uploadBusy', true, async (call, active) => {
|
|
1008
|
+
// Verify the displayed destination is still current, including the
|
|
1009
|
+
// distinct “create a new Gist” case. Never use a restore/target draft.
|
|
1010
|
+
const s = await readStatus(call)
|
|
1011
|
+
if (!compatible(s)) throw fail('bad-response')
|
|
1012
|
+
if (s.cloud.gistId !== expectedId || s.cloud.includeMachine !== expectedMachine) {
|
|
1013
|
+
move({ name: 'backup', id: s.cloud.gistId, includeMachine: s.cloud.includeMachine })
|
|
1014
|
+
notice('targetChanged'); return
|
|
1015
|
+
}
|
|
1016
|
+
if (expectedId !== null && !bareId(expectedId)) throw fail('bad-source')
|
|
1017
|
+
sent = true
|
|
1018
|
+
const r = await call('/gist/upload', { expectedTarget: expectedId, includeMachine: expectedMachine, ...token })
|
|
1019
|
+
if (!bareId(r.ref?.id) || (expectedId !== null && r.ref.id !== expectedId) || !number(r.files) || !number(r.bytes)) throw fail('bad-response')
|
|
1020
|
+
setBackupReceipt(r)
|
|
1021
|
+
// The upload receipt confirms the host saved this id; retain the link
|
|
1022
|
+
// even if the GET /status after it fails. Don't invent an upload time.
|
|
1023
|
+
setStatus(old => ({ ...old, cloud: { ...old.cloud, gistId: r.ref.id } }))
|
|
1024
|
+
move({ name: 'home' }, 'backup-receipt')
|
|
1025
|
+
await afterWrite(call, active)
|
|
1026
|
+
}, error => {
|
|
1027
|
+
move({ name: 'backup', id: expectedId, includeMachine: expectedMachine })
|
|
1028
|
+
const repair = sent && repairable(error)
|
|
1029
|
+
const changed = error?.code === 'stale-plan'
|
|
1030
|
+
const unknown = sent && !repair && !['stale-plan', 'notfound', 'too-large', 'busy', 'session-auth'].includes(error?.code)
|
|
1031
|
+
if (changed || unknown) setUploadCheck(changed ? 'targetChanged' : 'uploadUncertain')
|
|
1032
|
+
setIssue(changed ? { key: 'targetChanged' } : { error, repair, uploadUncertain: unknown })
|
|
1033
|
+
})
|
|
1034
|
+
}
|
|
1035
|
+
function backup() {
|
|
1036
|
+
if (targetId === null) return beginUpload(null, includeMachine)
|
|
1037
|
+
move({ name: 'backup', id: targetId, includeMachine })
|
|
1038
|
+
}
|
|
1039
|
+
function openTarget() {
|
|
1040
|
+
move({ name: 'target' }, 'target')
|
|
1041
|
+
setTargetDraft(targetId ?? '')
|
|
1042
|
+
}
|
|
1043
|
+
function saveTarget(e) {
|
|
1044
|
+
e.preventDefault()
|
|
1045
|
+
if (locked || flight.current) return
|
|
1046
|
+
const raw = targetDraft.trim()
|
|
1047
|
+
const id = raw === '' ? null : sourceId(raw)
|
|
1048
|
+
if (raw !== '' && !id) { focusNext.current = 'target'; setIssue({ error: fail('bad-source') }); return }
|
|
1049
|
+
if (id === targetId) return
|
|
1050
|
+
return run('busy', true, async (call, active) => {
|
|
1051
|
+
const r = await call('/settings', { gistId: id ?? '' })
|
|
1052
|
+
if (!r.cloud || r.cloud.gistId !== id || typeof r.cloud.includeMachine !== 'boolean') throw fail('bad-response')
|
|
1053
|
+
setStatus(s => ({ ...s, cloud: r.cloud }))
|
|
1054
|
+
// An old upload is not evidence that a newly linked Gist holds it.
|
|
1055
|
+
setBackupReceipt(old => old?.ref.id === id ? old : null)
|
|
1056
|
+
setTargetDraft(id ?? '')
|
|
1057
|
+
setAnnouncement('targetSaved')
|
|
1058
|
+
await afterWrite(call, active)
|
|
1059
|
+
})
|
|
1060
|
+
}
|
|
1061
|
+
function toggleMachine(value) {
|
|
1062
|
+
if (locked || flight.current) return
|
|
1063
|
+
return run('busy', true, async (call, active) => {
|
|
1064
|
+
const r = await call('/settings', { includeMachine: value })
|
|
1065
|
+
if (r.cloud?.includeMachine !== value) throw fail('bad-response')
|
|
1066
|
+
setStatus(s => ({ ...s, cloud: r.cloud }))
|
|
1067
|
+
setAnnouncement('machineSaved')
|
|
1068
|
+
await afterWrite(call, active)
|
|
1069
|
+
})
|
|
1070
|
+
}
|
|
1071
|
+
function openPlugins() {
|
|
1072
|
+
if (stale || flight.current) return
|
|
1073
|
+
move({ name: 'plugins' })
|
|
1074
|
+
return run('pluginsBusy', false, async call => {
|
|
1075
|
+
const inventory = await call('/plugins')
|
|
1076
|
+
if (!inventoryShape(inventory)) throw fail('bad-response')
|
|
1077
|
+
move({ name: 'plugins', inventory })
|
|
1078
|
+
})
|
|
1079
|
+
}
|
|
1080
|
+
function installPlugins() {
|
|
1081
|
+
const reviewed = page.inventory
|
|
1082
|
+
if (locked || flight.current || !installable(reviewed).length) return
|
|
1083
|
+
let sent = false
|
|
1084
|
+
move({ name: 'plugins' })
|
|
1085
|
+
return run('installBusy', true, async call => {
|
|
1086
|
+
// The standalone endpoint uses the local manifest, not a Gist plan.
|
|
1087
|
+
// If the current inventory no longer matches the review, stop here.
|
|
1088
|
+
const current = await call('/plugins')
|
|
1089
|
+
if (!inventoryShape(current)) throw fail('bad-response')
|
|
1090
|
+
const specs = x => x.missing.map(row => [row.name, row.resolvable, row.installSpec, row.note])
|
|
1091
|
+
if (!verifiedInventory(current) || JSON.stringify(specs(current)) !== JSON.stringify(specs(reviewed))) {
|
|
1092
|
+
move({ name: 'plugins', inventory: current }); notice('inventoryChanged'); return
|
|
1093
|
+
}
|
|
1094
|
+
sent = true
|
|
1095
|
+
const expectedPackages = installable(reviewed).map(({ name, installSpec }) => ({ name, installSpec }))
|
|
1096
|
+
const result = await call('/plugins/install', { expectedPackages })
|
|
1097
|
+
if (typeof result.available !== 'boolean' || !Array.isArray(result.results)) throw fail('bad-response')
|
|
1098
|
+
setInstallReceipt(result)
|
|
1099
|
+
move({ name: 'plugins', showResult: true })
|
|
1100
|
+
}, error => setIssue({ error, uncertain: sent && consumedPlanError(error) }))
|
|
1101
|
+
}
|
|
1102
|
+
function openUndo(expectedStamp = null) {
|
|
1103
|
+
if (stale || flight.current) return
|
|
1104
|
+
move({ name: 'undo' })
|
|
1105
|
+
return run('localBusy', false, async call => {
|
|
1106
|
+
const s = await readStatus(call)
|
|
1107
|
+
if (expectedStamp && s.undo?.stamp !== expectedStamp) { move({ name: 'home' }, 'restore-receipt'); setIssue({ error: fail('stale-plan') }); return }
|
|
1108
|
+
move({ name: 'undo', snapshot: s.undo })
|
|
1109
|
+
})
|
|
1110
|
+
}
|
|
1111
|
+
function doUndo() {
|
|
1112
|
+
if (locked || flight.current || !page.snapshot?.stamp) return
|
|
1113
|
+
const reviewed = page.snapshot
|
|
1114
|
+
let sent = false
|
|
1115
|
+
move({ name: 'undo' })
|
|
1116
|
+
return run('undoBusy', true, async (call, active) => {
|
|
1117
|
+
const s = await readStatus(call)
|
|
1118
|
+
if (!compatible(s) || s.undo?.stamp !== reviewed.stamp || s.undo.files !== reviewed.files) {
|
|
1119
|
+
move({ name: 'home' }, 'more'); setIssue({ error: fail('stale-plan') }); return
|
|
1120
|
+
}
|
|
1121
|
+
sent = true
|
|
1122
|
+
const r = await call('/undo', { expectedStamp: reviewed.stamp })
|
|
1123
|
+
if (r.report?.stamp !== reviewed.stamp || !number(r.report.reverted)) throw fail('bad-response')
|
|
1124
|
+
setRestoreReceipt({ mode: 'undo', reverted: r.report.reverted })
|
|
1125
|
+
move({ name: 'home' }, 'restore-receipt')
|
|
1126
|
+
await afterWrite(call, active)
|
|
1127
|
+
}, error => setIssue({ error, uncertain: sent && consumedPlanError(error) }))
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
const alerts = (omitBusy = false) => h(React.Fragment, null,
|
|
1131
|
+
uploadCheck && page.name !== 'backup' ? box('warning', h('p', { role: 'alert' }, t(uploadCheck)), h('div', { className: 'dpgsp-actions' }, btn('retry-status', t('statusRetry'), retryStatus, { disabled: !!busy }))) : null,
|
|
1132
|
+
statusError ? h('div', { className: 'dpgsp-box dpgsp-warning', role: 'alert' },
|
|
1133
|
+
h('strong', null, t(status ? 'refreshFailed' : 'hostMissing')), hint(errorText(t, statusError)),
|
|
1134
|
+
h('div', { className: 'dpgsp-actions' }, btn('retry-status', t('statusRetry'), retryStatus, { disabled: !!busy }))) : null,
|
|
1135
|
+
issue ? h('div', { className: `dpgsp-box dpgsp-${issue.error ? 'alert' : 'warning'}`, role: issue.error ? 'alert' : 'status' },
|
|
1136
|
+
issue.error ? h('p', null, errorText(t, issue.error)) : null, issue.key ? h('p', null, t(issue.key)) : null,
|
|
1137
|
+
issue.uncertain ? h('p', null, t('uncertain')) : null, issue.uploadUncertain ? h('p', null, t('uploadUncertain')) : null) : null,
|
|
1138
|
+
busy && !omitBusy ? h('p', { className: 'dpgsp-hint', role: 'status' }, t(busy)) : null)
|
|
1139
|
+
const isWrite = flight.current?.write === true
|
|
1140
|
+
const cancel = (back = false) => btn('cancel', t(back ? 'back' : 'cancel'), () => home(), { disabled: isWrite })
|
|
1141
|
+
const formId = `${uid}-form`
|
|
1142
|
+
const showRepair = issue?.repair === true && (page.name === 'backup' || (page.name === 'preview' && page.mode !== 'local'))
|
|
1143
|
+
const retryCloudRead = () => prepare(page.mode, page.id, takeToken())
|
|
1144
|
+
const retryUpload = () => beginUpload(page.id, page.includeMachine, takeToken())
|
|
1145
|
+
const repairView = retry => !showRepair ? null : h('form', { id: `${uid}-repair`, className: 'dpgsp-box', onSubmit: e => { e.preventDefault(); retry() } },
|
|
1146
|
+
h('h3', null, t('repair')), hint(t('tokenHelp')),
|
|
1147
|
+
h('div', { className: 'dpgsp-field' }, h('label', { htmlFor: `${uid}-token` }, t('tokenLabel')),
|
|
1148
|
+
h('input', { type: 'password', className: 'dpgsp-input', id: `${uid}-token`, ref: tokenInput, autoComplete: 'off', spellCheck: false, autoCapitalize: 'none',
|
|
1149
|
+
disabled: locked, 'aria-describedby': `${uid}-token-help` })),
|
|
1150
|
+
h('p', { className: 'dpgsp-hint', id: `${uid}-token-help` }, t('tokenPrivacy'), ' ', t('authRetry')))
|
|
1151
|
+
const retryProps = showRepair ? { type: 'submit', form: `${uid}-repair` } : {}
|
|
1152
|
+
const goMore = (key, action, glyph) => btn(key, t(key), rootAction('more', action), { kind: 'quiet', glyph, disabled: locked })
|
|
1153
|
+
// Ordinary disclosure: Tab walks the visible buttons. Arrow keys are a
|
|
1154
|
+
// convenience; focus and selection never leave this component's own list.
|
|
1155
|
+
const menuItems = () => Array.from(menuList.current?.querySelectorAll('button:not(:disabled)') ?? [])
|
|
1156
|
+
React.useEffect(() => {
|
|
1157
|
+
if (menu && menuEntry.current) {
|
|
1158
|
+
const items = menuItems()
|
|
1159
|
+
items[menuEntry.current === 'last' ? items.length - 1 : 0]?.focus()
|
|
1160
|
+
}
|
|
1161
|
+
menuEntry.current = null
|
|
1162
|
+
}, [menu])
|
|
1163
|
+
function menuKeys(e) {
|
|
1164
|
+
if (locked || flight.current || e.defaultPrevented || e.nativeEvent?.isComposing || e.altKey || e.ctrlKey || e.metaKey) return
|
|
1165
|
+
const fromButton = e.target === moreButton.current
|
|
1166
|
+
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(e.key) || (!menu && (!fromButton || !e.key.startsWith('Arrow')))) return
|
|
1167
|
+
e.preventDefault(); e.stopPropagation()
|
|
1168
|
+
if (!menu) { opener.current = 'more'; menuEntry.current = e.key === 'ArrowUp' ? 'last' : 'first'; setMenu(true); return }
|
|
1169
|
+
const items = menuItems()
|
|
1170
|
+
if (!items.length) return
|
|
1171
|
+
const i = items.indexOf(e.target)
|
|
1172
|
+
const next = e.key === 'Home' ? 0 : e.key === 'End' ? items.length - 1 : e.key === 'ArrowDown' ? (i + 1) % items.length : (i > 0 ? i - 1 : items.length - 1)
|
|
1173
|
+
items[next]?.focus()
|
|
1174
|
+
}
|
|
1175
|
+
function menuView() {
|
|
1176
|
+
return h('div', { className: 'dpgsp-menuwrap', onKeyDown: menuKeys, onBlur: e => { if (!e.currentTarget.contains(e.relatedTarget)) setMenu(false) } },
|
|
1177
|
+
btn('more', h(React.Fragment, null, t('more'), icon('chevron', 13)), rootAction('more', () => setMenu(v => !v)), { kind: 'quiet', ref: moreButton, 'data-focus': 'more',
|
|
1178
|
+
'aria-expanded': menu, 'aria-controls': menu ? `${uid}-more` : undefined, disabled: locked }),
|
|
1179
|
+
menu ? h('nav', { id: `${uid}-more`, ref: menuList, className: 'dpgsp-menulist', 'aria-label': t('more') },
|
|
1180
|
+
goMore('local', () => move({ name: 'local' }), 'file'), goMore('configMode', () => openRestore('config'), 'down'),
|
|
1181
|
+
goMore('install', openPlugins, 'pkg'), goMore('target', openTarget, 'arrow'), goMore('diagnostics', () => move({ name: 'diagnostics' }), 'info'),
|
|
1182
|
+
status?.undo ? goMore('undo', () => openUndo(), 'shield') : null) : null)
|
|
1183
|
+
}
|
|
1184
|
+
const linkView = id => {
|
|
1185
|
+
const href = gistLink({ id })
|
|
1186
|
+
return href ? h('a', { className: 'dpgsp-link', href, target: '_blank', rel: 'noopener noreferrer', referrerPolicy: 'no-referrer' }, href) : isolated(id ?? t('newGist'))
|
|
1187
|
+
}
|
|
1188
|
+
const receiptStamp = restoreReceipt?.result?.report?.undoStamp
|
|
1189
|
+
const receiptUndo = txt(receiptStamp) && receiptStamp === status?.undo?.stamp ? btn('undo-review', t('undo'), rootAction('restore', () => openUndo(receiptStamp)), { disabled: locked }) : null
|
|
1190
|
+
const intro = (key, subtitle) => h('header', null, title(t(key)), subtitle ? h('p', { className: 'dpgsp-intro' }, t(subtitle)) : null)
|
|
1191
|
+
function homeView() {
|
|
1192
|
+
const uploaded = targetId && backupReceipt?.ref?.id === targetId ? backupReceipt : null
|
|
1193
|
+
const history = cloud?.lastUpload
|
|
1194
|
+
const readyUrl = uploaded ? gistLink(uploaded.ref) : (bareId(targetId) && history?.gistId === targetId && txt(history.at) && number(history.files)
|
|
1195
|
+
? gistLink({ id: targetId }) : null)
|
|
1196
|
+
const dropped = Array.isArray(uploaded?.dropped) ? uploaded.dropped.filter(row => txt(row?.name)) : []
|
|
1197
|
+
const normal = status && compatible(status)
|
|
1198
|
+
const stateKey = !normal ? (!status && !statusError ? 'localBusy' : 'unavailable') : targetId ? 'linked' : history ? 'unlinked' : 'noneYet'
|
|
1199
|
+
const homeFooter = normal ? h('footer', { className: 'dpgsp-homefoot' }, menuView(),
|
|
1200
|
+
h('a', { className: 'dpgsp-help', href: GUIDE, target: '_blank', rel: 'noopener noreferrer', referrerPolicy: 'no-referrer', 'aria-label': t('openGuide') }, t('help'), icon('external', 12)),
|
|
1201
|
+
h('div', { className: 'dpgsp-actions' },
|
|
1202
|
+
btn('restore', t('restore'), rootAction('restore', () => openRestore('standard')), { disabled: locked, 'data-focus': 'restore' }),
|
|
1203
|
+
btn('backup', t('backup'), rootAction('backup', backup), { kind: 'primary', disabled: locked, 'data-focus': 'backup' }))) : null
|
|
1204
|
+
return h(React.Fragment, null,
|
|
1205
|
+
h(ProfileStatus, { key: (normal && readyUrl) || 'local', profile: status?.profile, stateKey, url: normal ? readyUrl : null, t }),
|
|
1206
|
+
normal ? frame(h(React.Fragment, null,
|
|
1207
|
+
facts([[t('backupContents'), t('contents')], [t('uploadTarget'), t(targetId === null ? 'newGist' : 'linkedGist')]]),
|
|
1208
|
+
note([targetId ? t('overwriteHint') : null, t('privacy')].filter(Boolean).join(' '), 'shield')), homeFooter) : null,
|
|
1209
|
+
statusError || issue || uploadCheck || (status && (busy || !normal)) ? frame(h(React.Fragment, null,
|
|
1210
|
+
alerts(!status && !statusError), status && !normal ? box('warning', h('p', null, t('staleHost')),
|
|
1211
|
+
h('div', { className: 'dpgsp-actions' }, btn('retry-status', t('statusRetry'), retryStatus, { disabled: !!busy }))) : null)) : null,
|
|
1212
|
+
normal && dropped.length ? frame(details(`${t('droppedDeps')} (${uploaded.droppedEntries ?? dropped.length})`, list(dropped, row => [isolated(row.name), mono(row.spec ?? '')]))) : null,
|
|
1213
|
+
normal && restoreReceipt ? h(RestoreReceipt, { receipt: restoreReceipt, t, undoButton: receiptUndo, locked, onRepreview: rootAction('restore', () => prepare('standard', restoreReceipt.result.ref.id)) }) : null)
|
|
1214
|
+
}
|
|
1215
|
+
function sourceView() {
|
|
1216
|
+
return frame(h(React.Fragment, null, intro(page.mode === 'config' ? 'configMode' : 'restore', 'sourceIntro'),
|
|
1217
|
+
page.mode === 'config' ? note(t('configScope'), 'shield') : null,
|
|
1218
|
+
h('form', { id: formId, onSubmit: sourceSubmit, className: 'dpgsp-group' }, h('div', { className: 'dpgsp-field' },
|
|
1219
|
+
h('label', { htmlFor: `${uid}-source` }, t('sourceLabel')), h('input', { id: `${uid}-source`, className: 'dpgsp-input', 'data-focus': 'source',
|
|
1220
|
+
type: 'text', inputMode: 'url', autoComplete: 'off', spellCheck: false, autoCapitalize: 'none', placeholder: t('sourcePlaceholder'), value: sourceDraft, disabled: locked,
|
|
1221
|
+
'aria-describedby': `${uid}-source-help`, 'aria-invalid': issue?.error?.code === 'bad-source' || undefined,
|
|
1222
|
+
onChange: e => { setSourceDraft(e.target.value); setIssue(null) } })),
|
|
1223
|
+
h('p', { id: `${uid}-source-help`, className: 'dpgsp-hint' }, t('newMachineStep1'))), alerts()),
|
|
1224
|
+
footer([cancel(), btn('preview', t('next'), undefined, { kind: 'primary', type: 'submit', form: formId, disabled: locked || !sourceDraft.trim() })]))
|
|
1225
|
+
}
|
|
1226
|
+
function previewView() {
|
|
1227
|
+
const p = page.plan
|
|
1228
|
+
const local = page.mode === 'local'
|
|
1229
|
+
const standard = page.mode === 'standard'
|
|
1230
|
+
const canApply = actionable(p)
|
|
1231
|
+
const n = installable(p?.plugins).length
|
|
1232
|
+
const confirmLabel = standard && n > 0 ? countText(t, n === 1 ? 'confirmOne' : 'confirmCombined', n) : t(standard ? 'confirmFiles' : 'confirmConfig')
|
|
1233
|
+
const buttons = [cancel(!!p && !canApply)]
|
|
1234
|
+
if (p && canApply) buttons.push(btn('confirm', confirmLabel, confirmPlan, { kind: 'primary', disabled: locked }))
|
|
1235
|
+
else if (!busy && (!p || (standard && !verifiedInventory(p.plugins)))) {
|
|
1236
|
+
buttons.push(local ? btn('choose-again', t('chooseAgain'), () => move({ name: 'local' }, 'pick'), { kind: 'primary', disabled: locked })
|
|
1237
|
+
: btn('preview', t('previewAgain'), showRepair ? undefined : retryCloudRead, { kind: 'primary', disabled: locked, ...retryProps }))
|
|
1238
|
+
}
|
|
1239
|
+
const changeSource = !local && !isWrite ? btn('change-source', t('changeSource'), () => sourcePage(page.mode), { kind: 'quiet' }) : null
|
|
1240
|
+
return frame(h(React.Fragment, null, intro(standard ? 'previewTitle' : local ? 'localPreview' : 'configPreview'),
|
|
1241
|
+
p ? h(PlanBody, { plan: p, t, changeSource }) : h('div', { className: 'dpgsp-source' }, `${t('source')}: `, isolated(local ? page.fileName : page.id), changeSource),
|
|
1242
|
+
alerts(), repairView(retryCloudRead),
|
|
1243
|
+
p && canApply ? hint(t('undoLimit')) : null),
|
|
1244
|
+
footer(buttons, canApply ? t(standard ? 'standardTrust' : 'configTrust') : null))
|
|
1245
|
+
}
|
|
1246
|
+
function backupView() {
|
|
1247
|
+
const brokenId = page.id !== null && !bareId(page.id)
|
|
1248
|
+
const mustRead = uploadCheck !== null
|
|
1249
|
+
const primary = mustRead ? btn('retry-status', t('statusRetry'), retryStatus, { kind: 'primary', disabled: !!busy })
|
|
1250
|
+
: btn('confirm-backup', t(page.id === null ? 'backup' : 'uploadConfirm'), showRepair ? undefined : retryUpload,
|
|
1251
|
+
{ kind: 'primary', disabled: locked || brokenId, ...retryProps })
|
|
1252
|
+
return frame(h(React.Fragment, null, intro(page.id === null ? 'backup' : 'overwriteReview', 'uploadScope'),
|
|
1253
|
+
facts([[t('uploadTarget'), linkView(page.id)], [t('targetProfile'), status?.profile]]),
|
|
1254
|
+
note([page.id ? t('visibilityKept') : null, t('privacy')].filter(Boolean).join(' '), 'shield'),
|
|
1255
|
+
hint(t(page.includeMachine ? 'machineIncluded' : 'machineExcluded')),
|
|
1256
|
+
status ? h(LocalInventory, { status, t }) : null, alerts(), repairView(retryUpload)), footer([cancel(), primary]))
|
|
1257
|
+
}
|
|
1258
|
+
function localView() {
|
|
1259
|
+
return frame(h(React.Fragment, null, intro('local', 'localHint'),
|
|
1260
|
+
h('p', null, t('configScope')), note(t(includeMachine ? 'machineIncluded' : 'machineExcluded')),
|
|
1261
|
+
h('input', { type: 'file', hidden: true, accept: '.json,application/json', ref: fileInput, onChange: chooseFile }), alerts()),
|
|
1262
|
+
footer([cancel(true), !locked ? h('a', { className: 'dpgsp-btn', 'data-action': 'export', href: `${API}/export${includeMachine ? '?include=machine' : ''}`, download: true }, t('export')) : null,
|
|
1263
|
+
btn('pick-file', t('import'), () => fileInput.current?.click(), { kind: 'primary', disabled: locked, 'data-focus': 'pick' })]))
|
|
1264
|
+
}
|
|
1265
|
+
function pluginsView() {
|
|
1266
|
+
const p = page.inventory
|
|
1267
|
+
const n = installable(p).length
|
|
1268
|
+
const result = page.showResult ? installReceipt : null
|
|
1269
|
+
const buttons = [cancel(!n)]
|
|
1270
|
+
if (n) buttons.push(btn('confirm-install', countText(t, n === 1 ? 'installOne' : 'installConfirm', n), installPlugins, { kind: 'primary', disabled: locked }))
|
|
1271
|
+
else if (!busy) buttons.push(btn('check-plugins', t('refreshInventory'), openPlugins, { disabled: locked }))
|
|
1272
|
+
return frame(h(React.Fragment, null, intro('install', 'installHint'), alerts(),
|
|
1273
|
+
p && !verifiedInventory(p) ? box('warning', h('strong', null, t('installUnknown')), hint(codeText(t, 'reason', p.reason))) : null,
|
|
1274
|
+
verifiedInventory(p) ? h(React.Fragment, null, !p.missing.length ? box(null, h('p', null, t('allPresent'))) : null, h(PackageRows, { p, t })) : null,
|
|
1275
|
+
result ? heading(t('pluginResults'), h(PluginReport, { p: result, t }), result.restart ? hint(t('restart')) : null) : null),
|
|
1276
|
+
footer(buttons, n ? t('installTrust') : null))
|
|
1277
|
+
}
|
|
1278
|
+
function targetView() {
|
|
1279
|
+
const raw = targetDraft.trim()
|
|
1280
|
+
const nextId = sourceId(raw)
|
|
1281
|
+
return frame(h(React.Fragment, null, intro('target', 'targetHint'), facts([[t('uploadTarget'), linkView(targetId)]]),
|
|
1282
|
+
h('form', { id: formId, onSubmit: saveTarget, className: 'dpgsp-field' }, h('label', { htmlFor: `${uid}-target` }, t('targetInput')),
|
|
1283
|
+
h('input', { id: `${uid}-target`, className: 'dpgsp-input', type: 'text', inputMode: 'url', autoComplete: 'off', autoCapitalize: 'none', spellCheck: false,
|
|
1284
|
+
value: targetDraft, 'data-focus': 'target', 'aria-invalid': issue?.error?.code === 'bad-source' || undefined, disabled: locked, placeholder: t('targetEmpty'),
|
|
1285
|
+
onChange: e => { setTargetDraft(e.target.value); setIssue(null); setAnnouncement('') } })),
|
|
1286
|
+
!raw || nextId ? box(null, facts([[t('targetNew'), linkView(nextId)]]), nextId ? hint(t('targetWarning')) : null) : null,
|
|
1287
|
+
alerts()), footer([cancel(), btn('save-target', t('saveTarget'), undefined, { type: 'submit', form: formId, kind: 'primary', disabled: locked || (raw ? nextId === targetId && nextId !== null : targetId === null) })]))
|
|
1288
|
+
}
|
|
1289
|
+
function diagnosticsView() {
|
|
1290
|
+
const stamp = record => txt(record?.at) ? [formatTime(record.at), bareId(record.gistId) ? record.gistId : null,
|
|
1291
|
+
number(record.files) ? countText(t, 'fileCount', record.files) : null].filter(Boolean).join(' · ') : t('never')
|
|
1292
|
+
return frame(h(React.Fragment, null, intro('diagnostics', 'diagnosticsHint'),
|
|
1293
|
+
facts([[t('targetProfile'), status.profile], [t('profileRoot'), status.root], [t('settingsFile'), cloud.settingsFile],
|
|
1294
|
+
[t('configFiles'), `${status.counts.files} · ${formatBytes(status.counts.bytes)}`], [t('lastUpload'), stamp(cloud.lastUpload)], [t('lastSync'), stamp(cloud.lastSync)],
|
|
1295
|
+
status.limits && [t('limits'), `${formatBytes(status.limits.maxBackupBytes)} / ${formatBytes(status.limits.gistMaxBytes)}`]]),
|
|
1296
|
+
h('label', { className: 'dpgsp-check' }, h('input', { type: 'checkbox', checked: includeMachine, disabled: locked, onChange: e => toggleMachine(e.target.checked) }), t('includeMachine')),
|
|
1297
|
+
h(LocalInventory, { status, t }), alerts()), footer([cancel(true), btn('retry-status', t('statusRetry'), retryStatus, { disabled: !!busy })]))
|
|
1298
|
+
}
|
|
1299
|
+
function undoView() {
|
|
1300
|
+
const s = page.snapshot
|
|
1301
|
+
const buttons = [cancel(!s)]
|
|
1302
|
+
if (s?.stamp && s.files > 0) buttons.push(btn('confirm-undo', t('undoConfirm'), doUndo, { kind: 'primary', disabled: locked }))
|
|
1303
|
+
else if (!busy) buttons.push(btn('retry-status', t('statusRetry'), retryStatus, { disabled: !!busy }))
|
|
1304
|
+
return frame(h(React.Fragment, null, intro('undo'), s ? h(React.Fragment, null,
|
|
1305
|
+
facts([[t('targetProfile'), status.profile], [t('undoWhen'), formatTime(s.createdAt)], [t('configFiles'), String(s.files)]]),
|
|
1306
|
+
box('warning', h('strong', null, t('undoLimit')), h('p', null, t('undoScope')))) : page.snapshot === null ? hint(t('undoNone')) : null,
|
|
1307
|
+
alerts()), footer(buttons))
|
|
1308
|
+
}
|
|
1309
|
+
const views = { home: homeView, source: sourceView, preview: previewView, backup: backupView, local: localView, plugins: pluginsView, target: targetView, diagnostics: diagnosticsView, undo: undoView }
|
|
1310
|
+
const visible = !status || !compatible(status) ? 'home' : page.name
|
|
1311
|
+
return h('div', { ref: root, className: 'dpgsp-root', 'data-view': visible, 'data-mode': page.mode,
|
|
1312
|
+
onKeyDown: e => {
|
|
1313
|
+
if (e.key !== 'Escape' || e.defaultPrevented || e.nativeEvent?.isComposing) return
|
|
1314
|
+
if (flight.current?.write) { e.preventDefault(); e.stopPropagation(); return }
|
|
1315
|
+
if (menu) { e.preventDefault(); e.stopPropagation(); setMenu(false); moreButton.current?.focus() }
|
|
1316
|
+
else if (page.name !== 'home') { e.preventDefault(); e.stopPropagation(); home() }
|
|
1317
|
+
} }, h('style', null, CSS), views[visible](),
|
|
1318
|
+
h('p', { className: !announcement || announcement === 'reviewDone' ? 'dpgsp-sr' : 'dpgsp-hint', role: 'status', 'aria-live': 'polite', 'aria-atomic': true }, announcement ? t(announcement) : ''))
|
|
1319
|
+
}
|
|
1320
|
+
return {
|
|
1321
|
+
inject: ['slots', 'locale'],
|
|
1322
|
+
apply(ctx) {
|
|
1323
|
+
ctx.effect(() => ctx.locale.register(NS, DICT), `${NS}: dictionaries`)
|
|
1324
|
+
const t = ctx.locale.bind(NS)
|
|
1325
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1326
|
+
name: 'settings.section', id: NS, order: SECTION_ORDER, label: () => t('section'), locale: NS,
|
|
1327
|
+
}, () => h(Panel, { ctx, t })))
|
|
1328
|
+
// The shell owns the nav button, selection, size and label. This optional
|
|
1329
|
+
// decorative seat is matched by section id; it does not add a page.
|
|
1330
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({ name: 'settings.section.icon', id: NS }, ({ size }) => icon('sync', size)))
|
|
1331
|
+
},
|
|
1332
|
+
}
|
|
1333
|
+
},
|
|
1334
|
+
})
|