dsh-config-sync-plugin 0.0.0-stage → 0.3.57
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.en.md +655 -0
- package/README.md +625 -2
- package/client.js +3208 -0
- package/cordis.patch.yml +16 -0
- package/index.js +4281 -0
- package/package.json +57 -3
- package/runtime/apply.ps1 +1437 -0
- package/runtime/capture.ps1 +1188 -0
- package/runtime/dsh-sync-common.ps1 +1002 -0
- package/runtime/install-plugin.ps1 +179 -0
- package/runtime/post-exit.ps1 +809 -0
- package/runtime/restore.ps1 +537 -0
- package/runtime/sync.ps1 +1029 -0
- package/runtime/tools/fix-session-cwd.mjs +200 -0
- package/tools/clientcheck.mjs +259 -0
- package/tools/pack-plugin.ps1 +79 -0
- package/tools/selftest.mjs +1461 -0
package/client.js
ADDED
|
@@ -0,0 +1,3208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-config-sync — 客户端半身(浏览器侧)
|
|
3
|
+
*
|
|
4
|
+
* 两个入口,共用一套数据:
|
|
5
|
+
* 1) 左侧栏一行(slot: sidebar.panellist,id = config-sync)+ 配对的 main 面板,
|
|
6
|
+
* 点开就是"配置同步"整页:仓库状态、版本契约、bundle 体检、生成退出后执行的脚本。
|
|
7
|
+
* 2) 设置 → 通用 里的一行摘要(slot: settings.general.item),保留给习惯从设置进的人。
|
|
8
|
+
*
|
|
9
|
+
* 契约说明(从 dshmarket / dsh-mnemon 的实现里读出来的)
|
|
10
|
+
* - 侧栏行:ctx.slots.register({ name:'sidebar.panellist', id, order, label: () => '...' }, IconComponent)
|
|
11
|
+
* 宿主按 id 负责点击后切换面板,所以必须再注册一个同名 key 的 main 面板:
|
|
12
|
+
* - 面板:ctx.slots.register({ name:'main', key: <同一 id> }, PageComponent)
|
|
13
|
+
* 两者要在同一个 ctx.slots.inject('main', ...) 作用域里成对注册、成对回收。
|
|
14
|
+
*
|
|
15
|
+
* 纪律:不 import 任何 @deepseek-ai/dsh-client-* 包;样式只用 --dsw-alias-* token;
|
|
16
|
+
* 不上 iframe;React 走 require('react')。
|
|
17
|
+
* 唯一碰 document.body 的地方是"启动即弹上次同步结果"那个浮层:它必须在面板没打开时也能显示,
|
|
18
|
+
* 只能自己 append 一个独立 div(不参与宿主布局,pointer-events:none,5 秒后自己移除)。
|
|
19
|
+
*/
|
|
20
|
+
window.__ModuleLoader__.load({
|
|
21
|
+
id: 'dsh-config-sync-plugin',
|
|
22
|
+
factory: (require) => {
|
|
23
|
+
// 官方 bundle 都在 factory 内部自建 module/exports —— 外层没有这两个名字,
|
|
24
|
+
// 直接用外层的 exports 会在真实加载器里 ReferenceError,整个 bundle import 失败。
|
|
25
|
+
var module = { exports: {} }
|
|
26
|
+
var exports = module.exports
|
|
27
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
28
|
+
|
|
29
|
+
const react = require('react')
|
|
30
|
+
const h = react.createElement
|
|
31
|
+
|
|
32
|
+
const name = 'dsh-config-sync-plugin'
|
|
33
|
+
const inject = ['slots']
|
|
34
|
+
const PANEL_ID = 'config-sync'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 语言:跟随客户端。zh-* 走中文,其余一律英文。
|
|
38
|
+
*
|
|
39
|
+
* 判定顺序(DSH 自己切换界面语言时**不会**改 navigator.language,所以不能只看它):
|
|
40
|
+
* 1. document.documentElement.lang —— DSH 切语言时写在这里(en / zh-CN …);
|
|
41
|
+
* 2. 页面里 dsh 暴露的语言设置(若有的版本只存设置不改 html lang);
|
|
42
|
+
* 3. navigator.languages / navigator.language —— 系统语言兜底。
|
|
43
|
+
* 每次调用现读,不缓存:用户在设置里切语言后不必重启客户端就能跟着变。
|
|
44
|
+
*/
|
|
45
|
+
const readTags = () => {
|
|
46
|
+
const tags = []
|
|
47
|
+
try {
|
|
48
|
+
const html = document.documentElement && document.documentElement.getAttribute('lang')
|
|
49
|
+
if (html) tags.push(String(html))
|
|
50
|
+
} catch { }
|
|
51
|
+
try {
|
|
52
|
+
for (const item of [document.body && document.body.getAttribute('lang'), document.body && document.body.getAttribute('data-lang')]) {
|
|
53
|
+
if (item) tags.push(String(item))
|
|
54
|
+
}
|
|
55
|
+
} catch { }
|
|
56
|
+
try {
|
|
57
|
+
const list = (navigator.languages && navigator.languages.length) ? navigator.languages : [navigator.language || '']
|
|
58
|
+
for (const item of list) if (item) tags.push(String(item))
|
|
59
|
+
} catch { }
|
|
60
|
+
return tags
|
|
61
|
+
}
|
|
62
|
+
const langIsZh = () => {
|
|
63
|
+
const tags = readTags()
|
|
64
|
+
for (const item of tags) {
|
|
65
|
+
const tag = String(item || '').trim().toLowerCase()
|
|
66
|
+
if (!tag) continue
|
|
67
|
+
if (/^(zh|cn|chinese)/.test(tag)) return true
|
|
68
|
+
if (/^(en|english)/.test(tag)) return false
|
|
69
|
+
}
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
const M = (zh, en) => (langIsZh() ? zh : en)
|
|
73
|
+
const localeNow = () => (langIsZh() ? 'zh-CN' : 'en-US')
|
|
74
|
+
const langHeaders = () => ({ 'accept-language': langIsZh() ? 'zh-CN,zh;q=0.9' : 'en-US,en;q=0.9' })
|
|
75
|
+
|
|
76
|
+
const S = {
|
|
77
|
+
// 侧栏 / 设置摘要行
|
|
78
|
+
row: { display: 'flex', flexDirection: 'column', gap: '6px', padding: '6px 0', width: '100%' },
|
|
79
|
+
head: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px', width: '100%' },
|
|
80
|
+
headText: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0 },
|
|
81
|
+
title: { fontSize: '14px', lineHeight: '20px', color: 'var(--dsw-alias-label-primary)' },
|
|
82
|
+
sub: { fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)', wordBreak: 'break-all' },
|
|
83
|
+
chip: { display: 'inline-flex', alignItems: 'center', fontSize: '11px', lineHeight: '16px', padding: '2px 9px', borderRadius: '999px', whiteSpace: 'nowrap', letterSpacing: '0.2px' },
|
|
84
|
+
btn: {
|
|
85
|
+
fontSize: '12px', lineHeight: '20px', padding: '5px 13px', borderRadius: '8px', cursor: 'pointer',
|
|
86
|
+
border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-base)',
|
|
87
|
+
color: 'var(--dsw-alias-label-primary)', transition: 'background .15s ease, border-color .15s ease',
|
|
88
|
+
},
|
|
89
|
+
btnPrimary: {
|
|
90
|
+
fontSize: '12px', lineHeight: '20px', padding: '5px 13px', borderRadius: '8px', cursor: 'pointer',
|
|
91
|
+
border: '1px solid var(--dsw-alias-button-primary-fill)',
|
|
92
|
+
background: 'var(--dsw-alias-button-primary-fill)',
|
|
93
|
+
color: 'var(--dsw-alias-label-primary-foreground)', fontWeight: 600,
|
|
94
|
+
transition: 'background .15s ease, border-color .15s ease',
|
|
95
|
+
},
|
|
96
|
+
// 面板整页
|
|
97
|
+
page: {
|
|
98
|
+
height: '100%', overflowY: 'auto', boxSizing: 'border-box',
|
|
99
|
+
padding: '24px 28px 36px', background: 'var(--dsw-alias-bg-base)',
|
|
100
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
101
|
+
},
|
|
102
|
+
pageInner: { maxWidth: '1140px', margin: '0 auto', display: 'flex', flexDirection: 'column', gap: '20px' },
|
|
103
|
+
pageTitle: { fontSize: '20px', lineHeight: '28px', fontWeight: 700, letterSpacing: '0.3px', color: 'var(--dsw-alias-label-primary)' },
|
|
104
|
+
pageLead: { fontSize: '12px', lineHeight: '19px', color: 'var(--dsw-alias-label-tertiary)', margin: 0, maxWidth: '820px' },
|
|
105
|
+
// 页头:左侧「标题 + 徽标 + 元信息 + 一句说明」,右侧独立操作区,底部一条分隔线
|
|
106
|
+
pageHeader: {
|
|
107
|
+
display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '20px', flexWrap: 'wrap',
|
|
108
|
+
padding: '2px 0 18px', borderBottom: '1px solid var(--dsw-alias-border-l1)',
|
|
109
|
+
},
|
|
110
|
+
pageHeaderMain: { display: 'flex', flexDirection: 'column', gap: '10px', minWidth: 0, flex: '1 1 460px' },
|
|
111
|
+
pageTitleRow: { display: 'flex', alignItems: 'center', gap: '12px', flexWrap: 'wrap' },
|
|
112
|
+
badgeGroup: { display: 'inline-flex', alignItems: 'center', gap: '6px', flexWrap: 'wrap' },
|
|
113
|
+
badgeKey: { fontSize: '11px', lineHeight: '16px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
114
|
+
headerActions: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap', paddingTop: '2px' },
|
|
115
|
+
// 标题下的一行元信息:小灰点分隔,只放"一眼要看"的事实,长句一律不进这里
|
|
116
|
+
meta: {
|
|
117
|
+
display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '6px 10px',
|
|
118
|
+
fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)',
|
|
119
|
+
fontFamily: 'Consolas, ui-monospace, monospace',
|
|
120
|
+
},
|
|
121
|
+
metaSep: { color: 'var(--dsw-alias-label-quaternary, var(--dsw-alias-label-tertiary))', opacity: 0.8 },
|
|
122
|
+
// 指标条:替代原来两张 Kv 卡,5 个小格子一行看完
|
|
123
|
+
strip: {
|
|
124
|
+
display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(100px, 1fr))',
|
|
125
|
+
gap: '1px', borderRadius: '12px', overflow: 'hidden',
|
|
126
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
127
|
+
background: 'var(--dsw-alias-border-l1)',
|
|
128
|
+
},
|
|
129
|
+
metric: {
|
|
130
|
+
display: 'flex', flexDirection: 'column', gap: '4px', padding: '11px 10px', minWidth: 0,
|
|
131
|
+
background: 'var(--dsw-alias-settings-card-fill)',
|
|
132
|
+
},
|
|
133
|
+
metricLabel: { fontSize: '11px', lineHeight: '16px', color: 'var(--dsw-alias-label-tertiary)', whiteSpace: 'nowrap', letterSpacing: '0.2px', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
134
|
+
metricValue: {
|
|
135
|
+
fontSize: '14px', lineHeight: '20px', fontWeight: 600, color: 'var(--dsw-alias-label-primary)',
|
|
136
|
+
fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all',
|
|
137
|
+
},
|
|
138
|
+
// 卡片标题行:标题 + 右侧状态/操作,统一成一行
|
|
139
|
+
cardHead: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' },
|
|
140
|
+
// 卡片底部的一行灰字(原先是整段解释,压缩成一句)
|
|
141
|
+
footnote: { fontSize: '11px', lineHeight: '17px', color: 'var(--dsw-alias-label-tertiary)', overflowWrap: 'break-word' },
|
|
142
|
+
// 卡片分组:小标题前面一根主色竖条当视觉锚点,网格宽屏两列 / 窄屏单列、卡片等高
|
|
143
|
+
section: { display: 'flex', flexDirection: 'column', gap: '12px' },
|
|
144
|
+
sectionHead: { display: 'flex', alignItems: 'baseline', gap: '10px', flexWrap: 'wrap' },
|
|
145
|
+
sectionTitle: {
|
|
146
|
+
display: 'flex', alignItems: 'center', gap: '9px',
|
|
147
|
+
paddingLeft: '10px', borderLeft: '3px solid var(--dsw-alias-toast-action)',
|
|
148
|
+
fontSize: '13px', lineHeight: '20px', fontWeight: 700, letterSpacing: '0.3px',
|
|
149
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
150
|
+
},
|
|
151
|
+
sectionHint: { fontSize: '11px', lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
152
|
+
grid: {
|
|
153
|
+
display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(340px, 1fr))',
|
|
154
|
+
gap: '12px', alignItems: 'stretch',
|
|
155
|
+
},
|
|
156
|
+
card: {
|
|
157
|
+
display: 'flex', flexDirection: 'column', gap: '10px', padding: '15px 16px', minWidth: 0,
|
|
158
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: '12px',
|
|
159
|
+
background: 'var(--dsw-alias-settings-card-fill)',
|
|
160
|
+
},
|
|
161
|
+
cardTitle: { fontSize: '13px', lineHeight: '18px', fontWeight: 600, color: 'var(--dsw-alias-label-primary)' },
|
|
162
|
+
kvRow: { display: 'flex', gap: '10px', fontSize: '12px', lineHeight: '18px', alignItems: 'flex-start', padding: '2px 0' },
|
|
163
|
+
kvKey: { minWidth: '100px', width: '100px', flexShrink: 0, color: 'var(--dsw-alias-label-tertiary)' },
|
|
164
|
+
kvVal: { flex: 1, minWidth: 0, color: 'var(--dsw-alias-label-secondary)', overflowWrap: 'break-word' },
|
|
165
|
+
advice: { fontSize: '12px', lineHeight: '19px', color: 'var(--dsw-alias-label-secondary)', margin: 0, paddingLeft: '18px', display: 'flex', flexDirection: 'column', gap: '2px' },
|
|
166
|
+
actions: { display: 'flex', gap: '8px', flexWrap: 'wrap', alignItems: 'center' },
|
|
167
|
+
hint: { fontSize: '12px', lineHeight: '19px', color: 'var(--dsw-alias-label-tertiary)', wordBreak: 'break-all' },
|
|
168
|
+
code: {
|
|
169
|
+
fontSize: '12px', lineHeight: '18px', padding: '9px 11px', borderRadius: '8px',
|
|
170
|
+
background: 'var(--dsw-alias-fill-l1, var(--dsw-alias-bg-layer-2))', color: 'var(--dsw-alias-label-secondary)',
|
|
171
|
+
fontFamily: 'Consolas, ui-monospace, monospace', whiteSpace: 'pre-wrap', wordBreak: 'break-all',
|
|
172
|
+
},
|
|
173
|
+
panel: {
|
|
174
|
+
display: 'flex', flexDirection: 'column', gap: '10px', padding: '12px',
|
|
175
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: '10px',
|
|
176
|
+
background: 'var(--dsw-alias-settings-card-fill)',
|
|
177
|
+
},
|
|
178
|
+
input: {
|
|
179
|
+
flex: 1, minWidth: 0, fontSize: '12px', lineHeight: '18px', padding: '6px 10px',
|
|
180
|
+
borderRadius: '8px', border: '1px solid var(--dsw-alias-border-l1)',
|
|
181
|
+
background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)',
|
|
182
|
+
fontFamily: 'Consolas, ui-monospace, monospace', outline: 'none',
|
|
183
|
+
},
|
|
184
|
+
inputReadonly: {
|
|
185
|
+
flex: 1, minWidth: 0, fontSize: '12px', lineHeight: '18px', padding: '6px 10px',
|
|
186
|
+
borderRadius: '8px', border: '1px solid transparent',
|
|
187
|
+
background: 'transparent', color: 'var(--dsw-alias-label-secondary)',
|
|
188
|
+
fontFamily: 'Consolas, ui-monospace, monospace',
|
|
189
|
+
},
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function chipStyle(kind) {
|
|
193
|
+
// 底色用随主题翻转的 tertiary(light 淡彩 / dark 深彩),文字一律用正文色:
|
|
194
|
+
// secondary 在 light/dark 都是同一批 400 级亮色、不翻转,dark 下亮底配近白字会看不清
|
|
195
|
+
const map = {
|
|
196
|
+
ok: 'var(--dsw-alias-state-success-tertiary)',
|
|
197
|
+
warn: 'var(--dsw-alias-state-warn-tertiary)',
|
|
198
|
+
pull: 'var(--dsw-alias-state-warn-tertiary)',
|
|
199
|
+
init: 'var(--dsw-alias-state-warn-tertiary)',
|
|
200
|
+
error: 'var(--dsw-alias-state-error-tertiary, var(--dsw-alias-file-diff-deleted-bg))',
|
|
201
|
+
idle: 'var(--dsw-alias-fill-l1, var(--dsw-alias-bg-base))',
|
|
202
|
+
}
|
|
203
|
+
return Object.assign({}, S.chip, {
|
|
204
|
+
background: map[kind] || map.idle,
|
|
205
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
206
|
+
fontWeight: 500,
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 一个分区:小标题 + 一句说明 + 内部网格。卡片少时自动单列,宽了并排两列。 */
|
|
211
|
+
function Section(title, hint, cards) {
|
|
212
|
+
const list = (cards || []).filter(Boolean)
|
|
213
|
+
if (!list.length) return null
|
|
214
|
+
return h('div', { style: S.section },
|
|
215
|
+
h('div', { style: S.sectionHead },
|
|
216
|
+
h('div', { style: S.sectionTitle }, title),
|
|
217
|
+
hint ? h('span', { style: { ...S.sectionHint, opacity: 0.75 } }, `· `) : null,
|
|
218
|
+
hint ? h('div', { style: S.sectionHint }, hint) : null,
|
|
219
|
+
),
|
|
220
|
+
h('div', { style: S.grid }, list),
|
|
221
|
+
)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 左侧徽标:只说**本机自身**的状态(配置是否齐、依赖是否缺、有没有未提交/未推送的改动)。
|
|
226
|
+
* 「云端比本机领先多少」一律交给右侧云端徽标(cloudLine),否则标题行会同时出现
|
|
227
|
+
* 「待处理」和「一致」两句都是在讲同一件事,看着像互相矛盾。
|
|
228
|
+
*/
|
|
229
|
+
function summarize(data) {
|
|
230
|
+
if (!data) return { kind: 'idle', text: M('尚未检测', 'Not checked yet') }
|
|
231
|
+
const { repo, version, bundles, deps } = data
|
|
232
|
+
if (!repo || (!repo.exists && !repo.empty)) return { kind: 'error', text: M('仓库路径未配置(见「本机仓库」卡)', 'Repo path not set (see the Local repo card)') }
|
|
233
|
+
// 云端地址缺失只算"待处理":云端有没有更新由右侧云端徽标讲,这里不重复报错
|
|
234
|
+
if (!data.remote || !data.remote.configured) return { kind: 'warn', text: M('云端仓库地址未配置', 'Cloud remote not set') }
|
|
235
|
+
if (bundles.unresolved.length || deps.missing.length) {
|
|
236
|
+
return {
|
|
237
|
+
kind: 'error',
|
|
238
|
+
text: M(
|
|
239
|
+
`${bundles.unresolved.length} 个 bundle 解析不到 · ${deps.missing.length} 个依赖缺失`,
|
|
240
|
+
`${bundles.unresolved.length} bundle(s) unresolved · ${deps.missing.length} dependency(ies) missing`,
|
|
241
|
+
),
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
// 本机自身问题优先报完之后,才轮到「仓库还没内容」——空目录只是初始状态,不是错误
|
|
245
|
+
if (repo.empty || repo.phase === 'missing') {
|
|
246
|
+
return repo.mode === 'await-init'
|
|
247
|
+
? { kind: 'init', text: M('本机与云端都还没有内容:待「初始化推送」', 'Local repo and cloud are both empty — Initialize push') }
|
|
248
|
+
: { kind: 'pull', text: M('本机仓库还没有内容:待从云端「拉取」', 'Local repo has no content yet — pull it from the cloud') }
|
|
249
|
+
}
|
|
250
|
+
if (version.local && version.contract && !version.match) {
|
|
251
|
+
return {
|
|
252
|
+
kind: 'warn',
|
|
253
|
+
text: M(
|
|
254
|
+
`版本不一致(本机 ${version.local} ≠ 契约 ${version.contract})`,
|
|
255
|
+
`Version mismatch (local ${version.local} ≠ contract ${version.contract})`,
|
|
256
|
+
),
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (repo.behind === null) return { kind: 'idle', text: M('读不到本机 git 状态(git 不可用或没 upstream)', 'Cannot read local git state (git missing or no upstream)') }
|
|
260
|
+
if (repo.dirty > 0) return { kind: 'warn', text: M(`本机有 ${repo.dirty} 处未提交改动,建议推送`, `${repo.dirty} uncommitted change(s) — consider pushing`) }
|
|
261
|
+
if (repo.ahead > 0) return { kind: 'warn', text: M(`本机有 ${repo.ahead} 个提交还没推送`, `${repo.ahead} local commit(s) not pushed yet`) }
|
|
262
|
+
// git 干净不代表没东西要推:新会话/新资料还躺在 ~\.dsh 里,没 capture 之前仓库是完全干净的
|
|
263
|
+
const local = data.local || {}
|
|
264
|
+
if (local.known && local.pending > 0) {
|
|
265
|
+
return {
|
|
266
|
+
kind: 'warn',
|
|
267
|
+
text: M(
|
|
268
|
+
`本机有 ${local.pending} 个文件在上次同步后有更新,建议推送`,
|
|
269
|
+
`${local.pending} local file(s) changed since the last sync — consider pushing`,
|
|
270
|
+
),
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { kind: 'ok', text: M('仓库与本机一致', 'Repo matches this machine') }
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function chipLabel(kind) {
|
|
277
|
+
if (kind === 'ok') return M('一致', 'In sync')
|
|
278
|
+
if (kind === 'error') return M('有问题', 'Problem')
|
|
279
|
+
if (kind === 'pull') return M('待拉取', 'To pull')
|
|
280
|
+
if (kind === 'init') return M('待初始化', 'To initialize')
|
|
281
|
+
if (kind === 'warn') return M('待推送', 'To push')
|
|
282
|
+
return M('未检测', 'Unchecked')
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function badJson(res) { return new Error(M(`${res.status} 返回非 JSON`, `${res.status} returned non-JSON`)) }
|
|
286
|
+
|
|
287
|
+
/** 单次 status 请求:15 秒超时(后端正常应在 2 秒内答完,超时基本就是后端卡住了)。 */
|
|
288
|
+
async function statusOnce() {
|
|
289
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null
|
|
290
|
+
const timer = controller ? setTimeout(() => { try { controller.abort() } catch { } }, 15000) : null
|
|
291
|
+
try {
|
|
292
|
+
const res = await fetch('/config-sync/status', {
|
|
293
|
+
cache: 'no-store',
|
|
294
|
+
credentials: 'same-origin',
|
|
295
|
+
headers: langHeaders(),
|
|
296
|
+
signal: controller ? controller.signal : undefined,
|
|
297
|
+
})
|
|
298
|
+
const text = await res.text()
|
|
299
|
+
let body
|
|
300
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
301
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
302
|
+
return body
|
|
303
|
+
} finally {
|
|
304
|
+
if (timer) clearTimeout(timer)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* status 会自动重试:一次抖动(宿主代理断流、后端那一刻正忙、请求被掐断)
|
|
310
|
+
* 不该让面板停在「读取失败」上等用户手动点「重新检测」。
|
|
311
|
+
* 3 次都失败才抛——并且文案里明确说重试过,免得用户以为是永久故障。
|
|
312
|
+
*/
|
|
313
|
+
async function callStatus() {
|
|
314
|
+
let last = null
|
|
315
|
+
for (let i = 0; i < 3; i++) {
|
|
316
|
+
try {
|
|
317
|
+
return await statusOnce()
|
|
318
|
+
} catch (e) {
|
|
319
|
+
last = e
|
|
320
|
+
const aborted = Boolean(e && (e.name === 'AbortError' || /abort/i.test(String(e.message || ''))))
|
|
321
|
+
if (aborted) last = new Error(M('读取超时(15 秒没有响应)', 'Read timed out (no response in 15s)'))
|
|
322
|
+
if (i < 2) await new Promise((r) => setTimeout(r, i === 0 ? 800 : 1800))
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const reason = String((last && last.message) || last || '')
|
|
326
|
+
throw new Error(M(`${reason}(已自动重试 3 次)`, `${reason} (retried 3 times)`))
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** 每个 POST 都带 accept-language:宿主的建议句/错误信息按它出中文或英文。 */
|
|
330
|
+
const jsonHeaders = { 'content-type': 'application/json', ...langHeaders() }
|
|
331
|
+
|
|
332
|
+
async function callPrepare(action, message, backupDir) {
|
|
333
|
+
const res = await fetch('/config-sync/prepare', {
|
|
334
|
+
method: 'POST',
|
|
335
|
+
cache: 'no-store',
|
|
336
|
+
credentials: 'same-origin',
|
|
337
|
+
headers: jsonHeaders,
|
|
338
|
+
body: JSON.stringify({ action, message: message || '', backupDir: backupDir || '' }),
|
|
339
|
+
})
|
|
340
|
+
const text = await res.text()
|
|
341
|
+
let body
|
|
342
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
343
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
344
|
+
return body
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function callSettings(payload) {
|
|
348
|
+
const res = await fetch('/config-sync/settings', {
|
|
349
|
+
method: 'POST',
|
|
350
|
+
cache: 'no-store',
|
|
351
|
+
credentials: 'same-origin',
|
|
352
|
+
headers: jsonHeaders,
|
|
353
|
+
body: JSON.stringify(payload),
|
|
354
|
+
})
|
|
355
|
+
const text = await res.text()
|
|
356
|
+
let body
|
|
357
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
358
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
359
|
+
return body
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** 自动同步接口:check / pull-now / push-now / cancel。 */
|
|
363
|
+
async function callAuto(payload) {
|
|
364
|
+
const res = await fetch('/config-sync/auto', {
|
|
365
|
+
method: 'POST',
|
|
366
|
+
cache: 'no-store',
|
|
367
|
+
credentials: 'same-origin',
|
|
368
|
+
headers: jsonHeaders,
|
|
369
|
+
body: JSON.stringify(payload),
|
|
370
|
+
})
|
|
371
|
+
const text = await res.text()
|
|
372
|
+
let body
|
|
373
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
374
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
375
|
+
return body
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 同步内容勾选:GET 取十组内容与当前勾选,POST 落盘 `<DshHome>\config-sync-scope.json`。
|
|
380
|
+
* 落盘后 capture.ps1 / apply.ps1 立刻按它跳过未勾选的内容(推送与拉取两侧同时生效)。
|
|
381
|
+
*/
|
|
382
|
+
async function callScope(payload) {
|
|
383
|
+
const res = await fetch('/config-sync/scope', payload
|
|
384
|
+
? {
|
|
385
|
+
method: 'POST',
|
|
386
|
+
cache: 'no-store',
|
|
387
|
+
credentials: 'same-origin',
|
|
388
|
+
headers: jsonHeaders,
|
|
389
|
+
body: JSON.stringify(payload),
|
|
390
|
+
}
|
|
391
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
392
|
+
const text = await res.text()
|
|
393
|
+
let body
|
|
394
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
395
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
396
|
+
return body
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* 插件数据 / 额外路径规则:GET 取 <DshHome>\config-sync-extra.json(排除名单、单文件上限、自选路径),
|
|
401
|
+
* POST 覆盖保存。单文件上限服务端封顶 100MB(GitHub 拒收更大文件)。
|
|
402
|
+
*/
|
|
403
|
+
async function callExtraConfig(payload) {
|
|
404
|
+
const res = await fetch('/config-sync/extra-config', payload
|
|
405
|
+
? {
|
|
406
|
+
method: 'POST',
|
|
407
|
+
cache: 'no-store',
|
|
408
|
+
credentials: 'same-origin',
|
|
409
|
+
headers: jsonHeaders,
|
|
410
|
+
body: JSON.stringify(payload),
|
|
411
|
+
}
|
|
412
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
413
|
+
const text = await res.text()
|
|
414
|
+
let body
|
|
415
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
416
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
417
|
+
return body
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 同步冲突:GET 取清单(两侧预览 + 每项当前选择),POST 存选择 / 还原单项 / 放弃清单。
|
|
422
|
+
* 落地由 sync.ps1 在下次拉取时按同一份 JSON 执行,这里只改文件不动仓库。
|
|
423
|
+
*/
|
|
424
|
+
async function callConflict(payload) {
|
|
425
|
+
const res = await fetch('/config-sync/conflict', payload
|
|
426
|
+
? {
|
|
427
|
+
method: 'POST',
|
|
428
|
+
cache: 'no-store',
|
|
429
|
+
credentials: 'same-origin',
|
|
430
|
+
headers: jsonHeaders,
|
|
431
|
+
body: JSON.stringify(payload),
|
|
432
|
+
}
|
|
433
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
434
|
+
const text = await res.text()
|
|
435
|
+
let body
|
|
436
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
437
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
438
|
+
return body
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** 插件更新:读版本清单(服务端缓存 30 分钟),check 时强制重查。 */
|
|
442
|
+
async function callUpdate(payload) {
|
|
443
|
+
const res = await fetch('/config-sync/update', payload
|
|
444
|
+
? {
|
|
445
|
+
method: 'POST',
|
|
446
|
+
cache: 'no-store',
|
|
447
|
+
credentials: 'same-origin',
|
|
448
|
+
headers: jsonHeaders,
|
|
449
|
+
body: JSON.stringify(payload),
|
|
450
|
+
}
|
|
451
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
452
|
+
const text = await res.text()
|
|
453
|
+
let body
|
|
454
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
455
|
+
if (!res.ok || !body) throw new Error((body && body.error) || `${res.status}`)
|
|
456
|
+
return body
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** 本机路径根:GET 拿当前值 + 待确认清单,POST 存用户选的本机路径。 */
|
|
460
|
+
async function callRoots(payload) {
|
|
461
|
+
const res = await fetch('/config-sync/roots', payload
|
|
462
|
+
? {
|
|
463
|
+
method: 'POST',
|
|
464
|
+
cache: 'no-store',
|
|
465
|
+
credentials: 'same-origin',
|
|
466
|
+
headers: jsonHeaders,
|
|
467
|
+
body: JSON.stringify(payload),
|
|
468
|
+
}
|
|
469
|
+
: { cache: 'no-store', credentials: 'same-origin', headers: langHeaders() })
|
|
470
|
+
const text = await res.text()
|
|
471
|
+
let body
|
|
472
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
473
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
474
|
+
return body
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** 问题反馈:GET 读 GitHub Issue 列表,POST 建 issue / 存令牌 / 补发队列,PATCH 改状态。 */
|
|
478
|
+
async function callFeedback(payload, opts = {}) {
|
|
479
|
+
const query = opts.query ? `?${new URLSearchParams(opts.query).toString()}` : ''
|
|
480
|
+
const method = opts.method || (payload ? 'POST' : 'GET')
|
|
481
|
+
const res = await fetch(`/config-sync/feedback${query}`, {
|
|
482
|
+
method,
|
|
483
|
+
cache: 'no-store',
|
|
484
|
+
credentials: 'same-origin',
|
|
485
|
+
headers: payload ? jsonHeaders : langHeaders(),
|
|
486
|
+
body: payload ? JSON.stringify(payload) : undefined,
|
|
487
|
+
})
|
|
488
|
+
const text = await res.text()
|
|
489
|
+
let body
|
|
490
|
+
try { body = text ? JSON.parse(text) : null } catch { throw badJson(res) }
|
|
491
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
492
|
+
return body
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** 取一份体检数据 + 生成脚本动作,供两个入口复用。 */
|
|
496
|
+
function useSync() {
|
|
497
|
+
const [data, setData] = react.useState(null)
|
|
498
|
+
const [err, setErr] = react.useState('')
|
|
499
|
+
const [busy, setBusy] = react.useState(false)
|
|
500
|
+
const [made, setMade] = react.useState(null)
|
|
501
|
+
|
|
502
|
+
const refresh = react.useCallback(async () => {
|
|
503
|
+
setBusy(true)
|
|
504
|
+
setErr('')
|
|
505
|
+
try { setData(await callStatus()) } catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
506
|
+
}, [])
|
|
507
|
+
|
|
508
|
+
react.useEffect(() => {
|
|
509
|
+
let alive = true
|
|
510
|
+
callStatus()
|
|
511
|
+
.then((d) => { if (alive) setData(d) })
|
|
512
|
+
.catch((e) => { if (alive) setErr(String((e && e.message) || e)) })
|
|
513
|
+
return () => { alive = false }
|
|
514
|
+
}, [])
|
|
515
|
+
|
|
516
|
+
const prepare = react.useCallback(async (action, message, backupDir) => {
|
|
517
|
+
setBusy(true)
|
|
518
|
+
setErr('')
|
|
519
|
+
try { setMade(await callPrepare(action, message, backupDir)) } catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
520
|
+
}, [])
|
|
521
|
+
|
|
522
|
+
return { data, err, busy, made, refresh, prepare }
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function Kv(props) {
|
|
526
|
+
return h('div', { style: S.kvRow },
|
|
527
|
+
h('div', { style: S.kvKey }, props.k),
|
|
528
|
+
h('div', { style: S.kvVal }, props.v),
|
|
529
|
+
)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
function Advice(props) {
|
|
533
|
+
return h('ul', { style: S.advice }, (props.items || []).map((a, i) => h('li', { key: i }, a)))
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function MadeNote(props) {
|
|
537
|
+
const made = props.made
|
|
538
|
+
if (!made) return null
|
|
539
|
+
const items = Array.isArray(made.built)
|
|
540
|
+
? made.built
|
|
541
|
+
: [{ action: made.action, label: made.label, path: made.path, command: made.command, backup: made.backup, warnings: made.warnings }]
|
|
542
|
+
const LABEL = {
|
|
543
|
+
push: M('推送', 'Push'),
|
|
544
|
+
pull: M('拉取', 'Pull'),
|
|
545
|
+
restore: M('还原', 'Restore'),
|
|
546
|
+
'restore-backup': M('还原指定备份', 'Restore chosen backup'),
|
|
547
|
+
all: M('全部', 'All'),
|
|
548
|
+
}
|
|
549
|
+
const backup = items.map((it) => it.backup).find((b) => b && b.dir)
|
|
550
|
+
const when = backup && backup.at ? new Date(backup.at).toLocaleString(localeNow(), { hour12: false }) : ''
|
|
551
|
+
const warnItems = items.flatMap((it) => (Array.isArray(it.warnings) ? it.warnings.map((w) => ({ action: it.action, w })) : []))
|
|
552
|
+
const key = 'warn_' + (warnItems.length ? 1 : 0)
|
|
553
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px' } },
|
|
554
|
+
items.map((it, i) => h('div', { key: i, style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
555
|
+
h('div', { style: S.hint }, M(
|
|
556
|
+
`已生成「${it.label || LABEL[it.action] || it.action}」:${it.path}`,
|
|
557
|
+
`Generated "${it.label || it.action}": ${it.path}`,
|
|
558
|
+
)),
|
|
559
|
+
h('div', { style: S.code }, it.command),
|
|
560
|
+
)),
|
|
561
|
+
backup
|
|
562
|
+
? h('div', { style: S.hint }, M(
|
|
563
|
+
`还原快照:${backup.dir}(${when},${backup.count} 份中的最新)`,
|
|
564
|
+
`Restore snapshot: ${backup.dir} (${when}; newest of ${backup.count})`,
|
|
565
|
+
))
|
|
566
|
+
: null,
|
|
567
|
+
warnItems.length
|
|
568
|
+
? h('div', { key, style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
|
|
569
|
+
warnItems.map((x, i) => h('div', {
|
|
570
|
+
key: i,
|
|
571
|
+
style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' },
|
|
572
|
+
}, `[${LABEL[x.action] || x.action}] ${x.w}`)))
|
|
573
|
+
: null,
|
|
574
|
+
h('div', { style: S.footnote }, M(
|
|
575
|
+
'脚本已带进程检查:退出 DSH 后双击;拉取 / 还原会先要你输 y 确认。',
|
|
576
|
+
'Scripts check for a running client: double-click after quitting DSH; pull/restore ask for y first.',
|
|
577
|
+
)),
|
|
578
|
+
)
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* 本机仓库卡:仓库目录(哪台机器上那份 dsh-config)。
|
|
583
|
+
* 默认只读;没配过就强制停在编辑态——不先指定仓库,推送/拉取/还原都无从生成。
|
|
584
|
+
*/
|
|
585
|
+
function RepoCard(props) {
|
|
586
|
+
const repo = (props.data && props.data.repo) || {}
|
|
587
|
+
// 空目录不算「没配好」:它是新机器还没拉取的状态,不该把人按在编辑态
|
|
588
|
+
const missing = Boolean(props.data) && !repo.exists && !repo.empty
|
|
589
|
+
const [editing, setEditing] = react.useState(false)
|
|
590
|
+
const [path, setPath] = react.useState(repo.path || '')
|
|
591
|
+
const [busy, setBusy] = react.useState(false)
|
|
592
|
+
const [err, setErr] = react.useState('')
|
|
593
|
+
const [msg, setMsg] = react.useState('')
|
|
594
|
+
const sourceLabel = (s) => s === 'settings' ? M('本机设置', 'Machine settings')
|
|
595
|
+
: (s === 'config' ? M('插件配置(cordis.patch.yml)', 'Plugin config (cordis.patch.yml)')
|
|
596
|
+
: (s === 'env' ? M('环境变量 DSH_CONFIG_REPO', 'Env var DSH_CONFIG_REPO')
|
|
597
|
+
: (s === 'auto' ? M('自动探测', 'Auto-detected') : M('未配置', 'Not set'))))
|
|
598
|
+
|
|
599
|
+
// 没配仓库 = 强制编辑态,且不允许「取消」回到只读
|
|
600
|
+
const forced = missing
|
|
601
|
+
const isEditing = editing || forced
|
|
602
|
+
|
|
603
|
+
const startEdit = () => { setPath(repo.path || ''); setErr(''); setMsg(''); setEditing(true) }
|
|
604
|
+
const cancelEdit = () => { setEditing(false); setErr(''); setMsg('') }
|
|
605
|
+
const save = async () => {
|
|
606
|
+
setBusy(true); setErr(''); setMsg('')
|
|
607
|
+
try {
|
|
608
|
+
const r = await callSettings({ repoPath: path })
|
|
609
|
+
setMsg(M(
|
|
610
|
+
`已保存仓库路径${(r.repo && r.repo.hasGit) ? '' : '(空目录:首次「拉取」会自动 git init + fetch + checkout,把它变成仓库;在那之前只允许拉取)'}`,
|
|
611
|
+
`Repo path saved${(r.repo && r.repo.hasGit) ? '' : ' (empty folder: the first Pull runs git init + fetch + checkout to turn it into the repo; until then only pull is allowed)'}`,
|
|
612
|
+
))
|
|
613
|
+
setEditing(false)
|
|
614
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
615
|
+
} catch (e) {
|
|
616
|
+
setErr(String((e && e.message) || e))
|
|
617
|
+
} finally { setBusy(false) }
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const row = h('div', { style: S.kvRow },
|
|
621
|
+
h('div', { style: S.kvKey }, M('仓库路径', 'Repo path')),
|
|
622
|
+
isEditing
|
|
623
|
+
? h('input', {
|
|
624
|
+
type: 'text', style: S.input, value: path, spellCheck: false,
|
|
625
|
+
placeholder: M('D:\\dsh-config(那台机器上装仓库的目录)', 'D:\\dsh-config (directory holding the repo on this machine)'),
|
|
626
|
+
onChange: (e) => setPath(e.target.value),
|
|
627
|
+
})
|
|
628
|
+
: h('div', { style: { ...S.kvVal, fontFamily: 'Consolas, ui-monospace, monospace' } }, repo.path || M('(未配置)', '(not set)')),
|
|
629
|
+
)
|
|
630
|
+
|
|
631
|
+
return h('div', { style: S.card },
|
|
632
|
+
h('div', { style: S.cardHead },
|
|
633
|
+
h('div', { style: S.cardTitle }, M('本机仓库', 'Local repo')),
|
|
634
|
+
isEditing && forced
|
|
635
|
+
? h('div', { style: { ...S.hint, flex: 1 } }, M('先填好仓库目录才能生成脚本', 'Set the repo path first — scripts need it'))
|
|
636
|
+
: null,
|
|
637
|
+
h('div', { style: S.actions },
|
|
638
|
+
isEditing
|
|
639
|
+
? h(react.Fragment, null,
|
|
640
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !path.trim(), onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
641
|
+
forced ? null : h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
|
|
642
|
+
)
|
|
643
|
+
: h('button', { type: 'button', style: S.btn, disabled: !props.data, onClick: startEdit }, M('修改', 'Edit')),
|
|
644
|
+
),
|
|
645
|
+
),
|
|
646
|
+
row,
|
|
647
|
+
h(Kv, {
|
|
648
|
+
k: M('路径来源', 'Path source'),
|
|
649
|
+
v: sourceLabel(repo.source) + (repo.exists ? '' : (repo.empty ? M('(空目录,待首次拉取)', ' (empty folder, waiting for the first pull)') : M('(这个路径不可用)', ' (path unavailable)'))),
|
|
650
|
+
}),
|
|
651
|
+
h(Kv, {
|
|
652
|
+
k: M('分支 / HEAD', 'Branch / HEAD'),
|
|
653
|
+
v: repo.exists ? `${repo.branch || '?'} @ ${repo.head || '?'}` : (repo.empty ? M('(待首次拉取)', '(after the first pull)') : M('(不可用)', '(unavailable)')),
|
|
654
|
+
}),
|
|
655
|
+
h(Kv, {
|
|
656
|
+
k: M('远端', 'Remote'),
|
|
657
|
+
v: repo.exists
|
|
658
|
+
? M(
|
|
659
|
+
`落后 ${repo.behind ?? '?'} · 领先 ${repo.ahead ?? '?'} · 未提交 ${repo.dirty ?? '?'}`,
|
|
660
|
+
`behind ${repo.behind ?? '?'} · ahead ${repo.ahead ?? '?'} · dirty ${repo.dirty ?? '?'}`,
|
|
661
|
+
)
|
|
662
|
+
: (repo.empty ? M('(拉取之后才有得比)', '(available after the first pull)') : M('(不可用)', '(unavailable)')),
|
|
663
|
+
}),
|
|
664
|
+
(repo.empty || repo.phase === 'missing')
|
|
665
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
666
|
+
repo.mode === 'await-init'
|
|
667
|
+
? M(
|
|
668
|
+
'本机仓库和云端仓库都还没有内容:点「初始化推送」把本机配置作为初始内容写进仓库并推上去(自动 git init + 写仓库骨架 + capture + 提交 + 推送)。这时拉取没有东西可拉。',
|
|
669
|
+
'Both the local repo and the cloud are empty: Initialize push writes this machine\'s config in as the initial content (git init + repo skeleton + capture + commit + push). There is nothing to pull yet.',
|
|
670
|
+
)
|
|
671
|
+
: M(
|
|
672
|
+
'本机仓库还没有内容:点「拉取」会从云端把仓库内容拉到这个路径(自动 git init + fetch + checkout);拉下来之前不支持推送。',
|
|
673
|
+
'The local repo has no content yet: Pull fetches the whole repo into this path (git init + fetch + checkout). Push is disabled until then.',
|
|
674
|
+
))
|
|
675
|
+
: null,
|
|
676
|
+
h(Kv, { k: M('本机数据', 'Local data'), v: (() => {
|
|
677
|
+
const local = props.data && props.data.local
|
|
678
|
+
if (!local || !local.known) return M('还没同步过', 'Never synced yet')
|
|
679
|
+
const when = local.lastSyncAt ? new Date(local.lastSyncAt).toLocaleString(localeNow(), { hour12: false }) : '?'
|
|
680
|
+
const tail = local.pending > 0
|
|
681
|
+
? M(
|
|
682
|
+
`有 ${local.pending} 个文件待推送${local.sample && local.sample.length ? `(如 ${local.sample.join('、')})` : ''}`,
|
|
683
|
+
`${local.pending} file(s) to push${local.sample && local.sample.length ? ` (e.g. ${local.sample.join(', ')})` : ''}`,
|
|
684
|
+
)
|
|
685
|
+
: M('没有新写入', 'nothing new')
|
|
686
|
+
return M(
|
|
687
|
+
`${tail} · 上次同步 ${when}${local.mode ? `(${local.mode})` : ''}`,
|
|
688
|
+
`${tail} · last sync ${when}${local.mode ? ` (${local.mode})` : ''}`,
|
|
689
|
+
)
|
|
690
|
+
})() }),
|
|
691
|
+
h('div', { style: S.footnote }, M(
|
|
692
|
+
'路径只存本机设置文件(~\\.dsh\\dsh-config-sync.json),不进仓库,各机器各配各的。',
|
|
693
|
+
'The path lives only in the local settings file (~\\.dsh\\dsh-config-sync.json), never in the repo.',
|
|
694
|
+
)),
|
|
695
|
+
forced
|
|
696
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } },
|
|
697
|
+
M(
|
|
698
|
+
'必须先把仓库目录配好:否则推送/拉取/还原三份脚本都无法生成,体检也只能看个空壳。',
|
|
699
|
+
'Configure the repo directory first — otherwise push/pull/restore cannot be generated and the check has nothing to inspect.',
|
|
700
|
+
))
|
|
701
|
+
: null,
|
|
702
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${err}`, `Save failed: ${err}`)) : null,
|
|
703
|
+
msg ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
|
|
704
|
+
)
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* 云端仓库卡:远端地址 + SSH 私钥路径。
|
|
709
|
+
* 默认只读展示;点「修改」才变成可编辑,保存走 POST /config-sync/settings,
|
|
710
|
+
* 宿主那边会同时 git remote set-url,失败则回滚设置文件并回显错误。
|
|
711
|
+
*/
|
|
712
|
+
function RemoteCard(props) {
|
|
713
|
+
const remote = (props.data && props.data.remote) || {}
|
|
714
|
+
// 没配过云端仓库 = 强制编辑态:不给「取消」,也不许就这么放着去生成推送/拉取
|
|
715
|
+
const missing = Boolean(props.data) && !remote.configured
|
|
716
|
+
const [editing, setEditing] = react.useState(false)
|
|
717
|
+
const [url, setUrl] = react.useState(remote.url || '')
|
|
718
|
+
const [key, setKey] = react.useState(remote.sshKey || '')
|
|
719
|
+
const [busy, setBusy] = react.useState(false)
|
|
720
|
+
const [err, setErr] = react.useState('')
|
|
721
|
+
const [msg, setMsg] = react.useState('')
|
|
722
|
+
const isEditing = editing || missing
|
|
723
|
+
const sourceLabel = (s) => s === 'settings' ? M('本机设置', 'Machine settings')
|
|
724
|
+
: (s === 'git' ? M('git 配置', 'git config')
|
|
725
|
+
: (s === 'default' ? M('自动探测', 'Auto-detected') : M('未配置', 'Not set')))
|
|
726
|
+
|
|
727
|
+
const startEdit = () => {
|
|
728
|
+
setUrl(remote.url || '')
|
|
729
|
+
setKey(remote.sshKey || '')
|
|
730
|
+
setErr('')
|
|
731
|
+
setMsg('')
|
|
732
|
+
setEditing(true)
|
|
733
|
+
}
|
|
734
|
+
const cancelEdit = () => { setEditing(false); setErr(''); setMsg('') }
|
|
735
|
+
const save = async () => {
|
|
736
|
+
setBusy(true); setErr(''); setMsg('')
|
|
737
|
+
try {
|
|
738
|
+
const r = await callSettings({ remoteUrl: url, sshKey: key })
|
|
739
|
+
setMsg(M(
|
|
740
|
+
`已保存${r.gitRemoteSet ? ',并已更新本机 git origin' : ''}`,
|
|
741
|
+
`Saved${r.gitRemoteSet ? ' and updated the local git origin' : ''}`,
|
|
742
|
+
))
|
|
743
|
+
setEditing(false)
|
|
744
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
745
|
+
} catch (e) {
|
|
746
|
+
setErr(String((e && e.message) || e))
|
|
747
|
+
} finally { setBusy(false) }
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const field = (label, value, onChange, placeholder) => h('div', { style: S.kvRow },
|
|
751
|
+
h('div', { style: S.kvKey }, label),
|
|
752
|
+
isEditing
|
|
753
|
+
? h('input', {
|
|
754
|
+
type: 'text', style: S.input, value, placeholder, spellCheck: false,
|
|
755
|
+
onChange: (e) => onChange(e.target.value),
|
|
756
|
+
})
|
|
757
|
+
: h('div', { style: { ...S.kvVal, fontFamily: 'Consolas, ui-monospace, monospace' } }, value || M('(未配置)', '(not set)')),
|
|
758
|
+
)
|
|
759
|
+
|
|
760
|
+
return h('div', { style: S.card },
|
|
761
|
+
h('div', { style: S.cardHead },
|
|
762
|
+
h('div', { style: S.cardTitle }, M('云端仓库', 'Cloud repo')),
|
|
763
|
+
isEditing && missing
|
|
764
|
+
? h('div', { style: { ...S.hint, flex: 1 } }, M('先填远端地址才能生成推送/拉取', 'Set the remote URL to enable push/pull'))
|
|
765
|
+
: null,
|
|
766
|
+
isEditing
|
|
767
|
+
? h('div', { style: S.actions },
|
|
768
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !url.trim(), onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
769
|
+
missing ? null : h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
|
|
770
|
+
)
|
|
771
|
+
: h('div', { style: S.actions },
|
|
772
|
+
h('button', { type: 'button', style: S.btn, disabled: !props.data, onClick: startEdit }, M('修改', 'Edit')),
|
|
773
|
+
),
|
|
774
|
+
),
|
|
775
|
+
field(M('远端地址', 'Remote URL'), isEditing ? url : (remote.url || ''), setUrl, 'git@<host>:you/dsh-config.git'),
|
|
776
|
+
field(M('SSH 私钥', 'SSH key'), isEditing ? key : (remote.sshKey || ''), setKey, M('C:\\Users\\你\\.ssh\\id_ed25519', 'C:\\Users\\you\\.ssh\\id_ed25519')),
|
|
777
|
+
h(Kv, {
|
|
778
|
+
k: M('私钥来源', 'Key source'),
|
|
779
|
+
v: `${sourceLabel(remote.sshKeyFrom)}${remote.sshKeyExists ? '' : M('(文件不存在)', ' (file missing)')}`,
|
|
780
|
+
}),
|
|
781
|
+
h(Kv, { k: M('地址来源', 'URL source'), v: sourceLabel(remote.urlSource) }),
|
|
782
|
+
h(Kv, { k: M('设置文件', 'Settings file'), v: remote.settingsPath || M('(未知)', '(unknown)') }),
|
|
783
|
+
missing && !remote.sshKeyExists
|
|
784
|
+
? h('div', { style: S.footnote }, M(
|
|
785
|
+
'私钥可留空:认证交给 .ssh\\config 或 Git 默认选择;填了才写进脚本的 GIT_SSH_COMMAND。',
|
|
786
|
+
'The key is optional — auth falls back to .ssh\\config or Git defaults; fill it only to write GIT_SSH_COMMAND into scripts.',
|
|
787
|
+
))
|
|
788
|
+
: null,
|
|
789
|
+
err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${err}`, `Save failed: ${err}`)) : null,
|
|
790
|
+
msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
|
|
791
|
+
h('div', { style: S.footnote }, M(
|
|
792
|
+
'远端地址支持任意 git 托管平台(Gitee / GitHub / GitLab / 自建 Gitea):'
|
|
793
|
+
+ 'git@host:owner/repo.git、ssh://、https:// 三种写法都行;'
|
|
794
|
+
+ '例:git@gitee.com:you/dsh-config.git、git@github.com:you/dsh-config.git、https://gitlab.com/you/dsh-config.git。'
|
|
795
|
+
+ 'SSH 地址用下面的私钥/ssh config 走认证,https 地址用 Git 凭据管理器里的账号或令牌。',
|
|
796
|
+
'Any git host works (Gitee / GitHub / GitLab / self-hosted Gitea): '
|
|
797
|
+
+ 'git@host:owner/repo.git, ssh:// and https:// are all accepted; '
|
|
798
|
+
+ 'e.g. git@gitee.com:you/dsh-config.git, git@github.com:you/dsh-config.git, https://gitlab.com/you/dsh-config.git. '
|
|
799
|
+
+ 'SSH URLs authenticate with the key or ssh config below; https URLs use the account or token in Git Credential Manager.',
|
|
800
|
+
)),
|
|
801
|
+
h('div', { style: S.footnote }, M(
|
|
802
|
+
'只存私钥路径不存内容;保存远端地址会同步更新本机 git origin,git 失败则整套回滚。',
|
|
803
|
+
'Only the key path is stored; saving also updates the local git origin, rolling everything back if git fails.',
|
|
804
|
+
)),
|
|
805
|
+
)
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* 「还原备份」卡:先看备份目录在哪(默认 <DshHome>\backups,可改成别的绝对路径),
|
|
810
|
+
* 再把该目录下的快照逐份列出来(时间 / 相对时间 / 文件数 / 大小 / 插件数 / 能不能拿来还原)。
|
|
811
|
+
*
|
|
812
|
+
* 「立即还原」= 和「立即拉取」同一条流水线:点快照 → 弹确认框(服务端现算差异:会撤走哪些插件、
|
|
813
|
+
* 会覆盖/写回哪些文件、会移走哪些快照之后新增的文件)→ 确认后排队 auto-sync,客户端退出后
|
|
814
|
+
* 由 post-exit.ps1 弹可见窗口跑 restore.ps1 -RollbackToPoint → 完成后自动重启客户端。
|
|
815
|
+
*
|
|
816
|
+
* 为什么不能"点了就直接覆盖":profile 文件在 DSH 运行时被客户端持有,边跑边覆盖会被退出时的
|
|
817
|
+
* 回写再盖回去,甚至把 profile 弄坏。所以仍然必须走"退出后执行",只是不再让用户自己双击 .cmd。
|
|
818
|
+
* 需要生成脚本的老路径(用于手动/离线执行)仍保留在「动作」卡里。
|
|
819
|
+
*/
|
|
820
|
+
function RestoreCard(props) {
|
|
821
|
+
const backup = (props.data && props.data.backup) || {}
|
|
822
|
+
const remote = (props.data && props.data.remote) || {}
|
|
823
|
+
const snapshots = Array.isArray(backup.snapshots) ? backup.snapshots
|
|
824
|
+
: (Array.isArray(backup.candidates) ? backup.candidates : [])
|
|
825
|
+
const defaultRoot = backup.defaultRoot || remote.backupRoot || ''
|
|
826
|
+
const [editing, setEditing] = react.useState(false)
|
|
827
|
+
const [root, setRoot] = react.useState(remote.backupRoot || defaultRoot)
|
|
828
|
+
const [busy, setBusy] = react.useState(false)
|
|
829
|
+
const [err, setErr] = react.useState('')
|
|
830
|
+
const [msg, setMsg] = react.useState('')
|
|
831
|
+
const [made, setMade] = react.useState(null)
|
|
832
|
+
const [confirm, setConfirm] = react.useState(null) // { snap, preview }:确认环节
|
|
833
|
+
const [queued, setQueued] = react.useState(null) // restore-now 的排队结果
|
|
834
|
+
const [manual, setManual] = react.useState(null) // 认不出类型时的「手动还原」指引
|
|
835
|
+
|
|
836
|
+
const startEdit = () => { setRoot(remote.backupRootCustom ? (remote.backupRoot || '') : ''); setErr(''); setMsg(''); setEditing(true) }
|
|
837
|
+
const cancelEdit = () => { setEditing(false); setErr(''); setMsg('') }
|
|
838
|
+
|
|
839
|
+
const save = async (payload) => {
|
|
840
|
+
setBusy(true); setErr(''); setMsg('')
|
|
841
|
+
try {
|
|
842
|
+
const r = await callSettings(payload)
|
|
843
|
+
setMsg(payload.clearBackupRoot
|
|
844
|
+
? M('已恢复默认备份目录', 'Backup folder reset to the default')
|
|
845
|
+
: M(`已保存备份目录:${(r.remote && r.remote.backupRoot) || ''}`, `Backup folder saved: ${(r.remote && r.remote.backupRoot) || ''}`))
|
|
846
|
+
setEditing(false)
|
|
847
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
848
|
+
} catch (e) {
|
|
849
|
+
setErr(String((e && e.message) || e))
|
|
850
|
+
} finally { setBusy(false) }
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* 第一步:点「立即还原」不是直接动手,先向服务端要一份差异预览 ——
|
|
855
|
+
* 会撤走哪些插件、会覆盖哪些文件、会移走哪些快照之后新增的文件,全部摆出来让人确认。
|
|
856
|
+
*/
|
|
857
|
+
const askRestore = async (snap) => {
|
|
858
|
+
setBusy(true); setErr(''); setMsg(''); setQueued(null)
|
|
859
|
+
try {
|
|
860
|
+
const r = await callAuto({ action: 'restore-preview', backupDir: snap.dir })
|
|
861
|
+
setConfirm({ snap, preview: (r && r.preview) || {} })
|
|
862
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/** 第二步:确认之后才排队「退出后还原」,随后请求客户端正常关闭(和立即拉取同一条流水线)。 */
|
|
866
|
+
const doRestore = async () => {
|
|
867
|
+
if (!confirm) return
|
|
868
|
+
setBusy(true); setErr('')
|
|
869
|
+
try {
|
|
870
|
+
const r = await callAuto({ action: 'restore-now', backupDir: confirm.snap.dir })
|
|
871
|
+
setQueued({ snap: confirm.snap, resp: r })
|
|
872
|
+
setConfirm(null)
|
|
873
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
const when = (at) => (at ? new Date(at).toLocaleString(localeNow(), { hour12: false }) : '?')
|
|
877
|
+
/** 相对时间:备份列表里"3 分钟前"比一串年月日更好判断新旧,具体时刻仍保留在旁边 */
|
|
878
|
+
const rel = (at) => {
|
|
879
|
+
if (!at) return '?'
|
|
880
|
+
const diff = Date.now() - Number(at)
|
|
881
|
+
if (diff < 0 || diff < 60000) return M('刚刚', 'just now')
|
|
882
|
+
const min = Math.floor(diff / 60000)
|
|
883
|
+
if (min < 60) return M(`${min} 分钟前`, `${min} min ago`)
|
|
884
|
+
const hr = Math.floor(min / 60)
|
|
885
|
+
if (hr < 24) return M(`${hr} 小时前`, `${hr} h ago`)
|
|
886
|
+
const day = Math.floor(hr / 24)
|
|
887
|
+
if (day < 30) return M(`${day} 天前`, `${day} d ago`)
|
|
888
|
+
return M(`${Math.floor(day / 30)} 个月前`, `${Math.floor(day / 30)} mo ago`)
|
|
889
|
+
}
|
|
890
|
+
const size = (n) => {
|
|
891
|
+
const v = Number(n) || 0
|
|
892
|
+
if (v >= 1048576) return `${(v / 1048576).toFixed(1)} MB`
|
|
893
|
+
if (v >= 1024) return `${(v / 1024).toFixed(1)} KB`
|
|
894
|
+
return `${v} B`
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* 快照类型。备份根 ~\.dsh\backups 是**三用途共用**的:
|
|
899
|
+
* 配置快照(能回到某个时间点)/ 插件本体备份(能回滚插件)/ 会话目录备份(能还原会话)
|
|
900
|
+
* 0.3.49 起三类都给还原入口;认不出类型的(冲突对照、手工拷来的)给手动还原指引 —— 不留死路。
|
|
901
|
+
*/
|
|
902
|
+
const KIND_ZH = { profile: '配置', plugin: '插件', session: '会话', other: '其它' }
|
|
903
|
+
const KIND_EN = { profile: 'config', plugin: 'plugin', session: 'session', other: 'other' }
|
|
904
|
+
const kindOf = (s) => ((s && s.kind) || 'profile')
|
|
905
|
+
const kindLabel = (k) => M(KIND_ZH[k] || KIND_ZH.other, KIND_EN[k] || KIND_EN.other)
|
|
906
|
+
const kindBadge = (k) => h('span', {
|
|
907
|
+
style: {
|
|
908
|
+
...S.hint,
|
|
909
|
+
padding: '0 5px', borderRadius: '4px', lineHeight: '16px',
|
|
910
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
911
|
+
color: k === 'other' ? 'var(--dsw-alias-label-secondary)' : 'var(--dsw-alias-label-primary)',
|
|
912
|
+
},
|
|
913
|
+
}, kindLabel(k))
|
|
914
|
+
const snapSummary = (s) => {
|
|
915
|
+
const k = kindOf(s)
|
|
916
|
+
if (k === 'profile') return M(`${s.plugins || 0} 个插件`, `${s.plugins || 0} plugins`)
|
|
917
|
+
const n = Number(s.entries || 0)
|
|
918
|
+
if (k === 'plugin') return M(`插件本体 ${n} 项`, `plugin files, ${n} items`)
|
|
919
|
+
if (k === 'session') return M(`${n} 个会话目录`, `${n} session folders`)
|
|
920
|
+
return M(`认不出类型,${n} 项`, `unrecognised, ${n} items`)
|
|
921
|
+
}
|
|
922
|
+
// 「手动还原」指引里的目标位置:认不出类型时按内容猜不到,索性把三类常见落点都摆出来
|
|
923
|
+
const manualTargets = () => [
|
|
924
|
+
M('插件本体 → 插件安装目录(如 D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.57)', 'Plugin files → the plugin install folder (e.g. D:\\DeepSeekHarness\\dsh-config-sync-plugin-0.3.57)'),
|
|
925
|
+
M('会话目录(--xxx--)→ ~\\.dsh\\sessions', 'Session folders (--xxx--) → ~\\.dsh\\sessions'),
|
|
926
|
+
M('配置五件套(package.json / pnpm-lock.yaml / cordis.yml…)→ ~\\.dsh\\profiles\\desktop', 'Config files (package.json / pnpm-lock.yaml / cordis.yml…) → ~\\.dsh\\profiles\\desktop'),
|
|
927
|
+
]
|
|
928
|
+
const rows = snapshots.length
|
|
929
|
+
? h('div', { style: { maxHeight: '260px', overflowY: 'auto', display: 'flex', flexDirection: 'column' } },
|
|
930
|
+
snapshots.map((s) => h('div', {
|
|
931
|
+
key: s.dir || s.name,
|
|
932
|
+
style: {
|
|
933
|
+
display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap',
|
|
934
|
+
padding: '7px 2px',
|
|
935
|
+
borderTop: '1px solid var(--dsw-alias-border-l1)',
|
|
936
|
+
},
|
|
937
|
+
},
|
|
938
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0, flex: 1 } },
|
|
939
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '6px', flexWrap: 'wrap' } },
|
|
940
|
+
kindBadge(kindOf(s)),
|
|
941
|
+
h('div', {
|
|
942
|
+
style: { fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-primary)', fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' },
|
|
943
|
+
}, s.name)),
|
|
944
|
+
h('div', { style: S.hint },
|
|
945
|
+
`${when(s.at)} · ${rel(s.at)} · ${snapSummary(s)}`
|
|
946
|
+
+ (kindOf(s) !== 'profile' && s.entryNames && s.entryNames.length
|
|
947
|
+
? M('(含 ', ' (contains ') + s.entryNames.slice(0, 3).join('、') + (Number(s.entries) > 3 ? '…' : '') + M(')', ')')
|
|
948
|
+
: '')),
|
|
949
|
+
),
|
|
950
|
+
kindOf(s) === 'other'
|
|
951
|
+
// 认不出类型的备份也给入口:弹一段「手动还原」指引(路径 + 里面有什么 + 该拷到哪)
|
|
952
|
+
? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setManual(s) }, M('手动还原', 'How to restore'))
|
|
953
|
+
: (s.usable === false
|
|
954
|
+
? h('button', { type: 'button', style: { ...S.btn, opacity: 0.5, cursor: 'not-allowed' }, disabled: true }, M('空备份', 'Empty backup'))
|
|
955
|
+
: h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => askRestore(s) },
|
|
956
|
+
kindOf(s) === 'plugin' ? M('回滚插件', 'Roll back plugin')
|
|
957
|
+
: (kindOf(s) === 'session' ? M('还原会话', 'Restore sessions') : M('立即还原', 'Restore now')),
|
|
958
|
+
)),
|
|
959
|
+
)))
|
|
960
|
+
: h('div', { style: S.hint }, backup.exists
|
|
961
|
+
? M('这个备份目录下还没有快照(apply.ps1 每次拉取/落地之前都会打一份)', 'No snapshots in this backup folder yet (apply.ps1 makes one before every pull/apply)')
|
|
962
|
+
: M(`备份目录不存在:${backup.root || defaultRoot}`, `Backup folder does not exist: ${backup.root || defaultRoot}`))
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* 确认环节 + 排队回执 + 上次还原结果。
|
|
966
|
+
* 三个块都直接挂在卡片里(不是弹窗),这样确认时能同时看到快照列表做对照。
|
|
967
|
+
*/
|
|
968
|
+
const listBox = (title, items, tone) => (items && items.length)
|
|
969
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
|
|
970
|
+
h('div', { style: { ...S.hint, color: tone || 'var(--dsw-alias-label-secondary)' } }, title),
|
|
971
|
+
h('div', {
|
|
972
|
+
style: {
|
|
973
|
+
...S.hint, fontFamily: 'Consolas, ui-monospace, monospace',
|
|
974
|
+
maxHeight: '110px', overflowY: 'auto', wordBreak: 'break-all',
|
|
975
|
+
},
|
|
976
|
+
}, items.join(' · ')))
|
|
977
|
+
: null
|
|
978
|
+
|
|
979
|
+
const pv = (confirm && confirm.preview) || {}
|
|
980
|
+
const pvRemovePlugins = pv.pluginsRemove || []
|
|
981
|
+
const pvInstallPlugins = pv.pluginsInstall || []
|
|
982
|
+
const pvRemoveFiles = pv.willRemove || []
|
|
983
|
+
const pvOverwrite = pv.willOverwrite || []
|
|
984
|
+
const pvWrite = pv.willWrite || []
|
|
985
|
+
|
|
986
|
+
const confirmKind = confirm ? kindOf(confirm.snap) : 'profile'
|
|
987
|
+
const boxStyle = {
|
|
988
|
+
display: 'flex', flexDirection: 'column', gap: '5px',
|
|
989
|
+
padding: '9px 11px', borderRadius: '8px',
|
|
990
|
+
border: '1px solid var(--dsw-alias-border-l1)',
|
|
991
|
+
background: 'var(--dsw-alias-bg-module-platform)',
|
|
992
|
+
}
|
|
993
|
+
const confirmTitle = !confirm ? '' : (confirmKind === 'plugin'
|
|
994
|
+
? M(`确认把插件回滚到 ${confirm.snap.name}?`, `Roll the plugin back to ${confirm.snap.name}?`)
|
|
995
|
+
: (confirmKind === 'session'
|
|
996
|
+
? M(`确认还原会话备份 ${confirm.snap.name}?`, `Restore session backup ${confirm.snap.name}?`)
|
|
997
|
+
: M(`确认还原到 ${confirm.snap.name}?`, `Restore to ${confirm.snap.name}?`)))
|
|
998
|
+
const confirmPrimary = confirmKind === 'plugin'
|
|
999
|
+
? M('确认回滚插件', 'Confirm plugin rollback')
|
|
1000
|
+
: (confirmKind === 'session' ? M('确认还原会话', 'Confirm session restore') : M('确认还原', 'Confirm restore'))
|
|
1001
|
+
|
|
1002
|
+
// 插件 / 会话备份的确认块:只讲「写到哪、写几个、先备份到哪」,不给 willRemove —— 它们不是时点回退
|
|
1003
|
+
const kindConfirmBlock = (confirm && confirmKind !== 'profile')
|
|
1004
|
+
? h('div', { style: boxStyle },
|
|
1005
|
+
h('div', { style: { ...S.cardTitle, fontSize: '13px' } }, confirmTitle),
|
|
1006
|
+
h('div', { style: S.hint }, M(
|
|
1007
|
+
`备份时间 ${when(confirm.snap.at)}(${rel(confirm.snap.at)})· ${snapSummary(confirm.snap)}`,
|
|
1008
|
+
`Backup ${when(confirm.snap.at)} (${rel(confirm.snap.at)}) · ${snapSummary(confirm.snap)}`,
|
|
1009
|
+
)),
|
|
1010
|
+
listBox(M(`将写回到:${pv.target || ''}`, `Writing back into: ${pv.target || ''}`), pv.source ? [pv.source] : [], 'var(--dsw-alias-label-secondary)'),
|
|
1011
|
+
listBox(M(`会写回 ${Number(pv.total || 0)} 项`, `Writing back ${Number(pv.total || 0)} item(s)`), pv.items || []),
|
|
1012
|
+
h('div', { style: S.hint }, pv.note || ''),
|
|
1013
|
+
h('div', { style: S.hint }, M(
|
|
1014
|
+
`动手前先整份备份当前位置到 ${pv.backupTo || 'backups\\<自动命名>'},不满意还能再退回来。`,
|
|
1015
|
+
`The current location is copied to ${pv.backupTo || 'backups\\<auto-named>'} first, so you can undo it.`,
|
|
1016
|
+
)),
|
|
1017
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
|
|
1018
|
+
'确认后:客户端正常退出 → 弹出进度窗口执行 → 完成后自动重启客户端。',
|
|
1019
|
+
'After confirming: the client closes normally, a progress window runs it, then the client restarts automatically.',
|
|
1020
|
+
)),
|
|
1021
|
+
h('div', { style: S.actions },
|
|
1022
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: doRestore },
|
|
1023
|
+
busy ? M('排队中…', 'Queuing…') : confirmPrimary),
|
|
1024
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setConfirm(null) }, M('取消', 'Cancel')),
|
|
1025
|
+
),
|
|
1026
|
+
)
|
|
1027
|
+
: null
|
|
1028
|
+
|
|
1029
|
+
const confirmBlock = (confirm && confirmKind === 'profile')
|
|
1030
|
+
? h('div', {
|
|
1031
|
+
style: boxStyle,
|
|
1032
|
+
},
|
|
1033
|
+
h('div', { style: { ...S.cardTitle, fontSize: '13px' } }, confirmTitle),
|
|
1034
|
+
h('div', { style: S.hint }, M(
|
|
1035
|
+
`快照时间 ${when(confirm.snap.at)}(${rel(confirm.snap.at)})· ${confirm.snap.files || 0} 个文件 · ${size(confirm.snap.bytes)} · ${confirm.snap.plugins || 0} 个插件`,
|
|
1036
|
+
`Snapshot ${when(confirm.snap.at)} (${rel(confirm.snap.at)}) · ${confirm.snap.files || 0} files · ${size(confirm.snap.bytes)} · ${confirm.snap.plugins || 0} plugins`,
|
|
1037
|
+
)),
|
|
1038
|
+
listBox(
|
|
1039
|
+
M(`将撤走 ${pvRemovePlugins.length} 个快照之后装上的插件`, `Removing ${pvRemovePlugins.length} plugin(s) installed after this snapshot`),
|
|
1040
|
+
pvRemovePlugins, 'var(--dsw-alias-state-error-primary)',
|
|
1041
|
+
),
|
|
1042
|
+
listBox(
|
|
1043
|
+
M(`将移走 ${pvRemoveFiles.length} 个快照之后新增的文件`, `Moving out ${pvRemoveFiles.length} file(s) created after this snapshot`),
|
|
1044
|
+
pvRemoveFiles, 'var(--dsw-alias-state-error-primary)',
|
|
1045
|
+
),
|
|
1046
|
+
listBox(
|
|
1047
|
+
M(`将覆盖 ${pvOverwrite.length} 个、写回 ${pvWrite.length} 个文件`, `Overwriting ${pvOverwrite.length}, writing back ${pvWrite.length} file(s)`),
|
|
1048
|
+
[].concat(pvOverwrite, pvWrite),
|
|
1049
|
+
),
|
|
1050
|
+
listBox(
|
|
1051
|
+
M(`还原后要重新安装 ${pvInstallPlugins.length} 个插件`, `Re-installing ${pvInstallPlugins.length} plugin(s) afterwards`),
|
|
1052
|
+
pvInstallPlugins,
|
|
1053
|
+
),
|
|
1054
|
+
h('div', { style: S.hint }, M(
|
|
1055
|
+
'动手前会把当前配置整份存到 backups\\manual-<时间戳>;撤走的东西另有 rollback 清单,随时能再还原回来。',
|
|
1056
|
+
'The current config is copied to backups\\manual-<timestamp> first, and everything removed is listed in a rollback manifest — both can be restored later.',
|
|
1057
|
+
)),
|
|
1058
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
|
|
1059
|
+
'确认后:客户端正常退出 → 弹出进度窗口执行还原 → 完成后自动重启客户端。',
|
|
1060
|
+
'After confirming: the client closes normally, a progress window runs the restore, then the client restarts automatically.',
|
|
1061
|
+
)),
|
|
1062
|
+
h('div', { style: S.actions },
|
|
1063
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: doRestore },
|
|
1064
|
+
busy ? M('排队中…', 'Queuing…') : M('确认还原', 'Confirm restore')),
|
|
1065
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setConfirm(null) }, M('取消', 'Cancel')),
|
|
1066
|
+
),
|
|
1067
|
+
)
|
|
1068
|
+
: null
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* 认不出类型的备份也不是死路:弹出「手动还原」指引 ——
|
|
1072
|
+
* 备份位置、里面有什么、按内容对照目标位置、拷之前先另存。
|
|
1073
|
+
* 不硬猜目标:猜错一次就是把 profile 覆盖成插件包(0.3.48 前那类误判的教训)。
|
|
1074
|
+
*/
|
|
1075
|
+
const manualBlock = manual
|
|
1076
|
+
? h('div', { style: boxStyle },
|
|
1077
|
+
h('div', { style: { ...S.cardTitle, fontSize: '13px' } }, M(`手动还原:${manual.name}`, `Manual restore: ${manual.name}`)),
|
|
1078
|
+
h('div', {
|
|
1079
|
+
style: { ...S.hint, fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' },
|
|
1080
|
+
}, M(`备份位置:${manual.dir}`, `Backup path: ${manual.dir}`)),
|
|
1081
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warning-primary)' } }, M(
|
|
1082
|
+
'这份备份认不出类型,自动还原不知道该写回哪,按下面三步手动拷:',
|
|
1083
|
+
'This backup cannot be classified, so there is no automatic target. Copy it by hand:',
|
|
1084
|
+
)),
|
|
1085
|
+
h('div', { style: S.hint }, M('1. 先完全退出 DSH —— 配置、插件、会话在运行时都被客户端持有。', '1. Quit DSH completely — config, plugins and sessions are held while it runs.')),
|
|
1086
|
+
h('div', { style: S.hint }, M('2. 打开上面的备份目录,按里面的内容对照目标位置:', '2. Open the backup folder and match its contents to a target:')),
|
|
1087
|
+
manualTargets().map((line, i) => h('div', { key: 'mt' + i, style: { ...S.hint, paddingLeft: '12px' } }, line)),
|
|
1088
|
+
manual.entryNames && manual.entryNames.length
|
|
1089
|
+
? h('div', {
|
|
1090
|
+
style: { ...S.hint, paddingLeft: '12px', fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' },
|
|
1091
|
+
}, M('这份里看到:', 'Contains: ') + manual.entryNames.join(' · '))
|
|
1092
|
+
: null,
|
|
1093
|
+
h('div', { style: S.hint }, M('3. 拷之前把目标位置现有文件另存一份;拷完重启客户端。', '3. Back up the target first, then copy and restart the client.')),
|
|
1094
|
+
h('div', { style: S.actions },
|
|
1095
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setManual(null) }, M('知道了', 'Got it')),
|
|
1096
|
+
),
|
|
1097
|
+
)
|
|
1098
|
+
: null
|
|
1099
|
+
|
|
1100
|
+
const queuedBlock = queued
|
|
1101
|
+
? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } },
|
|
1102
|
+
M(
|
|
1103
|
+
`已排队:还原到 ${queued.snap.name}。客户端即将退出,退出后会弹出进度窗口;完成后自动重启。`,
|
|
1104
|
+
`Queued: restoring to ${queued.snap.name}. The client will close, a progress window will run it, then it restarts.`,
|
|
1105
|
+
))
|
|
1106
|
+
: null
|
|
1107
|
+
|
|
1108
|
+
const lastRes = props.data && props.data.auto && props.data.auto.lastResult
|
|
1109
|
+
const lastRestoreBlock = (lastRes && lastRes.mode === 'restore')
|
|
1110
|
+
? h('div', { style: { ...S.footnote, color: lastRes.ok ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)' } },
|
|
1111
|
+
M(
|
|
1112
|
+
`上次还原:${lastRes.ok ? '成功' : '失败'} · ${when(lastRes.at)} · ${lastRes.message || ''}${lastRes.log ? ` · 日志 ${lastRes.log}` : ''}`,
|
|
1113
|
+
`Last restore: ${lastRes.ok ? 'ok' : 'failed'} · ${when(lastRes.at)} · ${lastRes.message || ''}${lastRes.log ? ` · log ${lastRes.log}` : ''}`,
|
|
1114
|
+
))
|
|
1115
|
+
: null
|
|
1116
|
+
|
|
1117
|
+
return h('div', { style: S.card },
|
|
1118
|
+
h('div', { style: S.cardHead },
|
|
1119
|
+
h('div', { style: S.cardTitle }, M('还原备份', 'Restore backup')),
|
|
1120
|
+
h('span', { style: { ...S.footnote, fontFamily: 'Consolas, ui-monospace, monospace' } },
|
|
1121
|
+
backup.exists ? M(`${backup.count || 0} 份快照`, `${backup.count || 0} snapshot(s)`) : M('目录不存在', 'folder missing')),
|
|
1122
|
+
h('div', { style: { flex: 1 } }, null),
|
|
1123
|
+
h('div', { style: S.actions },
|
|
1124
|
+
editing
|
|
1125
|
+
? h(react.Fragment, null,
|
|
1126
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: () => save({ backupRoot: root.trim() }) }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
1127
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => save({ clearBackupRoot: true }) }, M('恢复默认', 'Use default')),
|
|
1128
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
|
|
1129
|
+
)
|
|
1130
|
+
: h('button', { type: 'button', style: S.btn, disabled: !props.data || busy, onClick: startEdit }, M('修改', 'Edit')),
|
|
1131
|
+
),
|
|
1132
|
+
),
|
|
1133
|
+
h('div', { style: S.kvRow },
|
|
1134
|
+
h('div', { style: S.kvKey }, M('备份目录', 'Backup folder')),
|
|
1135
|
+
editing
|
|
1136
|
+
? h('input', {
|
|
1137
|
+
type: 'text', style: S.input, value: root, spellCheck: false,
|
|
1138
|
+
placeholder: defaultRoot || M('留空 = 默认 <用户目录>\\.dsh\\backups', 'Empty = default <home>\\.dsh\\backups'),
|
|
1139
|
+
onChange: (e) => setRoot(e.target.value),
|
|
1140
|
+
})
|
|
1141
|
+
: h('div', { style: { ...S.kvVal, fontFamily: 'Consolas, ui-monospace, monospace' } },
|
|
1142
|
+
`${remote.backupRoot || backup.root || defaultRoot}${(remote.backupRootCustom ? M('(本机设置)', ' (machine setting)') : M('(默认)', ' (default)'))}`),
|
|
1143
|
+
),
|
|
1144
|
+
rows,
|
|
1145
|
+
confirmBlock,
|
|
1146
|
+
kindConfirmBlock,
|
|
1147
|
+
manualBlock,
|
|
1148
|
+
queuedBlock,
|
|
1149
|
+
lastRestoreBlock,
|
|
1150
|
+
made
|
|
1151
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
1152
|
+
h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } },
|
|
1153
|
+
M(`已生成:${made.path}`, `Generated: ${made.path}`)),
|
|
1154
|
+
h('div', { style: S.code }, made.command || ''),
|
|
1155
|
+
h('div', { style: S.footnote }, M(
|
|
1156
|
+
'完全退出 DSH 后双击这份 .cmd:先打印计划,输 y 才真正写(写前自动备份当前状态)。',
|
|
1157
|
+
'Quit DSH, then double-click the .cmd: it prints the plan and only writes after y (backing up the current state first).',
|
|
1158
|
+
)),
|
|
1159
|
+
)
|
|
1160
|
+
: null,
|
|
1161
|
+
err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`操作失败:${err}`, `Failed: ${err}`)) : null,
|
|
1162
|
+
msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
|
|
1163
|
+
h('div', { style: S.footnote }, M(
|
|
1164
|
+
'留空 = 默认 ~\\.dsh\\backups;只能选该目录下的备份。备份根里混着三类:配置快照(回到该时间点,之后新增的文件与插件移进 rollback,可再还原)· 插件备份(回滚插件本体)· 会话备份(把会话目录写回)。'
|
|
1165
|
+
+ '认不出类型的给「手动还原」指引(路径 + 里面有什么 + 该拷到哪)。每类动手前都先把当前位置整份备份,不留糊涂账。',
|
|
1166
|
+
'Empty = default ~\\.dsh\\backups; only backups inside it are offered. Three kinds share this folder: config snapshots (roll back to that point; later additions move into the rollback folder and stay restorable), plugin backups (roll the plugin itself back), session backups (write session folders back).'
|
|
1167
|
+
+ ' Anything unrecognised gets a manual restore hint (path, contents, and where to copy). Every kind backs up the current state first.',
|
|
1168
|
+
)),
|
|
1169
|
+
)
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* 「同步冲突」卡:拉取被本机文件挡住时,sync.ps1 会先备份本机副本、再写一份冲突清单
|
|
1174
|
+
* (<DshHome>\sync-conflicts.json,含两侧预览)。
|
|
1175
|
+
* 这里逐项列出,点行展开看两边内容,选「用本机 / 用云端」,保存后由 sync.ps1 在下次拉取时落地:
|
|
1176
|
+
* 用云端 = 丢掉本机那份(备份里留着,随时可「还原」)
|
|
1177
|
+
* 用本机 = 先让云端版本落地,再把本机那份写回工作区,下次推送带上
|
|
1178
|
+
* 没冲突时这张卡不出现(不占版面)。
|
|
1179
|
+
*/
|
|
1180
|
+
function ConflictCard(props) {
|
|
1181
|
+
const [state, setState] = react.useState(null)
|
|
1182
|
+
const [open, setOpen] = react.useState({})
|
|
1183
|
+
const [busy, setBusy] = react.useState(false)
|
|
1184
|
+
const [err, setErr] = react.useState('')
|
|
1185
|
+
const [msg, setMsg] = react.useState('')
|
|
1186
|
+
|
|
1187
|
+
const load = async () => {
|
|
1188
|
+
try { setState(await callConflict()) } catch (e) { setErr(String((e && e.message) || e)) }
|
|
1189
|
+
}
|
|
1190
|
+
react.useEffect(() => { load() }, [])
|
|
1191
|
+
|
|
1192
|
+
const size = (n) => {
|
|
1193
|
+
const v = Number(n) || 0
|
|
1194
|
+
if (v >= 1048576) return `${(v / 1048576).toFixed(1)} MB`
|
|
1195
|
+
if (v >= 1024) return `${(v / 1024).toFixed(1)} KB`
|
|
1196
|
+
return `${v} B`
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
if (!state) {
|
|
1200
|
+
return h('div', { style: S.card },
|
|
1201
|
+
h('div', { style: S.cardTitle }, M('同步冲突', 'Sync conflicts')),
|
|
1202
|
+
h('div', { style: S.hint }, err
|
|
1203
|
+
? M(`读取失败:${err}`, `Read failed: ${err}`)
|
|
1204
|
+
: M('正在读取冲突清单…', 'Loading conflicts…')),
|
|
1205
|
+
)
|
|
1206
|
+
}
|
|
1207
|
+
if (!state.exists) return null
|
|
1208
|
+
|
|
1209
|
+
const items = Array.isArray(state.items) ? state.items : []
|
|
1210
|
+
const pending = items.filter((it) => !it.choice).length
|
|
1211
|
+
const chosen = items.length - pending
|
|
1212
|
+
|
|
1213
|
+
const setChoice = (path, choice) => {
|
|
1214
|
+
setMsg('')
|
|
1215
|
+
setState({ ...state, items: items.map((it) => (it.path === path ? { ...it, choice } : it)) })
|
|
1216
|
+
}
|
|
1217
|
+
const setAll = (choice) => {
|
|
1218
|
+
setMsg('')
|
|
1219
|
+
setState({ ...state, items: items.map((it) => ({ ...it, choice })) })
|
|
1220
|
+
}
|
|
1221
|
+
const save = async () => {
|
|
1222
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1223
|
+
try {
|
|
1224
|
+
const r = await callConflict({ items: items.map((it) => ({ path: it.path, choice: it.choice || '' })) })
|
|
1225
|
+
setMsg(r.pending
|
|
1226
|
+
? M(`已保存:${r.chosen}/${r.total} 项已选,还有 ${r.pending} 项没选(选完才能拉取)`, `Saved: ${r.chosen}/${r.total} chosen, ${r.pending} still unset (a pull needs them all)`)
|
|
1227
|
+
: M(`已保存:${r.chosen}/${r.total} 项都选好了,去点「立即拉取」`, `Saved: all ${r.chosen}/${r.total} chosen — now click "Pull now"`))
|
|
1228
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
1229
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
1230
|
+
}
|
|
1231
|
+
const restore = async (path, side) => {
|
|
1232
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1233
|
+
try {
|
|
1234
|
+
await callConflict({ action: 'restore', path, side })
|
|
1235
|
+
setMsg(side === 'cloud'
|
|
1236
|
+
? M(`已从备份把云端副本还原到:${path}`, `Cloud copy restored from backup: ${path}`)
|
|
1237
|
+
: M(`已从备份把本机副本还原到:${path}`, `Local copy restored from backup: ${path}`))
|
|
1238
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
1239
|
+
}
|
|
1240
|
+
const discard = async () => {
|
|
1241
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1242
|
+
try {
|
|
1243
|
+
await callConflict({ action: 'reset' })
|
|
1244
|
+
setState({ exists: false })
|
|
1245
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
1246
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy(false) }
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
const preview = (title, text, empty) => h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', minWidth: 0 } },
|
|
1250
|
+
h('div', { style: S.hint }, title),
|
|
1251
|
+
h('pre', {
|
|
1252
|
+
style: {
|
|
1253
|
+
margin: 0, padding: '6px 8px', maxHeight: '180px', overflow: 'auto',
|
|
1254
|
+
fontSize: '11px', lineHeight: '16px', whiteSpace: 'pre-wrap', wordBreak: 'break-word',
|
|
1255
|
+
fontFamily: 'Consolas, ui-monospace, monospace',
|
|
1256
|
+
border: '1px solid var(--dsw-alias-border-l1)', borderRadius: '6px',
|
|
1257
|
+
background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-secondary, var(--dsw-alias-label-primary))',
|
|
1258
|
+
},
|
|
1259
|
+
}, text || empty),
|
|
1260
|
+
)
|
|
1261
|
+
|
|
1262
|
+
const rows = items.map((it) => {
|
|
1263
|
+
const expanded = open[it.path] === true
|
|
1264
|
+
return h('div', {
|
|
1265
|
+
key: it.path,
|
|
1266
|
+
style: { borderTop: '1px solid var(--dsw-alias-border-l1)', paddingTop: '6px', paddingBottom: '2px' },
|
|
1267
|
+
},
|
|
1268
|
+
h('div', {
|
|
1269
|
+
style: { display: 'flex', alignItems: 'center', gap: '8px', cursor: 'pointer' },
|
|
1270
|
+
onClick: () => setOpen({ ...open, [it.path]: !expanded }),
|
|
1271
|
+
},
|
|
1272
|
+
h('span', { style: { flexShrink: 0, width: '10px', fontSize: '11px', color: 'var(--dsw-alias-label-tertiary)' } }, expanded ? '▾' : '▸'),
|
|
1273
|
+
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: '1px' } },
|
|
1274
|
+
h('div', {
|
|
1275
|
+
style: { fontSize: '12px', lineHeight: '18px', fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' },
|
|
1276
|
+
}, it.path),
|
|
1277
|
+
h('div', { style: S.hint },
|
|
1278
|
+
M(
|
|
1279
|
+
`${it.kind === 'untracked' ? '本机未入库' : '本机已修改'} · 本机 ${size(it.localSize)} vs 云端 ${size(it.remoteSize)}${it.binary ? ' · 二进制,只看大小' : ''}`,
|
|
1280
|
+
`${it.kind === 'untracked' ? 'untracked' : 'modified'} · local ${size(it.localSize)} vs cloud ${size(it.remoteSize)}${it.binary ? ' · binary, size only' : ''}`,
|
|
1281
|
+
)),
|
|
1282
|
+
),
|
|
1283
|
+
h('div', { style: { display: 'flex', gap: '4px', flexShrink: 0 } },
|
|
1284
|
+
h('button', {
|
|
1285
|
+
type: 'button',
|
|
1286
|
+
style: it.choice === 'local' ? S.btnPrimary : S.btn,
|
|
1287
|
+
onClick: (e) => { e.stopPropagation(); setChoice(it.path, 'local') },
|
|
1288
|
+
}, M('用本机', 'Keep local')),
|
|
1289
|
+
h('button', {
|
|
1290
|
+
type: 'button',
|
|
1291
|
+
style: it.choice === 'cloud' ? S.btnPrimary : S.btn,
|
|
1292
|
+
onClick: (e) => { e.stopPropagation(); setChoice(it.path, 'cloud') },
|
|
1293
|
+
}, M('用云端', 'Use cloud')),
|
|
1294
|
+
),
|
|
1295
|
+
),
|
|
1296
|
+
expanded
|
|
1297
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '6px', marginLeft: '18px', marginTop: '6px' } },
|
|
1298
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '8px' } },
|
|
1299
|
+
preview(M('本机版本(工作区)', 'Local (working tree)'), it.localPreview,
|
|
1300
|
+
M('(空文件 / 无法预览)', '(empty or not previewable)')),
|
|
1301
|
+
preview(M('云端版本(远端提交)', 'Cloud (remote commit)'), it.remotePreview,
|
|
1302
|
+
M('(空文件 / 无法预览)', '(empty or not previewable)')),
|
|
1303
|
+
),
|
|
1304
|
+
h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
1305
|
+
h('button', {
|
|
1306
|
+
type: 'button',
|
|
1307
|
+
style: S.btn,
|
|
1308
|
+
disabled: busy || !it.localSaved,
|
|
1309
|
+
onClick: () => restore(it.path, 'local'),
|
|
1310
|
+
}, M('还原本机副本', 'Restore local copy')),
|
|
1311
|
+
h('button', {
|
|
1312
|
+
type: 'button',
|
|
1313
|
+
style: S.btn,
|
|
1314
|
+
disabled: busy || !it.cloudSaved,
|
|
1315
|
+
onClick: () => restore(it.path, 'cloud'),
|
|
1316
|
+
}, M('还原云端副本', 'Restore cloud copy')),
|
|
1317
|
+
h('span', { style: S.footnote },
|
|
1318
|
+
M(
|
|
1319
|
+
(it.localSaved ? '本机副本已备份' : '本机副本备份缺失') + ' · ' + (it.cloudSaved ? '云端副本已备份' : '云端副本备份缺失(旧清单或备份失败)'),
|
|
1320
|
+
(it.localSaved ? 'local copy saved' : 'local copy MISSING') + ' · ' + (it.cloudSaved ? 'cloud copy saved' : 'cloud copy MISSING (older list or backup failed)'),
|
|
1321
|
+
)),
|
|
1322
|
+
),
|
|
1323
|
+
h('div', { style: S.footnote },
|
|
1324
|
+
M('备份目录:' + (state.backupDir || '?'), 'Backup folder: ' + (state.backupDir || '?')),
|
|
1325
|
+
),
|
|
1326
|
+
)
|
|
1327
|
+
: null,
|
|
1328
|
+
)
|
|
1329
|
+
})
|
|
1330
|
+
|
|
1331
|
+
return h('div', { style: S.card },
|
|
1332
|
+
h('div', { style: S.cardHead },
|
|
1333
|
+
h('div', { style: S.cardTitle }, M('同步冲突', 'Sync conflicts')),
|
|
1334
|
+
h('span', { style: { ...S.footnote } },
|
|
1335
|
+
M(`${items.length} 个文件挡住拉取`, `${items.length} file(s) blocking the pull`)),
|
|
1336
|
+
h('div', { style: { flex: 1 } }, null),
|
|
1337
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('刷新', 'Refresh')),
|
|
1338
|
+
),
|
|
1339
|
+
h('div', { style: S.hint },
|
|
1340
|
+
M(
|
|
1341
|
+
'这些文件本机有、云端也有同名版本,git 不肯直接覆盖。逐项选:用云端 = 丢弃本机那份;用本机 = 先让云端落地、再把本机版写回,下次推送带上。两份副本都会存进备份目录,展开后哪一份都能还原。',
|
|
1342
|
+
'These paths exist both locally and in the cloud, so git refuses to overwrite them. Pick per file: Cloud = drop the local copy; Local = apply the cloud version, then write the local one back so the next push carries it. Both copies are saved in the backup folder and either one can be restored.',
|
|
1343
|
+
)),
|
|
1344
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', maxHeight: '420px', overflowY: 'auto' } }, rows),
|
|
1345
|
+
h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap', marginTop: '4px' } },
|
|
1346
|
+
h('span', { style: S.hint },
|
|
1347
|
+
M(`已选 ${chosen}/${items.length}${pending ? `,${pending} 项未选` : ''}`, `${chosen}/${items.length} chosen${pending ? `, ${pending} unset` : ''}`)),
|
|
1348
|
+
h('div', { style: { flex: 1 } }, null),
|
|
1349
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setAll('cloud') }, M('全部用云端', 'All cloud')),
|
|
1350
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setAll('local') }, M('全部用本机', 'All local')),
|
|
1351
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: save }, busy ? M('保存中…', 'Saving…') : M('保存选择', 'Save')),
|
|
1352
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: discard }, M('放弃清单', 'Discard')),
|
|
1353
|
+
),
|
|
1354
|
+
err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`操作失败:${err}`, `Failed: ${err}`)) : null,
|
|
1355
|
+
msg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, msg) : null,
|
|
1356
|
+
h('div', { style: S.footnote },
|
|
1357
|
+
M(
|
|
1358
|
+
'保存后点「立即拉取」:脚本按选择先移走被挡的文件、快进到云端,再把「用本机」的写回。清单与备份都留在本机。',
|
|
1359
|
+
'After saving, click "Pull now": the script clears the blocked files, fast-forwards, then writes back the local ones. The list and backup stay on this machine.',
|
|
1360
|
+
)),
|
|
1361
|
+
)
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
/** 面板整页:左侧栏「配置同步」点开后看到的就是这个。 */
|
|
1365
|
+
/**
|
|
1366
|
+
* 「同步内容」卡:把云端同步的十组内容逐组列出,点行即可展开看明细,明细项也能单独取消。
|
|
1367
|
+
* 默认全勾;取消勾选后推送不再抓、拉取不再还原(两侧共用 <DshHome>\config-sync-scope.json)。
|
|
1368
|
+
* deleteCloud(默认关)是唯一的破坏性选项:打开后取消勾选会顺手删掉仓库里的副本。
|
|
1369
|
+
* 只读优先:进卡先只看不改,点「修改」才解锁勾选,改完点「保存」才落盘(取消=丢弃这次改动)。
|
|
1370
|
+
*/
|
|
1371
|
+
/**
|
|
1372
|
+
* 「插件数据与额外路径」卡:新插件自己往 <DshHome>\<插件名>\ 或自选目录里写的配置/数据,
|
|
1373
|
+
* 靠这组的规则决定哪些跟着配置走。规则落在 <DshHome>\config-sync-extra.json:
|
|
1374
|
+
* - 单文件上限(默认 100MB,GitHub 单文件硬限,调大也按 100MB 算)
|
|
1375
|
+
* - 排除名单(通配,一行一条;可恢复默认)
|
|
1376
|
+
* - 额外路径(自己加的绝对路径,目录或单个文件)
|
|
1377
|
+
* 保存后 capture 立刻按新规则抓取,apply 按 manifest 反向展开写回。
|
|
1378
|
+
*/
|
|
1379
|
+
function ExtraCard() {
|
|
1380
|
+
const [data, setData] = react.useState(null)
|
|
1381
|
+
const [draft, setDraft] = react.useState(null)
|
|
1382
|
+
const [busy, setBusy] = react.useState(false)
|
|
1383
|
+
const [editing, setEditing] = react.useState(false)
|
|
1384
|
+
const [err, setErr] = react.useState('')
|
|
1385
|
+
const [msg, setMsg] = react.useState('')
|
|
1386
|
+
const [newPath, setNewPath] = react.useState('')
|
|
1387
|
+
const [newLabel, setNewLabel] = react.useState('')
|
|
1388
|
+
|
|
1389
|
+
const toDraft = (d) => ({
|
|
1390
|
+
pdEnabled: d.config.pluginData.enabled !== false,
|
|
1391
|
+
exEnabled: d.config.extra.enabled !== false,
|
|
1392
|
+
maxMB: Math.round((d.config.pluginData.maxFileBytes || d.hardMaxBytes) / (1024 * 1024)),
|
|
1393
|
+
excludeText: (d.config.pluginData.exclude || []).join('\n'),
|
|
1394
|
+
skipDirs: [...(d.config.pluginData.skipDirs || [])],
|
|
1395
|
+
paths: (d.config.extra.paths || []).map((p) => ({ ...p })),
|
|
1396
|
+
})
|
|
1397
|
+
|
|
1398
|
+
const load = async () => {
|
|
1399
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1400
|
+
try {
|
|
1401
|
+
const r = await callExtraConfig()
|
|
1402
|
+
setData(r)
|
|
1403
|
+
setDraft(toDraft(r))
|
|
1404
|
+
} catch (e) {
|
|
1405
|
+
setErr(String((e && e.message) || e))
|
|
1406
|
+
} finally { setBusy(false) }
|
|
1407
|
+
}
|
|
1408
|
+
react.useEffect(() => { load() }, [])
|
|
1409
|
+
|
|
1410
|
+
const save = async () => {
|
|
1411
|
+
if (!data || !draft) return
|
|
1412
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1413
|
+
try {
|
|
1414
|
+
const maxMB = Math.min(Math.max(1, Number(draft.maxMB) || 100), Math.round(data.hardMaxBytes / (1024 * 1024)))
|
|
1415
|
+
const r = await callExtraConfig({
|
|
1416
|
+
config: {
|
|
1417
|
+
pluginData: {
|
|
1418
|
+
enabled: draft.pdEnabled,
|
|
1419
|
+
maxFileBytes: maxMB * 1024 * 1024,
|
|
1420
|
+
exclude: draft.excludeText.split(/\r?\n/).map((x) => x.trim()).filter(Boolean),
|
|
1421
|
+
skipDirs: draft.skipDirs,
|
|
1422
|
+
},
|
|
1423
|
+
extra: {
|
|
1424
|
+
enabled: draft.exEnabled,
|
|
1425
|
+
paths: draft.paths.map((p) => ({ id: p.id, src: p.src, label: p.label })),
|
|
1426
|
+
},
|
|
1427
|
+
},
|
|
1428
|
+
})
|
|
1429
|
+
setData(r)
|
|
1430
|
+
setDraft(toDraft(r))
|
|
1431
|
+
setEditing(false)
|
|
1432
|
+
setMsg(M('已保存规则,下次推送按新规则抓取', 'Rules saved; the next push follows them'))
|
|
1433
|
+
} catch (e) {
|
|
1434
|
+
setErr(String((e && e.message) || e))
|
|
1435
|
+
} finally { setBusy(false) }
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// 取消:丢掉草稿,回到最后一次保存的状态(与「同步内容」卡同一套手势)
|
|
1439
|
+
const cancel = () => {
|
|
1440
|
+
if (data) setDraft(toDraft(data))
|
|
1441
|
+
setEditing(false)
|
|
1442
|
+
setErr(''); setMsg('')
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
const resetExclude = () => {
|
|
1446
|
+
if (!data || !editing) return
|
|
1447
|
+
setDraft({ ...draft, excludeText: (data.defaults.exclude || []).join('\n') })
|
|
1448
|
+
setMsg(M('已填回默认排除名单(还要点保存才生效)', 'Default exclusions restored in the form (click Save to apply)'))
|
|
1449
|
+
}
|
|
1450
|
+
const addPath = () => {
|
|
1451
|
+
const p = newPath.trim()
|
|
1452
|
+
if (!p || !draft || !editing) return
|
|
1453
|
+
if (!/^([A-Za-z]:[\\/]|\\\\)/.test(p)) {
|
|
1454
|
+
setErr(M('要填绝对路径,比如 C:\\Users\\你\\某个目录(相对路径换台机器对不上)', 'Use an absolute path such as C:\\Users\\you\\some-folder'))
|
|
1455
|
+
return
|
|
1456
|
+
}
|
|
1457
|
+
const label = newLabel.trim() || p.replace(/[\\/]+$/, '').split(/[\\/]/).pop() || 'extra'
|
|
1458
|
+
setDraft({ ...draft, paths: [...draft.paths, { id: label, src: p, label }] })
|
|
1459
|
+
setNewPath(''); setNewLabel(''); setErr('')
|
|
1460
|
+
setMsg(M('已加进列表,点「保存」才真正生效', 'Added to the list — click Save to apply'))
|
|
1461
|
+
}
|
|
1462
|
+
const removePath = (idx) => {
|
|
1463
|
+
if (!draft || !editing) return
|
|
1464
|
+
setDraft({ ...draft, paths: draft.paths.filter((_, i) => i !== idx) })
|
|
1465
|
+
setMsg(M('已从列表移除,点「保存」才真正生效', 'Removed from the list — click Save to apply'))
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
if (!data || !draft) {
|
|
1469
|
+
return h('div', { style: S.card },
|
|
1470
|
+
h('div', { style: S.cardTitle }, M('插件数据与额外路径', 'Plugin data & extra paths')),
|
|
1471
|
+
h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('正在读取规则…', 'Loading rules…')))
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
const hardMB = Math.round(data.hardMaxBytes / (1024 * 1024))
|
|
1475
|
+
return h('div', { style: S.card },
|
|
1476
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' } },
|
|
1477
|
+
h('div', { style: S.cardTitle }, M('插件数据与额外路径', 'Plugin data & extra paths')),
|
|
1478
|
+
h('div', { style: { ...S.hint, flex: 1, minWidth: '160px' } },
|
|
1479
|
+
M('新插件自己的配置与数据:自动按插件目录收,规则可改', 'New plugins\' own config & data: collected per plugin folder, rules editable')),
|
|
1480
|
+
editing
|
|
1481
|
+
? [
|
|
1482
|
+
h('button', { key: 'save', type: 'button', style: S.btnPrimary, disabled: busy, onClick: save },
|
|
1483
|
+
busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
1484
|
+
h('button', { key: 'cancel', type: 'button', style: S.btn, disabled: busy, onClick: cancel }, M('取消', 'Cancel')),
|
|
1485
|
+
]
|
|
1486
|
+
: [
|
|
1487
|
+
h('button', { key: 'edit', type: 'button', style: S.btn, disabled: busy, onClick: () => { setEditing(true); setMsg(''); setErr('') } }, M('修改', 'Edit')),
|
|
1488
|
+
h('button', { key: 'reload', type: 'button', style: S.btn, disabled: busy, onClick: load }, M('刷新', 'Refresh')),
|
|
1489
|
+
],
|
|
1490
|
+
),
|
|
1491
|
+
h('div', { style: S.footnote },
|
|
1492
|
+
editing
|
|
1493
|
+
? M('改完点「保存」写进 config-sync-extra.json;点「取消」丢弃改动', 'Click Save to write config-sync-extra.json; Cancel drops the change')
|
|
1494
|
+
: M('只读:点右上「修改」才能改规则、加路径', 'Read-only: click Edit to change rules or add paths')),
|
|
1495
|
+
msg ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-success-primary, #1a7f37)' } }, msg) : null,
|
|
1496
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, err) : null,
|
|
1497
|
+
h('div', { style: S.footnote }, `${data.path}${data.exists ? '' : M('(尚未创建,保存后生成)', ' (created on first save)')}`),
|
|
1498
|
+
|
|
1499
|
+
// 两个整组开关
|
|
1500
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px', marginTop: '4px' } },
|
|
1501
|
+
h('label', { style: { display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px', opacity: editing ? 1 : 0.85 } },
|
|
1502
|
+
h('input', { type: 'checkbox', disabled: !editing, checked: draft.pdEnabled, onChange: (e) => setDraft({ ...draft, pdEnabled: e.target.checked }) }),
|
|
1503
|
+
h('span', null, M('插件数据(自动枚举本机各插件目录)', 'Plugin data (auto-scan each plugin folder)'))),
|
|
1504
|
+
h('label', { style: { display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px', opacity: editing ? 1 : 0.85 } },
|
|
1505
|
+
h('input', { type: 'checkbox', disabled: !editing, checked: draft.exEnabled, onChange: (e) => setDraft({ ...draft, exEnabled: e.target.checked }) }),
|
|
1506
|
+
h('span', null, M('额外路径(下面自己加的路径)', 'Extra paths (added below)'))),
|
|
1507
|
+
),
|
|
1508
|
+
|
|
1509
|
+
// 单文件上限
|
|
1510
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap', marginTop: '6px' } },
|
|
1511
|
+
h('span', { style: { fontSize: '12px' } }, M('单文件上限', 'Max file size')),
|
|
1512
|
+
h('input', {
|
|
1513
|
+
type: 'number', min: 1, max: hardMB, disabled: !editing, value: draft.maxMB,
|
|
1514
|
+
onChange: (e) => setDraft({ ...draft, maxMB: e.target.value }),
|
|
1515
|
+
style: { width: '90px', padding: '3px 6px', fontSize: '12px' },
|
|
1516
|
+
}),
|
|
1517
|
+
h('span', { style: { fontSize: '12px' } }, 'MB'),
|
|
1518
|
+
h('span', { style: S.footnote }, M(`超过就跳过;上限 ${hardMB}MB(GitHub 单文件硬限,调大也按它算)`, `Bigger files are skipped; capped at ${hardMB}MB (GitHub single-file limit)`)),
|
|
1519
|
+
),
|
|
1520
|
+
|
|
1521
|
+
// 排除名单
|
|
1522
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', marginTop: '6px', flexWrap: 'wrap' } },
|
|
1523
|
+
h('div', { style: { fontSize: '12px' } }, M('排除名单(通配,一行一条)', 'Exclusions (wildcards, one per line)')),
|
|
1524
|
+
h('button', { type: 'button', style: S.btn, disabled: !editing || busy, onClick: resetExclude }, M('恢复默认', 'Restore defaults')),
|
|
1525
|
+
),
|
|
1526
|
+
h('textarea', {
|
|
1527
|
+
value: draft.excludeText, spellCheck: false, readOnly: !editing,
|
|
1528
|
+
onChange: (e) => setDraft({ ...draft, excludeText: e.target.value }),
|
|
1529
|
+
style: {
|
|
1530
|
+
width: '100%', boxSizing: 'border-box', minHeight: '96px', fontFamily: 'ui-monospace, Consolas, monospace',
|
|
1531
|
+
fontSize: '12px', lineHeight: '16px',
|
|
1532
|
+
background: editing ? undefined : 'var(--dsw-alias-bg-secondary, #f7f7f8)',
|
|
1533
|
+
},
|
|
1534
|
+
}),
|
|
1535
|
+
|
|
1536
|
+
// 额外路径
|
|
1537
|
+
h('div', { style: { fontSize: '12px', marginTop: '8px' } }, M('额外路径(绝对路径,目录或单个文件)', 'Extra paths (absolute, folder or single file)')),
|
|
1538
|
+
draft.paths.length === 0
|
|
1539
|
+
? h('div', { style: S.footnote }, M('还没有加路径:只想同步插件目录就不用加', 'None yet — skip this if plugin folders are enough'))
|
|
1540
|
+
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
|
|
1541
|
+
draft.paths.map((p, i) => h('div', { key: `${p.id}-${i}`, style: { display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px' } },
|
|
1542
|
+
h('span', { style: { minWidth: '90px' } }, p.label || p.id),
|
|
1543
|
+
h('span', { style: { flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', color: 'var(--dsw-alias-label-secondary)' } }, p.src),
|
|
1544
|
+
editing ? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => removePath(i) }, M('移除', 'Remove')) : null,
|
|
1545
|
+
))),
|
|
1546
|
+
editing
|
|
1547
|
+
? h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', flexWrap: 'wrap', marginTop: '4px' } },
|
|
1548
|
+
h('input', {
|
|
1549
|
+
type: 'text', value: newLabel, placeholder: M('名字(可留空)', 'Name (optional)'),
|
|
1550
|
+
onChange: (e) => setNewLabel(e.target.value),
|
|
1551
|
+
style: { width: '140px', padding: '3px 6px', fontSize: '12px' },
|
|
1552
|
+
}),
|
|
1553
|
+
h('input', {
|
|
1554
|
+
type: 'text', value: newPath, placeholder: M('C:\\Users\\你\\某个目录 或某个文件', 'C:\\Users\\you\\some-folder'),
|
|
1555
|
+
onChange: (e) => setNewPath(e.target.value),
|
|
1556
|
+
style: { flex: 1, minWidth: '200px', padding: '3px 6px', fontSize: '12px' },
|
|
1557
|
+
}),
|
|
1558
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: addPath }, M('添加', 'Add')),
|
|
1559
|
+
)
|
|
1560
|
+
: h('div', { style: S.footnote }, M('点「修改」后这里会出现输入框,可直接加路径', 'Click Edit and an input appears here to add a path')),
|
|
1561
|
+
)
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
function ScopeCard() {
|
|
1565
|
+
const [state, setState] = react.useState(null)
|
|
1566
|
+
const [open, setOpen] = react.useState({})
|
|
1567
|
+
const [busy, setBusy] = react.useState(false)
|
|
1568
|
+
const [editing, setEditing] = react.useState(false)
|
|
1569
|
+
const [msg, setMsg] = react.useState('')
|
|
1570
|
+
const [err, setErr] = react.useState('')
|
|
1571
|
+
|
|
1572
|
+
const load = async () => {
|
|
1573
|
+
try {
|
|
1574
|
+
const r = await callScope()
|
|
1575
|
+
setState({ deleteCloud: r.deleteCloud === true, path: r.path || '', groups: r.groups || [] })
|
|
1576
|
+
setErr('')
|
|
1577
|
+
} catch (e) {
|
|
1578
|
+
setErr(String((e && e.message) || e))
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
react.useEffect(() => { load() }, [])
|
|
1582
|
+
|
|
1583
|
+
const save = async (next) => {
|
|
1584
|
+
setBusy(true); setErr(''); setMsg('')
|
|
1585
|
+
try {
|
|
1586
|
+
const groups = {}
|
|
1587
|
+
for (const g of next.groups || []) {
|
|
1588
|
+
const excluded = (g.items || []).filter((i) => i.enabled === false).map((i) => i.id)
|
|
1589
|
+
groups[g.id] = { enabled: g.enabled !== false, excluded }
|
|
1590
|
+
}
|
|
1591
|
+
await callScope({ deleteCloud: next.deleteCloud === true, groups })
|
|
1592
|
+
setState(next)
|
|
1593
|
+
setEditing(false)
|
|
1594
|
+
const offGroups = (next.groups || []).filter((g) => g.enabled === false).length
|
|
1595
|
+
const offItems = (next.groups || []).reduce((n, g) => n + (g.items || []).filter((i) => i.enabled === false).length, 0)
|
|
1596
|
+
setMsg(offGroups || offItems
|
|
1597
|
+
? M(`已保存:整组不同步 ${offGroups} 组、组内排除 ${offItems} 项`, `Saved: ${offGroups} group(s) off, ${offItems} item(s) excluded`)
|
|
1598
|
+
: M('已保存:云端同步全部内容', 'Saved: everything is synced'))
|
|
1599
|
+
} catch (e) {
|
|
1600
|
+
setErr(String((e && e.message) || e))
|
|
1601
|
+
} finally { setBusy(false) }
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// 勾选只改本次编辑的草稿,不落盘;「保存」才发请求,「取消」直接 reload 丢弃
|
|
1605
|
+
const toggleGroup = (id) => {
|
|
1606
|
+
if (!state || !editing) return
|
|
1607
|
+
const g0 = state.groups.find((x) => x.id === id)
|
|
1608
|
+
if (g0 && g0.required === true) return // 必需组钉死,点也点不动
|
|
1609
|
+
setState({ ...state, groups: state.groups.map((g) => (g.id === id ? { ...g, enabled: g.enabled === false } : g)) })
|
|
1610
|
+
setMsg('')
|
|
1611
|
+
}
|
|
1612
|
+
const toggleItem = (gid, iid) => {
|
|
1613
|
+
if (!state || !editing) return
|
|
1614
|
+
setState({
|
|
1615
|
+
...state,
|
|
1616
|
+
groups: state.groups.map((g) => (g.id === gid
|
|
1617
|
+
? { ...g, items: g.items.map((i) => (i.id === iid ? { ...i, enabled: i.enabled === false } : i)) }
|
|
1618
|
+
: g)),
|
|
1619
|
+
})
|
|
1620
|
+
setMsg('')
|
|
1621
|
+
}
|
|
1622
|
+
const toggleDeleteCloud = () => {
|
|
1623
|
+
if (!state || !editing) return
|
|
1624
|
+
setState({ ...state, deleteCloud: state.deleteCloud !== true })
|
|
1625
|
+
setMsg('')
|
|
1626
|
+
}
|
|
1627
|
+
const cancelEdit = () => { setMsg(''); setErr(''); setEditing(false); load() }
|
|
1628
|
+
|
|
1629
|
+
if (!state) {
|
|
1630
|
+
return h('div', { style: S.card },
|
|
1631
|
+
h('div', { style: S.cardTitle }, M('同步内容', 'Sync content')),
|
|
1632
|
+
h('div', { style: S.hint }, err ? M(`读取失败:${err}`, `Read failed: ${err}`) : M('正在读取同步范围…', 'Loading sync scope…')),
|
|
1633
|
+
)
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
const total = state.groups.reduce((n, g) => n + (g.items || []).length, 0)
|
|
1637
|
+
const checked = state.groups.reduce((n, g) => (g.enabled === false ? n : n + (g.items || []).filter((i) => i.enabled !== false).length), 0)
|
|
1638
|
+
|
|
1639
|
+
return h('div', { style: S.card },
|
|
1640
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'wrap' } },
|
|
1641
|
+
h('div', { style: S.cardTitle }, M('同步内容', 'Sync content')),
|
|
1642
|
+
h('div', { style: { ...S.hint, flex: 1, minWidth: '160px' } },
|
|
1643
|
+
editing
|
|
1644
|
+
? M(`改完点「保存」才生效(当前 ${checked}/${total} 项参与同步)`, `Click Save to apply (${checked}/${total} items currently active)`)
|
|
1645
|
+
: M(`只读:点「修改」后才能取消勾选(当前 ${checked}/${total} 项参与同步)`, `Read-only: click Edit to change the selection (${checked}/${total} items currently active)`)),
|
|
1646
|
+
editing
|
|
1647
|
+
? h('button', { type: 'button', style: S.btnPrimary, disabled: busy, onClick: () => save(state) }, busy ? M('保存中…', 'Saving…') : M('保存', 'Save'))
|
|
1648
|
+
: null,
|
|
1649
|
+
editing
|
|
1650
|
+
? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel'))
|
|
1651
|
+
: null,
|
|
1652
|
+
editing
|
|
1653
|
+
? null
|
|
1654
|
+
: h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => { setMsg(''); setErr(''); setEditing(true) } }, M('修改', 'Edit')),
|
|
1655
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('刷新', 'Refresh')),
|
|
1656
|
+
),
|
|
1657
|
+
h('label', { style: { display: 'flex', gap: '8px', alignItems: 'flex-start', cursor: editing ? 'pointer' : 'default' } },
|
|
1658
|
+
h('input', {
|
|
1659
|
+
type: 'checkbox', checked: state.deleteCloud === true, disabled: busy || !editing,
|
|
1660
|
+
onChange: toggleDeleteCloud, style: { marginTop: '2px', flexShrink: 0 },
|
|
1661
|
+
}),
|
|
1662
|
+
h('div', { style: { minWidth: 0 } },
|
|
1663
|
+
h('div', { style: { fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-primary)' } },
|
|
1664
|
+
M('取消勾选时顺手删掉云端副本', 'Also delete the cloud copy when unchecked')),
|
|
1665
|
+
h('div', { style: S.footnote },
|
|
1666
|
+
M(
|
|
1667
|
+
'默认关闭:云端保留,重新勾上即继续同步;打开后删除不可恢复。',
|
|
1668
|
+
'Off by default: the cloud copy is kept and re-checking resumes it; when on, deletion is permanent.',
|
|
1669
|
+
)),
|
|
1670
|
+
),
|
|
1671
|
+
),
|
|
1672
|
+
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', maxHeight: '340px', overflowY: 'auto' } },
|
|
1673
|
+
state.groups.map((g) => {
|
|
1674
|
+
const items = g.items || []
|
|
1675
|
+
const excluded = items.filter((i) => i.enabled === false).length
|
|
1676
|
+
const expanded = open[g.id] === true
|
|
1677
|
+
const groupOn = g.enabled !== false
|
|
1678
|
+
const canExpand = items.length > 0
|
|
1679
|
+
return h('div', {
|
|
1680
|
+
style: { borderTop: '1px solid var(--dsw-alias-border-l1)', paddingTop: '6px', paddingBottom: '2px' },
|
|
1681
|
+
},
|
|
1682
|
+
// 整行可点:点一下展开明细,再点收起(不再单独放「明细」按钮)
|
|
1683
|
+
h('div', {
|
|
1684
|
+
style: { display: 'flex', alignItems: 'center', gap: '8px', cursor: canExpand ? 'pointer' : 'default' },
|
|
1685
|
+
onClick: canExpand ? () => setOpen({ ...open, [g.id]: !expanded }) : undefined,
|
|
1686
|
+
},
|
|
1687
|
+
canExpand
|
|
1688
|
+
? h('span', {
|
|
1689
|
+
style: { flexShrink: 0, width: '10px', fontSize: '11px', color: 'var(--dsw-alias-label-tertiary)' },
|
|
1690
|
+
}, expanded ? '▾' : '▸')
|
|
1691
|
+
: h('span', { style: { flexShrink: 0, width: '10px' } }),
|
|
1692
|
+
h('input', {
|
|
1693
|
+
type: 'checkbox', checked: groupOn, disabled: busy || !editing || g.required === true,
|
|
1694
|
+
title: g.required === true
|
|
1695
|
+
? M('必需内容:取消会让另一台机器拉取时直接报错', 'Required: unchecking it makes the other machine fail on pull')
|
|
1696
|
+
: (editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first')),
|
|
1697
|
+
onClick: (e) => e.stopPropagation(), // 勾选别当成"点行展开"
|
|
1698
|
+
onChange: () => toggleGroup(g.id), style: { flexShrink: 0 },
|
|
1699
|
+
}),
|
|
1700
|
+
h('div', { style: { flex: 1, minWidth: 0, display: 'flex', alignItems: 'baseline', gap: '6px', flexWrap: 'wrap' } },
|
|
1701
|
+
h('div', {
|
|
1702
|
+
style: {
|
|
1703
|
+
fontSize: '12.5px', lineHeight: '18px',
|
|
1704
|
+
color: groupOn ? 'var(--dsw-alias-label-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
1705
|
+
textDecoration: groupOn ? 'none' : 'line-through',
|
|
1706
|
+
},
|
|
1707
|
+
}, g.required === true ? `${g.title} · ${M('必需', 'required')}` : g.title),
|
|
1708
|
+
g.desc
|
|
1709
|
+
? h('div', { style: S.footnote },
|
|
1710
|
+
g.required === true
|
|
1711
|
+
? `${g.desc} · ${M('必需内容:取消后拉取会直接报错', 'Required content: unchecking makes pull fail')}`
|
|
1712
|
+
: g.desc)
|
|
1713
|
+
: null,
|
|
1714
|
+
),
|
|
1715
|
+
h('span', { style: S.hint }, items.length ? `${items.length - excluded}/${items.length}` : M('无明细', 'no items')),
|
|
1716
|
+
),
|
|
1717
|
+
expanded
|
|
1718
|
+
? h('div', {
|
|
1719
|
+
style: {
|
|
1720
|
+
display: 'flex', flexDirection: 'column', gap: '2px',
|
|
1721
|
+
marginLeft: '26px', marginTop: '4px', maxHeight: '180px', overflowY: 'auto',
|
|
1722
|
+
},
|
|
1723
|
+
},
|
|
1724
|
+
items.map((i) => h('label', {
|
|
1725
|
+
style: {
|
|
1726
|
+
display: 'flex', gap: '8px', alignItems: 'center', fontSize: '12px',
|
|
1727
|
+
cursor: editing ? 'pointer' : 'default', opacity: groupOn ? 1 : 0.6,
|
|
1728
|
+
},
|
|
1729
|
+
},
|
|
1730
|
+
h('input', {
|
|
1731
|
+
type: 'checkbox', checked: i.enabled !== false, disabled: busy || !editing,
|
|
1732
|
+
title: editing ? '' : M('只读:先点「修改」', 'Read-only: click Edit first'),
|
|
1733
|
+
onChange: () => toggleItem(g.id, i.id), style: { flexShrink: 0 },
|
|
1734
|
+
}),
|
|
1735
|
+
h('span', { style: { wordBreak: 'break-all' } }, i.label),
|
|
1736
|
+
)),
|
|
1737
|
+
)
|
|
1738
|
+
: null,
|
|
1739
|
+
)
|
|
1740
|
+
}),
|
|
1741
|
+
),
|
|
1742
|
+
msg ? h('div', { style: S.footnote }, msg) : null,
|
|
1743
|
+
err ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${err}`, `Save failed: ${err}`)) : null,
|
|
1744
|
+
h('div', { style: S.footnote },
|
|
1745
|
+
M(
|
|
1746
|
+
`勾选记在本机 ${state.path || 'config-sync-scope.json'}(不进仓库),推送与拉取共用。`,
|
|
1747
|
+
`Choices live on this machine in ${state.path || 'config-sync-scope.json'} (never committed); push and pull share them.`,
|
|
1748
|
+
)),
|
|
1749
|
+
)
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
/**
|
|
1753
|
+
* 自动同步卡:两个开关(默认关)+ 云端一致性状态。
|
|
1754
|
+
* 打开后:启动延迟检查一次;云端更新 → 系统确认框 → 退出后拉取(按设置自动重启);
|
|
1755
|
+
* 本机领先 → 排队等 DSH 退出后推送。插件不自己退进程后干活,原因见宿主注释。
|
|
1756
|
+
*/
|
|
1757
|
+
function AutoCard(props) {
|
|
1758
|
+
const auto = (props.data && props.data.auto) || {}
|
|
1759
|
+
const repo = (props.data && props.data.repo) || {}
|
|
1760
|
+
// 门禁由后端算(repo.pushAllowed / pullAllowed);这里只管有没有路径、按钮要不要强调
|
|
1761
|
+
const pushAllowed = repo.pushAllowed === true
|
|
1762
|
+
const canPullNow = repo.pullAllowed === true
|
|
1763
|
+
// 两边都空:这次推送就是「初始化推送」,按钮换个说法,别让人以为在推一个已有仓库
|
|
1764
|
+
const initMode = repo.mode === 'await-init'
|
|
1765
|
+
const drift = auto.drift || null
|
|
1766
|
+
const [busy, setBusy] = react.useState('')
|
|
1767
|
+
const [err, setErr] = react.useState('')
|
|
1768
|
+
const [msg, setMsg] = react.useState('')
|
|
1769
|
+
|
|
1770
|
+
const save = async (patch) => {
|
|
1771
|
+
setBusy('save'); setErr(''); setMsg('')
|
|
1772
|
+
try {
|
|
1773
|
+
await callSettings(patch)
|
|
1774
|
+
setMsg(M('已保存', 'Saved'))
|
|
1775
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
1776
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy('') }
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
const act = async (action, extra) => {
|
|
1780
|
+
setBusy(action); setErr(''); setMsg('')
|
|
1781
|
+
try {
|
|
1782
|
+
const res = await fetch('/config-sync/auto', {
|
|
1783
|
+
method: 'POST', cache: 'no-store', credentials: 'same-origin',
|
|
1784
|
+
headers: jsonHeaders,
|
|
1785
|
+
body: JSON.stringify({ action, ...(extra || {}) }),
|
|
1786
|
+
})
|
|
1787
|
+
const text = await res.text()
|
|
1788
|
+
const body = text ? JSON.parse(text) : null
|
|
1789
|
+
if (!res.ok || !body || body.ok !== true) throw new Error((body && body.error) || `${res.status}`)
|
|
1790
|
+
if (action === 'check') {
|
|
1791
|
+
const d = body.drift
|
|
1792
|
+
setMsg(d
|
|
1793
|
+
? M(`云端:落后 ${d.behind} 个提交,领先 ${d.ahead} 个提交`, `Cloud: ${d.behind} commit(s) behind, ${d.ahead} ahead`)
|
|
1794
|
+
: (body.error || M('读不到远端', 'Cannot read the remote')))
|
|
1795
|
+
} else {
|
|
1796
|
+
setMsg(body.closeRequested
|
|
1797
|
+
? M('已排队:客户端马上关闭,退出后执行;拉取完成后按设置自动重开', 'Queued: the client closes now and the sync runs after exit; it relaunches per your settings when pulling finishes')
|
|
1798
|
+
: M('已排队:退出 DSH 后自动执行', 'Queued: runs automatically after DSH exits'))
|
|
1799
|
+
}
|
|
1800
|
+
if (typeof props.onSaved === 'function') props.onSaved()
|
|
1801
|
+
} catch (e) { setErr(String((e && e.message) || e)) } finally { setBusy('') }
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
const sw = (patchKey, stateKey, label, hintText) => {
|
|
1805
|
+
// 设置接口的字段名是 autoPull / autoPush,体检返回的是 auto.pull / auto.push,别拿混。
|
|
1806
|
+
const on = auto[stateKey] === true
|
|
1807
|
+
return h('div', {
|
|
1808
|
+
style: {
|
|
1809
|
+
display: 'flex', flexDirection: 'column', gap: '2px', padding: '7px 0',
|
|
1810
|
+
borderTop: '1px solid var(--dsw-alias-border-l1)',
|
|
1811
|
+
},
|
|
1812
|
+
},
|
|
1813
|
+
h('label', {
|
|
1814
|
+
style: {
|
|
1815
|
+
display: 'flex', alignItems: 'center', gap: '8px', cursor: busy ? 'default' : 'pointer',
|
|
1816
|
+
fontSize: '12.5px', lineHeight: '18px', color: 'var(--dsw-alias-label-primary)',
|
|
1817
|
+
},
|
|
1818
|
+
},
|
|
1819
|
+
h('input', {
|
|
1820
|
+
type: 'checkbox', checked: on, disabled: Boolean(busy),
|
|
1821
|
+
onChange: (e) => save({ [patchKey]: e.target.checked }),
|
|
1822
|
+
}),
|
|
1823
|
+
h('span', null, label),
|
|
1824
|
+
h('span', {
|
|
1825
|
+
style: {
|
|
1826
|
+
...S.footnote, marginLeft: 'auto',
|
|
1827
|
+
color: on ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-label-tertiary)',
|
|
1828
|
+
},
|
|
1829
|
+
}, on ? M('已开启', 'On') : M('已关闭', 'Off')),
|
|
1830
|
+
),
|
|
1831
|
+
h('div', { style: { ...S.footnote, paddingLeft: '22px' } }, hintText),
|
|
1832
|
+
)
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
const pending = auto.pending
|
|
1836
|
+
// 后台调度拿不到请求语言,宿主把原因中英各存一份,这里按当前界面语言挑
|
|
1837
|
+
const pendingReason = pending ? (langIsZh() ? (pending.reasonZh || pending.reason) : (pending.reasonEn || pending.reason)) : ''
|
|
1838
|
+
return h('div', { style: S.card },
|
|
1839
|
+
h('div', { style: S.cardHead },
|
|
1840
|
+
h('div', { style: S.cardTitle }, M('自动同步', 'Auto sync')),
|
|
1841
|
+
h('div', { style: { ...S.footnote, flex: 1 } }, M('默认关闭;不开就是纯手动', 'Off by default — leaving them off keeps it manual')),
|
|
1842
|
+
),
|
|
1843
|
+
sw('autoPull', 'pull', M('启动时自动拉取', 'Pull on startup'),
|
|
1844
|
+
M('云端有新提交 → 弹确认 → 退出后拉取,失败自动还原上次配置',
|
|
1845
|
+
'New commits upstream → confirm → pull after exit; failures roll back to the previous config')),
|
|
1846
|
+
sw('autoPush', 'push', M('退出时自动推送', 'Push on exit'),
|
|
1847
|
+
M('有改动 / 新资料 / 未推送提交 → 每 2 分钟复查,退出后推送',
|
|
1848
|
+
'Changes / new data / unpushed commits → re-checked every 2 min, pushed after exit')),
|
|
1849
|
+
pending
|
|
1850
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1851
|
+
M(
|
|
1852
|
+
`已排队:退出后${pending.mode === 'pull' ? '拉取' + (pending.restart ? '并重启客户端' : '') : '推送'}`
|
|
1853
|
+
+ `(${new Date(pending.at).toLocaleTimeString(localeNow(), { hour12: false })}`
|
|
1854
|
+
+ `${pendingReason ? M(`,原因:${pendingReason}`, `, reason: ${pendingReason}`) : ''})`,
|
|
1855
|
+
`Queued: ${pending.mode === 'pull' ? 'pull' + (pending.restart ? ' and relaunch the client' : '') : 'push'} after exit `
|
|
1856
|
+
+ `(${new Date(pending.at).toLocaleTimeString(localeNow(), { hour12: false })}`
|
|
1857
|
+
+ `${pendingReason ? `, reason: ${pendingReason}` : ''})`,
|
|
1858
|
+
))
|
|
1859
|
+
: null,
|
|
1860
|
+
!auto.script
|
|
1861
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1862
|
+
M('插件与仓库里都找不到 post-exit.ps1:自动同步排不了队,重装一次插件即可(新包自带 runtime)',
|
|
1863
|
+
'post-exit.ps1 is missing from both the plugin and the repo, so auto sync cannot queue — reinstall the plugin (the current package ships runtime/)'))
|
|
1864
|
+
: null,
|
|
1865
|
+
h('div', { style: S.actions },
|
|
1866
|
+
h('button', {
|
|
1867
|
+
type: 'button',
|
|
1868
|
+
style: canPullNow ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
|
|
1869
|
+
disabled: Boolean(busy) || !canPullNow,
|
|
1870
|
+
title: canPullNow ? '' : M('云端还是空的:没有内容可拉,先「初始化推送」', 'The cloud is still empty — nothing to pull, initialize push first'),
|
|
1871
|
+
onClick: () => act('pull-now'),
|
|
1872
|
+
}, M('立即拉取(会关闭 DSH)', 'Pull now (closes DSH)')),
|
|
1873
|
+
h('button', {
|
|
1874
|
+
type: 'button',
|
|
1875
|
+
style: pushAllowed ? S.btnPrimary : { ...S.btnPrimary, opacity: 0.5, cursor: 'not-allowed' },
|
|
1876
|
+
disabled: Boolean(busy) || !pushAllowed,
|
|
1877
|
+
title: pushAllowed ? '' : M('云端已有内容:本机还是空的,先拉取', 'The cloud already has content — pull first'),
|
|
1878
|
+
onClick: () => act('push-now'),
|
|
1879
|
+
}, initMode
|
|
1880
|
+
? M('初始化推送(会关闭 DSH)', 'Initialize push (closes DSH)')
|
|
1881
|
+
: M('立即推送(会关闭 DSH)', 'Push now (closes DSH)')),
|
|
1882
|
+
pending ? h('button', { type: 'button', style: S.btn, disabled: Boolean(busy), onClick: () => act('cancel') }, M('取消排队', 'Cancel queue')) : null,
|
|
1883
|
+
),
|
|
1884
|
+
initMode
|
|
1885
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1886
|
+
M(
|
|
1887
|
+
'本机仓库和云端仓库都还是空的:点「初始化推送」会把本机配置当作仓库的初始内容推上去(自动 git init + 写仓库骨架 + capture + 提交 + 推送)。这时没有东西可拉,拉取按钮是灰的。',
|
|
1888
|
+
'Both the local repo and the cloud are empty: Initialize push uploads this machine\'s config as the repo\'s initial content (git init + repo skeleton + capture + commit + push). There is nothing to pull yet, so Pull stays disabled.',
|
|
1889
|
+
))
|
|
1890
|
+
: null,
|
|
1891
|
+
(!pushAllowed || !canPullNow)
|
|
1892
|
+
? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1893
|
+
!pushAllowed && !initMode
|
|
1894
|
+
? (repo.empty || repo.remoteEmpty === false
|
|
1895
|
+
? M(
|
|
1896
|
+
'本机仓库还是空目录、云端已有内容:先「立即拉取」把云端仓库拉下来,之后才能推送。',
|
|
1897
|
+
'The local repo is empty while the cloud has content: run Pull first; push unlocks after that.',
|
|
1898
|
+
)
|
|
1899
|
+
: M(
|
|
1900
|
+
'本机仓库不可用:先在「本机仓库」卡里设好路径,才能推送。',
|
|
1901
|
+
'The local repo is unusable: set the path in the Local repo card before pushing.',
|
|
1902
|
+
))
|
|
1903
|
+
: null)
|
|
1904
|
+
: null,
|
|
1905
|
+
msg ? h('div', { style: S.hint }, msg) : null,
|
|
1906
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, err) : null,
|
|
1907
|
+
noticesBlock(auto.lastResult && auto.lastResult.notices),
|
|
1908
|
+
)
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* 未同步文件常驻区块:只在上次同步确实有文件没同步成时出现。
|
|
1913
|
+
* 用常驻而不是 toast,是因为「跳过一个大文件」不会造成失败提示,
|
|
1914
|
+
* 只弹一次 5 秒等于没告诉人;面板这块一直挂着,直到下一次同步清掉。
|
|
1915
|
+
*/
|
|
1916
|
+
function noticesBlock(notices) {
|
|
1917
|
+
if (!notices || !notices.total) return null
|
|
1918
|
+
const kindLabel = (k) => ({
|
|
1919
|
+
'too-large': M('超过单文件上限', 'Over size cap'),
|
|
1920
|
+
history: M('历史里的超限文件', 'Oversized in history'),
|
|
1921
|
+
failed: M('失败', 'Failed'),
|
|
1922
|
+
skipped: M('跳过', 'Skipped'),
|
|
1923
|
+
}[k] || k)
|
|
1924
|
+
const rows = (notices.items || []).map((it, i) => h('div', {
|
|
1925
|
+
key: `notice-${i}`,
|
|
1926
|
+
style: { display: 'flex', gap: '6px', alignItems: 'baseline', fontSize: '11.5px', lineHeight: '18px' },
|
|
1927
|
+
},
|
|
1928
|
+
h('span', { style: { color: 'var(--dsw-alias-state-warn-primary)', whiteSpace: 'nowrap' } }, `[${kindLabel(it.kind)}]`),
|
|
1929
|
+
h('span', { style: { wordBreak: 'break-all', color: 'var(--dsw-alias-label-primary)' } }, it.path),
|
|
1930
|
+
it.bytes ? h('span', { style: { color: 'var(--dsw-alias-label-tertiary)', whiteSpace: 'nowrap' } }, `${(it.bytes / 1048576).toFixed(1)} MB`) : null,
|
|
1931
|
+
))
|
|
1932
|
+
const parts = []
|
|
1933
|
+
if (notices.byKind) {
|
|
1934
|
+
if (notices.byKind['too-large']) parts.push(M(`${notices.byKind['too-large']} 个超过单文件上限`, `${notices.byKind['too-large']} over the size cap`))
|
|
1935
|
+
if (notices.byKind.history) parts.push(M(`${notices.byKind.history} 个在历史提交里`, `${notices.byKind.history} already in history`))
|
|
1936
|
+
if (notices.byKind.failed) parts.push(M(`${notices.byKind.failed} 个失败`, `${notices.byKind.failed} failed`))
|
|
1937
|
+
if (notices.byKind.skipped) parts.push(M(`${notices.byKind.skipped} 个被跳过`, `${notices.byKind.skipped} skipped`))
|
|
1938
|
+
}
|
|
1939
|
+
return h('div', {
|
|
1940
|
+
style: {
|
|
1941
|
+
marginTop: '6px', padding: '8px 10px', borderRadius: '6px',
|
|
1942
|
+
border: '1px solid var(--dsw-alias-state-warn-primary)',
|
|
1943
|
+
background: 'color-mix(in srgb, var(--dsw-alias-state-warn-primary) 8%, transparent)',
|
|
1944
|
+
},
|
|
1945
|
+
},
|
|
1946
|
+
h('div', { style: { fontSize: '12px', fontWeight: 600, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1947
|
+
M(`上次同步有 ${notices.total} 个文件没同步${parts.length ? `(${parts.join('、')})` : ''}`, `Last sync left ${notices.total} file(s) unsynced${parts.length ? ` (${parts.join(', ')})` : ''}`)),
|
|
1948
|
+
h('div', { style: { ...S.footnote, marginTop: '3px' } },
|
|
1949
|
+
M('这些文件仍在本机磁盘上,只是没进仓库;下次同步会自动复查。',
|
|
1950
|
+
'They are still on this machine, just not in the repo; the next sync re-checks them.')),
|
|
1951
|
+
h('div', { style: { marginTop: '4px' } }, rows),
|
|
1952
|
+
notices.truncated
|
|
1953
|
+
? h('div', { style: { ...S.footnote, marginTop: '3px' } },
|
|
1954
|
+
M(`只列前 ${rows.length} 个,完整清单:~/.dsh/sync-notices.json`,
|
|
1955
|
+
`Showing the first ${rows.length}; full list: ~/.dsh/sync-notices.json`))
|
|
1956
|
+
: null,
|
|
1957
|
+
notices.byKind && notices.byKind.history
|
|
1958
|
+
? h('div', { style: { ...S.footnote, marginTop: '4px', color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
1959
|
+
M('历史提交里的超限文件会让整次推送被远端拒收:换一份新的空仓库(本卡「初始化推送」),或用 git filter-repo 清史。',
|
|
1960
|
+
'Oversized files already in history make the whole push get rejected: point at a fresh empty repo (Initialize push here), or rewrite history with git filter-repo.'))
|
|
1961
|
+
: null,
|
|
1962
|
+
)
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
function ConfigSyncPanel() {
|
|
1966
|
+
const { data, err, busy, made, refresh, prepare } = useSync()
|
|
1967
|
+
const [note, setNote] = react.useState('')
|
|
1968
|
+
const [checking, setChecking] = react.useState(false)
|
|
1969
|
+
const [toast, setToast] = react.useState('')
|
|
1970
|
+
const [upd, setUpd] = react.useState(null)
|
|
1971
|
+
const [updBusy, setUpdBusy] = react.useState(false)
|
|
1972
|
+
// 「插件更新」卡里的配置编辑态:清单地址 + 只读令牌都放这一张卡,不散到云端仓库那去
|
|
1973
|
+
const [updEdit, setUpdEdit] = react.useState(false)
|
|
1974
|
+
const [updManifest, setUpdManifest] = react.useState('')
|
|
1975
|
+
const [updToken, setUpdToken] = react.useState('')
|
|
1976
|
+
const [updMsg, setUpdMsg] = react.useState('')
|
|
1977
|
+
const [updErr, setUpdErr] = react.useState('')
|
|
1978
|
+
// 「本机路径」平时不占版面:只在标题行按钮被点开时才渲染;按钮本身在
|
|
1979
|
+
// 「根外路径 / 被覆盖的配置」两类告警下变橙并带数字(待确认路径不算告警)。
|
|
1980
|
+
const [showRoots, setShowRoots] = react.useState(false)
|
|
1981
|
+
// 定时器放 ref 里:数据每刷新一次 effect 就会重跑,若在 effect 里 return 清理函数,
|
|
1982
|
+
// 会把还没到点的"5 秒后消失"定时器一起清掉,提示就一直挂在屏幕上。
|
|
1983
|
+
const toastTimer = react.useRef(null)
|
|
1984
|
+
const summary = summarize(data)
|
|
1985
|
+
// 门禁分三条:有路径就能生成还原脚本;拉取允许「真仓库 or 空目录」;推送只允许真仓库。
|
|
1986
|
+
// 空目录 = 新机器还没拉过,面板只放行「拉取」,推送按钮直接禁掉(后端也会再拦一次)。
|
|
1987
|
+
const hasRepoPath = Boolean(data && data.repo && data.repo.path)
|
|
1988
|
+
// 门禁统一由后端算好(repo.pullAllowed / pushAllowed),面板只做呈现:
|
|
1989
|
+
// 真仓库 → 推拉都行;本机空 + 云端有内容 → 只拉;本机空 + 云端也空 → 只「初始化推送」。
|
|
1990
|
+
const canPull = Boolean(data && data.repo && data.repo.pullAllowed === true)
|
|
1991
|
+
const canPush = Boolean(data && data.repo && data.repo.pushAllowed === true)
|
|
1992
|
+
// 云端仓库没配 = 推送/拉取禁用(还原只动本机快照,不拦)
|
|
1993
|
+
const noRemote = !data || !data.remote || !data.remote.configured
|
|
1994
|
+
|
|
1995
|
+
// 插件版本:打开面板查一次,之后每 30 分钟复查(服务端自己也缓存,网络开销≈0)。
|
|
1996
|
+
// 老版本机器就是靠这一条知道云端发了新版本。
|
|
1997
|
+
react.useEffect(() => {
|
|
1998
|
+
let alive = true
|
|
1999
|
+
const run = async () => {
|
|
2000
|
+
try {
|
|
2001
|
+
const u = await callUpdate()
|
|
2002
|
+
if (alive) setUpd(u)
|
|
2003
|
+
} catch (e) {
|
|
2004
|
+
if (alive) setUpd({ ok: false, error: String((e && e.message) || e), checkedAt: Date.now() })
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
run()
|
|
2008
|
+
const timer = setInterval(run, 30 * 60 * 1000)
|
|
2009
|
+
return () => { alive = false; clearInterval(timer) }
|
|
2010
|
+
}, [])
|
|
2011
|
+
|
|
2012
|
+
const showToast = (text) => {
|
|
2013
|
+
setToast(text)
|
|
2014
|
+
if (toastTimer.current) clearTimeout(toastTimer.current)
|
|
2015
|
+
toastTimer.current = setTimeout(() => setToast(''), 5000)
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
// 「下载更新」= 只下载,不动插件目录(宿主 action: prepare):
|
|
2019
|
+
// 下到 <DshHome>\update-staging\ 并校验 sha256。插件文件一个字节都没改,
|
|
2020
|
+
// 所以宿主不会重建插件树,当前这个页面不会跳走。
|
|
2021
|
+
const downloadUpdate = async () => {
|
|
2022
|
+
setUpdBusy(true)
|
|
2023
|
+
setUpdMsg(M('正在下载更新包(不改动插件目录,页面不会跳走)…', 'Downloading the package (the plugin directory stays untouched)…'))
|
|
2024
|
+
try {
|
|
2025
|
+
const r = await callUpdate({ action: 'prepare' })
|
|
2026
|
+
setUpd(r)
|
|
2027
|
+
const v = (r && r.prepared && r.prepared.version) || (r && r.remote && r.remote.version) || ''
|
|
2028
|
+
const kb = Math.round(((r && r.prepared && r.prepared.size) || 0) / 1024)
|
|
2029
|
+
setUpdMsg(M(`已下载 ${v}${kb ? `(${kb} KB)` : ''},点「重启并安装」生效`, `Downloaded ${v}${kb ? ` (${kb} KB)` : ''} — click "Restart & install" to apply`))
|
|
2030
|
+
showToast(M(`更新包已下载(${v}),点「重启并安装」生效`, `Update package downloaded (${v}) — click "Restart & install" to apply`))
|
|
2031
|
+
} catch (e) {
|
|
2032
|
+
const msg = String((e && e.message) || e)
|
|
2033
|
+
setUpdMsg(M('下载失败:', 'Download failed: ') + msg)
|
|
2034
|
+
showToast(M('下载失败:', 'Download failed: ') + msg)
|
|
2035
|
+
} finally {
|
|
2036
|
+
setUpdBusy(false)
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
// 「重启并安装」= 退出 DSH,退出后的脚本用已下好的本地包覆盖安装,然后自动拉起新版本。
|
|
2041
|
+
// 覆盖发生在 DSH 退出之后,所以不会打断你正在看的页面;全程只需这一次重启。
|
|
2042
|
+
const restartAndInstall = async () => {
|
|
2043
|
+
setUpdBusy(true)
|
|
2044
|
+
setUpdMsg(M('DSH 即将退出,退出后安装并自动重启…', 'DSH will exit; the package is installed afterwards and DSH relaunches…'))
|
|
2045
|
+
try {
|
|
2046
|
+
await callUpdate({ action: 'install-restart' })
|
|
2047
|
+
showToast(M('DSH 即将退出并自动安装、重启…', 'DSH will exit, install, and relaunch…'))
|
|
2048
|
+
} catch (e) {
|
|
2049
|
+
const msg = String((e && e.message) || e)
|
|
2050
|
+
setUpdMsg(M('安装失败:', 'Install failed: ') + msg)
|
|
2051
|
+
showToast(M('安装失败:', 'Install failed: ') + msg)
|
|
2052
|
+
setUpdBusy(false)
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
// 老路径遗留(install-live 装好了但没重启):只重启,不装东西
|
|
2057
|
+
const restartDsh = async () => {
|
|
2058
|
+
setUpdBusy(true)
|
|
2059
|
+
try {
|
|
2060
|
+
await callUpdate({ action: 'restart' })
|
|
2061
|
+
showToast(M('DSH 即将退出并自动重启…', 'DSH will exit and relaunch…'))
|
|
2062
|
+
} catch (e) {
|
|
2063
|
+
showToast(M('重启失败:', 'Restart failed: ') + String((e && e.message) || e))
|
|
2064
|
+
} finally {
|
|
2065
|
+
setUpdBusy(false)
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
const checkUpdateNow = async () => {
|
|
2070
|
+
setUpdBusy(true)
|
|
2071
|
+
try {
|
|
2072
|
+
setUpd(await callUpdate({ action: 'check' }))
|
|
2073
|
+
} catch (e) {
|
|
2074
|
+
setUpd({ ok: false, error: String((e && e.message) || e), checkedAt: Date.now() })
|
|
2075
|
+
} finally {
|
|
2076
|
+
setUpdBusy(false)
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
const startEditUpd = () => {
|
|
2081
|
+
const cfg = (upd && upd.config) || {}
|
|
2082
|
+
setUpdManifest(cfg.manifestUrlIsDefault ? '' : (cfg.manifestUrl || ''))
|
|
2083
|
+
setUpdToken('')
|
|
2084
|
+
setUpdErr('')
|
|
2085
|
+
setUpdMsg('')
|
|
2086
|
+
setUpdEdit(true)
|
|
2087
|
+
}
|
|
2088
|
+
const cancelEditUpd = () => { setUpdEdit(false); setUpdErr(''); setUpdToken('') }
|
|
2089
|
+
const saveUpdConfig = async () => {
|
|
2090
|
+
setUpdBusy(true); setUpdErr(''); setUpdMsg('')
|
|
2091
|
+
try {
|
|
2092
|
+
const payload = { updateManifestUrl: updManifest.trim() }
|
|
2093
|
+
if (updToken.trim()) payload.updateToken = updToken.trim()
|
|
2094
|
+
await callSettings(payload)
|
|
2095
|
+
setUpdEdit(false)
|
|
2096
|
+
setUpdToken('')
|
|
2097
|
+
setUpdMsg(M('已保存', 'Saved'))
|
|
2098
|
+
setUpd(await callUpdate({ action: 'check' }))
|
|
2099
|
+
} catch (e) {
|
|
2100
|
+
setUpdErr(String((e && e.message) || e))
|
|
2101
|
+
} finally { setUpdBusy(false) }
|
|
2102
|
+
}
|
|
2103
|
+
const clearUpdToken = async () => {
|
|
2104
|
+
setUpdBusy(true); setUpdErr(''); setUpdMsg('')
|
|
2105
|
+
try {
|
|
2106
|
+
await callSettings({ clearUpdateToken: true })
|
|
2107
|
+
setUpdMsg(M('已清除本机保存的更新令牌', 'Cleared the update token stored on this machine'))
|
|
2108
|
+
setUpd(await callUpdate({ action: 'check' }))
|
|
2109
|
+
} catch (e) {
|
|
2110
|
+
setUpdErr(String((e && e.message) || e))
|
|
2111
|
+
} finally { setUpdBusy(false) }
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// 打开面板就自动检查一次云端,之后每 2 分钟复查一次(只读,不改仓库、不动 profile)
|
|
2115
|
+
react.useEffect(() => {
|
|
2116
|
+
let alive = true
|
|
2117
|
+
const run = async () => {
|
|
2118
|
+
if (alive) setChecking(true)
|
|
2119
|
+
try {
|
|
2120
|
+
await callAuto({ action: 'check' })
|
|
2121
|
+
} catch { /* 检查失败不该挡住页面,状态行会显示失败原因 */ }
|
|
2122
|
+
if (alive) setChecking(false)
|
|
2123
|
+
if (alive && typeof refresh === 'function') refresh()
|
|
2124
|
+
}
|
|
2125
|
+
run()
|
|
2126
|
+
const timer = setInterval(run, 2 * 60 * 1000)
|
|
2127
|
+
return () => { alive = false; clearInterval(timer) }
|
|
2128
|
+
}, [])
|
|
2129
|
+
|
|
2130
|
+
// 上次「退出后自动同步」的结果:15 分钟内、且没弹过,就弹 5 秒提示。
|
|
2131
|
+
// 判据与「启动即弹」共用 takeFreshResult(同一个 localStorage 键,不会弹两次)。
|
|
2132
|
+
react.useEffect(() => {
|
|
2133
|
+
const text = takeFreshResult(data && data.auto && data.auto.lastResult)
|
|
2134
|
+
if (!text) return
|
|
2135
|
+
setToast(text)
|
|
2136
|
+
if (toastTimer.current) clearTimeout(toastTimer.current)
|
|
2137
|
+
toastTimer.current = setTimeout(() => setToast(''), 5000)
|
|
2138
|
+
}, [data])
|
|
2139
|
+
|
|
2140
|
+
// 云端一致性:和「一致 / 仓库与本机一致」同一个徽标样式,绿=一致、红=不一致,
|
|
2141
|
+
// 后面跟一句具体状态;全自动检查(挂载即查 + 每 2 分钟复查),不给手动按钮。
|
|
2142
|
+
const cloudLine = (() => {
|
|
2143
|
+
const auto = (data && data.auto) || {}
|
|
2144
|
+
const repo = (data && data.repo) || {}
|
|
2145
|
+
// 本机还没内容时后端会把 check 短路掉(不算错误),这里也先判一次,
|
|
2146
|
+
// 免得落到下面「lastCheckAt 有值但 lastCheckError 为空」的分支,被误显示成检查失败
|
|
2147
|
+
if (repo.empty || repo.phase === 'missing') {
|
|
2148
|
+
return repo.mode === 'await-init'
|
|
2149
|
+
? { kind: 'init', text: M('本机与云端都还没有内容:初始化推送一次就能和云端比对', 'Local repo and cloud are both empty — initialize push once to compare') }
|
|
2150
|
+
: { kind: 'pull', text: M('本机仓库还没有内容:拉取一次就能和云端比对', 'Local repo has no content yet — pull once to compare') }
|
|
2151
|
+
}
|
|
2152
|
+
if (auto.checking || checking) return { kind: 'idle', text: M('云端检查中…', 'Checking the cloud…') }
|
|
2153
|
+
const drift = auto.drift
|
|
2154
|
+
if (drift) {
|
|
2155
|
+
const same = drift.behind === 0 && drift.ahead === 0
|
|
2156
|
+
if (same) return { kind: 'ok', text: M('云端已同步到最新,无需拉取', 'Cloud is up to date — nothing to pull') }
|
|
2157
|
+
const parts = []
|
|
2158
|
+
if (drift.behind > 0) parts.push(M(`落后 ${drift.behind} 个提交`, `${drift.behind} commit(s) behind`))
|
|
2159
|
+
if (drift.ahead > 0) parts.push(M(`领先 ${drift.ahead} 个提交`, `${drift.ahead} ahead`))
|
|
2160
|
+
return { kind: 'error', text: M(`云端与本机不一致:${parts.join(' · ')}`, `Cloud differs from this machine: ${parts.join(' · ')}`) }
|
|
2161
|
+
}
|
|
2162
|
+
if (auto.lastCheckAt) {
|
|
2163
|
+
return { kind: 'error', text: M(`云端检查失败:${auto.lastCheckError || '读不到远端'}`, `Cloud check failed: ${auto.lastCheckError || 'cannot read the remote'}`) }
|
|
2164
|
+
}
|
|
2165
|
+
return { kind: 'idle', text: M('云端检查中…', 'Checking the cloud…') }
|
|
2166
|
+
})()
|
|
2167
|
+
|
|
2168
|
+
const cloudLabel = cloudLine.kind === 'ok' ? M('一致', 'In sync')
|
|
2169
|
+
: (cloudLine.kind === 'error' ? M('不一致', 'Out of sync')
|
|
2170
|
+
: (cloudLine.kind === 'pull' ? M('待拉取', 'To pull') : M('检查中', 'Checking')))
|
|
2171
|
+
|
|
2172
|
+
// 插件更新卡:老版本机器进来第一眼就能看到"有新版本 x.y.z"和更新按钮;
|
|
2173
|
+
// 更新相关的配置(清单地址、只读令牌)也收在这张卡里,别散到「云端仓库」去。
|
|
2174
|
+
const updCard = (() => {
|
|
2175
|
+
const u = upd || {}
|
|
2176
|
+
const cfg = u.config || {}
|
|
2177
|
+
const local = (u.local && u.local.version) || '…'
|
|
2178
|
+
const remote = (u.remote && u.remote.version) || ''
|
|
2179
|
+
const has = u.hasUpdate === true
|
|
2180
|
+
const installed = u.installed || null
|
|
2181
|
+
const restartRequired = u.restartRequired === true
|
|
2182
|
+
// 0.3.7 主路径:包已经下到暂存目录(插件目录没动),等一次「重启并安装」
|
|
2183
|
+
const prepared = u.prepared || null
|
|
2184
|
+
const preparedReady = !!(prepared && prepared.ready)
|
|
2185
|
+
const preparedKb = Math.round((prepared && prepared.size ? prepared.size : 0) / 1024)
|
|
2186
|
+
const failed = !has && u.ok === false && !restartRequired
|
|
2187
|
+
const kind = (restartRequired || preparedReady || has) ? 'warn' : (failed ? 'error' : 'ok')
|
|
2188
|
+
const notesText = (u.remote && (langIsZh() ? (u.remote.notes || u.remote.notesEn) : (u.remote.notesEn || u.remote.notes))) || ''
|
|
2189
|
+
// 检查失败时把每个源的失败原因摆出来,别只给一句 aborted
|
|
2190
|
+
const badSources = (Array.isArray(u.sources) ? u.sources : []).filter((x) => x && x.ok === false)
|
|
2191
|
+
const sourceNote = badSources.length
|
|
2192
|
+
? M(
|
|
2193
|
+
`(${badSources.map((x) => `${x.host || x.url}: ${x.error || '失败'}`).join(';')})`,
|
|
2194
|
+
` (${badSources.map((x) => `${x.host || x.url}: ${x.error || 'failed'}`).join('; ')})`,
|
|
2195
|
+
)
|
|
2196
|
+
: ''
|
|
2197
|
+
const label = restartRequired
|
|
2198
|
+
? M('已安装,待重启', 'Installed, restart pending')
|
|
2199
|
+
: (preparedReady
|
|
2200
|
+
? M('已下载,待安装', 'Downloaded, install pending')
|
|
2201
|
+
: (has
|
|
2202
|
+
? M(`有新版本 ${remote}`, `New version ${remote}`)
|
|
2203
|
+
: (failed ? M('检查失败', 'Check failed') : (u.checkedAt ? M('已是最新', 'Up to date') : M('检查中', 'Checking')))))
|
|
2204
|
+
const text = restartRequired
|
|
2205
|
+
? M(
|
|
2206
|
+
`已装好 ${(installed && installed.version) || remote},当前进程还是 ${local};点「重启 DSH」后生效`,
|
|
2207
|
+
`Installed ${(installed && installed.version) || remote}; this process still runs ${local} — click "Restart DSH" to apply`,
|
|
2208
|
+
)
|
|
2209
|
+
: (preparedReady
|
|
2210
|
+
? M(
|
|
2211
|
+
`已下载 ${prepared.version}${preparedKb ? `(${preparedKb} KB)` : ''} · 点「重启并安装」退出后装好并自动重开`,
|
|
2212
|
+
`Downloaded ${prepared.version}${preparedKb ? ` (${preparedKb} KB)` : ''} — "Restart & install" exits, installs and relaunches`,
|
|
2213
|
+
)
|
|
2214
|
+
: (has
|
|
2215
|
+
? M(
|
|
2216
|
+
`当前 ${local} → 可更新到 ${remote}${notesText ? ` · ${notesText}` : ''}`,
|
|
2217
|
+
`Current ${local} → can update to ${remote}${notesText ? ` · ${notesText}` : ''}`,
|
|
2218
|
+
)
|
|
2219
|
+
: (failed
|
|
2220
|
+
? M(`读不到更新清单:${u.error || '未知原因'}${sourceNote}`, `Cannot read the manifest: ${u.error || 'unknown reason'}${sourceNote}`)
|
|
2221
|
+
: (u.checkedAt ? M(`当前 ${local},云端没有更新的版本`, `Current ${local}; no newer version upstream`) : M('正在读云端版本清单…', 'Reading the cloud manifest…')))))
|
|
2222
|
+
return h('div', { style: S.card },
|
|
2223
|
+
h('div', { style: S.cardHead },
|
|
2224
|
+
h('div', { style: S.cardTitle }, M('插件更新', 'Plugin update')),
|
|
2225
|
+
h('span', { style: chipStyle(kind) }, label),
|
|
2226
|
+
h('div', { style: { flex: 1, minWidth: '8px' } }, null),
|
|
2227
|
+
h('div', { style: S.actions },
|
|
2228
|
+
restartRequired
|
|
2229
|
+
? h('button', {
|
|
2230
|
+
type: 'button', style: S.btnPrimary, disabled: updBusy,
|
|
2231
|
+
onClick: restartDsh,
|
|
2232
|
+
}, updBusy ? M('重启中…', 'Restarting…') : M('重启 DSH', 'Restart DSH'))
|
|
2233
|
+
: (preparedReady
|
|
2234
|
+
? h('button', {
|
|
2235
|
+
type: 'button', style: S.btnPrimary, disabled: updBusy,
|
|
2236
|
+
onClick: restartAndInstall,
|
|
2237
|
+
}, updBusy ? M('安装中…', 'Installing…') : M('重启并安装', 'Restart & install'))
|
|
2238
|
+
: (has ? h('button', {
|
|
2239
|
+
type: 'button', style: S.btnPrimary, disabled: updBusy || !u.remote,
|
|
2240
|
+
onClick: downloadUpdate,
|
|
2241
|
+
}, updBusy ? M('下载中…', 'Downloading…') : M(`下载更新 ${remote}`, `Download ${remote}`)) : null)),
|
|
2242
|
+
h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: checkUpdateNow }, M('检查更新', 'Check for updates')),
|
|
2243
|
+
updEdit
|
|
2244
|
+
? null
|
|
2245
|
+
: h('button', { type: 'button', style: S.btn, disabled: !u.local, onClick: startEditUpd }, M('修改配置', 'Edit config')),
|
|
2246
|
+
),
|
|
2247
|
+
),
|
|
2248
|
+
h('div', { style: S.hint }, text),
|
|
2249
|
+
updEdit
|
|
2250
|
+
? h('div', null,
|
|
2251
|
+
h('div', { style: S.kvRow },
|
|
2252
|
+
h('div', { style: S.kvKey }, M('更新清单', 'Manifest')),
|
|
2253
|
+
h('input', {
|
|
2254
|
+
type: 'text', style: S.input, value: updManifest, spellCheck: false,
|
|
2255
|
+
placeholder: cfg.manifestUrlIsDefault
|
|
2256
|
+
? M(`留空 = 用内置默认(${cfg.manifestUrl || ''})`, `Leave empty = built-in default (${cfg.manifestUrl || ''})`)
|
|
2257
|
+
: 'https://…/version.json',
|
|
2258
|
+
onChange: (e) => setUpdManifest(e.target.value),
|
|
2259
|
+
}),
|
|
2260
|
+
),
|
|
2261
|
+
h('div', { style: S.kvRow },
|
|
2262
|
+
h('div', { style: S.kvKey }, M('更新令牌', 'Token')),
|
|
2263
|
+
h('input', {
|
|
2264
|
+
type: 'text', style: S.input, value: updToken, spellCheck: false,
|
|
2265
|
+
placeholder: cfg.tokenSet
|
|
2266
|
+
? M('已配置;留空表示不改', 'Already set; leave empty to keep it')
|
|
2267
|
+
: M('Gitee 私人令牌(私有库必填)', 'Gitee personal token (required for private repos)'),
|
|
2268
|
+
onChange: (e) => setUpdToken(e.target.value),
|
|
2269
|
+
}),
|
|
2270
|
+
),
|
|
2271
|
+
h('div', { style: S.actions },
|
|
2272
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: updBusy, onClick: saveUpdConfig }, updBusy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
2273
|
+
h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: cancelEditUpd }, M('取消', 'Cancel')),
|
|
2274
|
+
cfg.tokenSet
|
|
2275
|
+
? h('button', { type: 'button', style: S.btn, disabled: updBusy, onClick: clearUpdToken }, M('清除已存令牌', 'Clear stored token'))
|
|
2276
|
+
: null,
|
|
2277
|
+
),
|
|
2278
|
+
)
|
|
2279
|
+
: h('div', null,
|
|
2280
|
+
h(Kv, {
|
|
2281
|
+
k: M('更新清单', 'Manifest'),
|
|
2282
|
+
v: cfg.manifestUrlIsDefault
|
|
2283
|
+
? M('内置默认(jsDelivr → GitHub raw 依次尝试)', 'Built-in default (jsDelivr → GitHub raw in order)')
|
|
2284
|
+
: (cfg.manifestUrl || '…'),
|
|
2285
|
+
}),
|
|
2286
|
+
h(Kv, {
|
|
2287
|
+
k: M('更新源', 'Source'),
|
|
2288
|
+
v: u.sourceUsed
|
|
2289
|
+
? u.sourceUsed
|
|
2290
|
+
: M('本次检查还没读到清单', 'No source reached yet'),
|
|
2291
|
+
}),
|
|
2292
|
+
h(Kv, {
|
|
2293
|
+
k: M('更新令牌', 'Token'),
|
|
2294
|
+
v: cfg.tokenSet
|
|
2295
|
+
? M('已配置(只存本机)', 'Set (stored on this machine only)')
|
|
2296
|
+
: M('未配置(私有库会读不到清单)', 'Not set (private repos cannot be read)'),
|
|
2297
|
+
}),
|
|
2298
|
+
),
|
|
2299
|
+
h('div', { style: S.footnote },
|
|
2300
|
+
M(
|
|
2301
|
+
'下载只写 update-staging 并校验 sha256,插件目录不动;「重启并安装」在退出后覆盖安装并自动重开,失败自动回滚。令牌只存本机。',
|
|
2302
|
+
'Download only writes to update-staging and verifies sha256; "Restart & install" overwrites after exit and relaunches, rolling back on failure. The token stays local.',
|
|
2303
|
+
)),
|
|
2304
|
+
updErr ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } }, M(`保存失败:${updErr}`, `Save failed: ${updErr}`)) : null,
|
|
2305
|
+
updMsg ? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-success-primary)' } }, updMsg) : null,
|
|
2306
|
+
)
|
|
2307
|
+
})()
|
|
2308
|
+
|
|
2309
|
+
// 概览不再用两张 Kv 卡:压成一行指标条(5 格)+ 只在有事时才出现的「待办」。
|
|
2310
|
+
// 明细(Electron 版本、未解析项名字)挪到标题下的元信息行,避免正文堆字。
|
|
2311
|
+
const metric = (label, value, kind) => h('div', { style: S.metric },
|
|
2312
|
+
h('div', { style: S.metricLabel }, label),
|
|
2313
|
+
h('div', {
|
|
2314
|
+
style: {
|
|
2315
|
+
...S.metricValue,
|
|
2316
|
+
color: kind === 'error' ? 'var(--dsw-alias-state-error-primary)'
|
|
2317
|
+
: (kind === 'warn' ? 'var(--dsw-alias-state-warn-primary)' : 'var(--dsw-alias-label-primary)'),
|
|
2318
|
+
},
|
|
2319
|
+
}, value),
|
|
2320
|
+
)
|
|
2321
|
+
const versionText = !data ? '…'
|
|
2322
|
+
: `${data.version.local || '?'} / ${data.version.contract || '?'}`
|
|
2323
|
+
const metrics = h('div', { style: S.strip },
|
|
2324
|
+
metric(M('本机 / 契约', 'App / contract'), versionText,
|
|
2325
|
+
data && data.version.local && data.version.contract && !data.version.match ? 'warn' : 'ok'),
|
|
2326
|
+
metric('bundle',
|
|
2327
|
+
!data ? '…' : (data.bundles.unresolved.length
|
|
2328
|
+
? M(`缺 ${data.bundles.unresolved.length} / ${data.bundles.total}`, `${data.bundles.unresolved.length} missing / ${data.bundles.total}`)
|
|
2329
|
+
: M(`全部可解析 ${data.bundles.total}`, `all ${data.bundles.total} resolvable`)),
|
|
2330
|
+
data && data.bundles.unresolved.length ? 'error' : 'ok'),
|
|
2331
|
+
metric(M('依赖', 'Dependencies'),
|
|
2332
|
+
!data ? '…' : (data.deps.missing.length
|
|
2333
|
+
? M(`缺 ${data.deps.missing.length} / ${data.deps.total}`, `${data.deps.missing.length} missing / ${data.deps.total}`)
|
|
2334
|
+
: M(`齐全 ${data.deps.total}`, `all ${data.deps.total} present`)),
|
|
2335
|
+
data && data.deps.missing.length ? 'error' : 'ok'),
|
|
2336
|
+
metric(M('备份快照', 'Snapshots'),
|
|
2337
|
+
!data ? '…' : (data.backup && data.backup.count ? M(`${data.backup.count} 份`, `${data.backup.count}`) : M('还没有', 'none')),
|
|
2338
|
+
data && data.backup && data.backup.count ? 'ok' : 'warn'),
|
|
2339
|
+
metric(M('上次同步', 'Last sync'), (() => {
|
|
2340
|
+
const local = data && data.local
|
|
2341
|
+
if (!local || !local.known) return M('从未', 'never')
|
|
2342
|
+
const when = local.lastSyncAt ? new Date(local.lastSyncAt) : null
|
|
2343
|
+
const base = when
|
|
2344
|
+
? `${when.getMonth() + 1}/${when.getDate()} ${String(when.getHours()).padStart(2, '0')}:${String(when.getMinutes()).padStart(2, '0')}`
|
|
2345
|
+
: '?'
|
|
2346
|
+
return local.pending > 0 ? M(`${base}(+${local.pending})`, `${base} (+${local.pending})`) : base
|
|
2347
|
+
})(), data && data.local && data.local.pending > 0 ? 'warn' : 'ok'),
|
|
2348
|
+
)
|
|
2349
|
+
const overview = h('div', { style: { gridColumn: '1 / -1', display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
2350
|
+
metrics,
|
|
2351
|
+
data && Array.isArray(data.advice) && data.advice.length
|
|
2352
|
+
? h('div', { style: { ...S.card, gap: '4px', padding: '10px 13px' } },
|
|
2353
|
+
h('div', { style: S.cardTitle }, M('待办', 'To-do')),
|
|
2354
|
+
h(Advice, { items: data.advice }))
|
|
2355
|
+
: null,
|
|
2356
|
+
)
|
|
2357
|
+
|
|
2358
|
+
// 仓库路径可配:默认只读展示,点「修改」才编辑;没配过就强制停在编辑态(见 RepoCard)
|
|
2359
|
+
const repoCard = data ? h(RepoCard, { data, onSaved: refresh }) : h('div', { style: S.card },
|
|
2360
|
+
h('div', { style: S.cardTitle }, M('本机仓库', 'Local repo')),
|
|
2361
|
+
h(Kv, { k: M('仓库路径', 'Repo path'), v: '…' }),
|
|
2362
|
+
)
|
|
2363
|
+
|
|
2364
|
+
const actionCard = h('div', { style: S.card },
|
|
2365
|
+
h('div', { style: S.cardHead },
|
|
2366
|
+
h('div', { style: S.cardTitle }, M('生成退出后执行的脚本', 'Generate post-exit scripts')),
|
|
2367
|
+
),
|
|
2368
|
+
h('div', { style: { ...S.kvRow, alignItems: 'center' } },
|
|
2369
|
+
h('div', { style: S.kvKey }, M('提交说明', 'Commit note')),
|
|
2370
|
+
h('input', {
|
|
2371
|
+
type: 'text',
|
|
2372
|
+
style: S.input,
|
|
2373
|
+
value: note,
|
|
2374
|
+
placeholder: M('可选:这次改了什么(生成推送脚本时写进提交信息,时间会自动附上)', 'Optional: what changed (written into the push commit message; the timestamp is added automatically)'),
|
|
2375
|
+
spellCheck: false,
|
|
2376
|
+
onChange: (e) => setNote(e.target.value),
|
|
2377
|
+
}),
|
|
2378
|
+
),
|
|
2379
|
+
h('div', { style: S.footnote },
|
|
2380
|
+
data && data.backup && data.backup.latest
|
|
2381
|
+
? M(
|
|
2382
|
+
`还原快照:${data.backup.latest}(${data.backup.count} 份中的最新)`,
|
|
2383
|
+
`Restore snapshot: ${data.backup.latest} (newest of ${data.backup.count})`,
|
|
2384
|
+
)
|
|
2385
|
+
: M('还原快照:还没有任何备份快照(还原将无从下手,需拉取或指定 -FromCommit)', 'Restore snapshot: no backups yet (restore has nothing to fall back to — pull first, or pass -FromCommit)')),
|
|
2386
|
+
data && data.repo && !data.repo.exists && !data.repo.empty
|
|
2387
|
+
? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } },
|
|
2388
|
+
M('仓库路径还没配置:先在「本机仓库」卡里设好,否则脚本生成不出来。',
|
|
2389
|
+
'Repo path is not set: configure it in the Local repo card, otherwise scripts cannot be generated.'))
|
|
2390
|
+
: null,
|
|
2391
|
+
data && data.repo && (data.repo.phase === 'empty' || data.repo.phase === 'missing')
|
|
2392
|
+
? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2393
|
+
data.repo.mode === 'await-init'
|
|
2394
|
+
? M('本机与云端都还没有内容:现在只生成「推送」(推送时自动初始化仓库并写骨架),拉取没有东西可拉。',
|
|
2395
|
+
'Both the local repo and the cloud are empty: only Push can be generated (push initializes the repo and writes the skeleton); there is nothing to pull.')
|
|
2396
|
+
: M('本机仓库还没有内容:现在只生成「拉取」(顺带可生成还原)。拉取会把云端仓库整个拉到这个路径,之后推送按钮才会放开。',
|
|
2397
|
+
'The local repo has no content yet: only Pull (plus Restore) can be generated now. Pull brings the whole cloud repo into this path; push unlocks after that.'))
|
|
2398
|
+
: null,
|
|
2399
|
+
data && data.remote && !data.remote.configured
|
|
2400
|
+
? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-error-primary)' } },
|
|
2401
|
+
M('云端仓库地址未配置:推送 / 拉取不可用(还原照常可生成)。',
|
|
2402
|
+
'Cloud remote not set: push/pull unavailable (restore still works).'))
|
|
2403
|
+
: null,
|
|
2404
|
+
data && data.repo && data.repo.ahead > 0
|
|
2405
|
+
? h('div', { style: { ...S.footnote, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2406
|
+
M(`本机领先远端 ${data.repo.ahead} 个提交:改动要推送才入库;拉取会用仓库版本覆盖本机配置。`,
|
|
2407
|
+
`${data.repo.ahead} local commit(s) not pushed: pushing publishes them, pulling overwrites local config.`))
|
|
2408
|
+
: null,
|
|
2409
|
+
h('div', { style: S.actions },
|
|
2410
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || (!canPull && !canPush) || noRemote, onClick: () => prepare('all', note) },
|
|
2411
|
+
canPush && canPull ? M('一键生成 推送 / 拉取 / 还原', 'Generate push / pull / restore')
|
|
2412
|
+
: (canPush ? M('一键生成 推送 / 还原', 'Generate push / restore') : M('一键生成 拉取 / 还原', 'Generate pull / restore'))),
|
|
2413
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !canPush || noRemote, onClick: () => prepare('push', note) }, M('只生成推送', 'Push only')),
|
|
2414
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !canPull || noRemote, onClick: () => prepare('pull') }, M('只生成拉取', 'Pull only')),
|
|
2415
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !hasRepoPath, onClick: () => prepare('restore') }, M('只生成还原', 'Restore only')),
|
|
2416
|
+
),
|
|
2417
|
+
h(MadeNote, { made }),
|
|
2418
|
+
h('div', { style: S.footnote },
|
|
2419
|
+
M('推送 / 拉取要等 DSH 完全退出后跑:生成脚本 → 退出 → 双击。',
|
|
2420
|
+
'Push/pull must run after DSH fully exits: generate, quit, then double-click.')),
|
|
2421
|
+
)
|
|
2422
|
+
|
|
2423
|
+
const remoteCard = data ? h(RemoteCard, { data, onSaved: refresh }) : null
|
|
2424
|
+
const autoCard = data ? h(AutoCard, { data, onSaved: refresh }) : null
|
|
2425
|
+
// 「还原备份」自己拿 status 里的 backup 段(快照列表),改动后让父层 refresh 重新读
|
|
2426
|
+
const restoreCard = data ? h(RestoreCard, { data, onSaved: refresh }) : null
|
|
2427
|
+
// 「同步内容」卡自己拉 /config-sync/scope,不依赖 status(status 读的是仓库与本机,跟勾选无关)
|
|
2428
|
+
const scopeCard = h(ScopeCard, {})
|
|
2429
|
+
const extraCard = h(ExtraCard, {})
|
|
2430
|
+
// 「本机路径」与「问题反馈」自己持有数据(roots 文件是本机私有,feedback 在仓库里)
|
|
2431
|
+
// 这一区平时不进页面:只有标题行的按钮被点开才渲染。
|
|
2432
|
+
// 三类都算告警(待确认路径 / 根外绝对路径 / 被覆盖的配置),数量挂在按钮上。
|
|
2433
|
+
const lpAlert = (data && data.localPaths && data.localPaths.alert) || 0
|
|
2434
|
+
const rootsCard = showRoots ? h(RootsCard, { onRootsSaved: refresh }) : null
|
|
2435
|
+
const feedbackCard = h(FeedbackCard, {})
|
|
2436
|
+
// 冲突卡只在真有清单时才出现:没冲突就不占版面
|
|
2437
|
+
const conflictCard = data && data.conflicts && data.conflicts.exists
|
|
2438
|
+
? h(ConflictCard, { data, onSaved: refresh })
|
|
2439
|
+
: null
|
|
2440
|
+
|
|
2441
|
+
return h('div', { style: S.page },
|
|
2442
|
+
h('div', { style: S.pageInner },
|
|
2443
|
+
h('div', { style: S.pageHeader },
|
|
2444
|
+
h('div', { style: S.pageHeaderMain },
|
|
2445
|
+
h('div', { style: S.pageTitleRow },
|
|
2446
|
+
h('div', { style: S.pageTitle }, M('配置同步', 'Config Sync')),
|
|
2447
|
+
h('div', { style: S.badgeGroup },
|
|
2448
|
+
h('span', { style: S.badgeKey }, M('本机', 'local')),
|
|
2449
|
+
h('span', { style: chipStyle(summary.kind) }, chipLabel(summary.kind)),
|
|
2450
|
+
),
|
|
2451
|
+
// 云端状态:跟左边同一个徽标样式(绿=一致、红=不一致),挂载即查 + 每 2 分钟复查
|
|
2452
|
+
h('div', { style: S.badgeGroup },
|
|
2453
|
+
h('span', { style: S.badgeKey }, M('云端', 'cloud')),
|
|
2454
|
+
h('span', { style: chipStyle(cloudLine.kind) }, cloudLabel),
|
|
2455
|
+
),
|
|
2456
|
+
),
|
|
2457
|
+
// 一行元信息:版本与仓库位置。状态说明交给上面的徽标和下面的指标条,这里不再重复。
|
|
2458
|
+
h('div', { style: S.meta },
|
|
2459
|
+
data ? [
|
|
2460
|
+
h('span', { key: 'app' }, `app ${data.version.local || '?'} / Electron ${data.version.electron || '?'}`),
|
|
2461
|
+
data.repo && data.repo.exists
|
|
2462
|
+
? [
|
|
2463
|
+
h('span', { key: 's2', style: S.metaSep }, '·'),
|
|
2464
|
+
h('span', { key: 'repo' }, `${data.repo.branch || '?'} @ ${(data.repo.head || '').split(' ')[0] || '?'}`),
|
|
2465
|
+
]
|
|
2466
|
+
: null,
|
|
2467
|
+
] : h('span', null, summary.text),
|
|
2468
|
+
),
|
|
2469
|
+
h('div', { style: S.pageLead },
|
|
2470
|
+
M('配置在本机、仓库、云端三处流转:改完立即生效;写入与还原的脚本统一在退出客户端后执行。',
|
|
2471
|
+
'Configs flow between this machine, the repo and the cloud. Changes take effect at once; write and restore scripts run after the client quits.')),
|
|
2472
|
+
),
|
|
2473
|
+
h('div', { style: S.headerActions },
|
|
2474
|
+
// 「本机路径」区唯一的入口:平时普通按钮,只有根外路径/被覆盖这两类告警才变橙并带数字
|
|
2475
|
+
h('button', {
|
|
2476
|
+
type: 'button',
|
|
2477
|
+
style: (!showRoots && lpAlert > 0)
|
|
2478
|
+
? { ...S.btn, color: 'var(--dsw-alias-state-warn-primary)', borderColor: 'var(--dsw-alias-state-warn-primary)' }
|
|
2479
|
+
: S.btn,
|
|
2480
|
+
title: (!showRoots && lpAlert > 0)
|
|
2481
|
+
? M('本机路径有需要处理的告警(根外路径 / 被覆盖的配置),点开查看', 'Local paths need attention (outside-root paths / overwritten configs) - click to open')
|
|
2482
|
+
: M('查看本机路径与占位符的对照', 'Show local paths and their placeholders'),
|
|
2483
|
+
onClick: () => setShowRoots((v) => !v),
|
|
2484
|
+
},
|
|
2485
|
+
showRoots
|
|
2486
|
+
? M('收起本机路径', 'Hide local paths')
|
|
2487
|
+
: (lpAlert > 0
|
|
2488
|
+
? M(`本机路径 · ${lpAlert} 项告警`, `Local paths · ${lpAlert} alert(s)`)
|
|
2489
|
+
: M('本机路径', 'Local paths'))),
|
|
2490
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: refresh },
|
|
2491
|
+
busy ? M('检测中…', 'Checking…') : M('重新检测', 'Re-check')),
|
|
2492
|
+
),
|
|
2493
|
+
),
|
|
2494
|
+
toast
|
|
2495
|
+
? h('div', {
|
|
2496
|
+
style: {
|
|
2497
|
+
position: 'fixed', left: '50%', top: '24px', transform: 'translateX(-50%)', zIndex: 9999,
|
|
2498
|
+
padding: '10px 16px', borderRadius: '8px', fontSize: '13px', lineHeight: 1.5,
|
|
2499
|
+
maxWidth: '70vw', wordBreak: 'break-all',
|
|
2500
|
+
background: 'var(--dsw-alias-settings-card-fill)',
|
|
2501
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
2502
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
2503
|
+
boxShadow: '0 6px 18px var(--dsw-alias-border-l2)',
|
|
2504
|
+
},
|
|
2505
|
+
}, toast)
|
|
2506
|
+
: null,
|
|
2507
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`读取失败:${err}`, `Read failed: ${err}`)) : null,
|
|
2508
|
+
// 按内容分区:状态在上、配置居中、动作在下;每区内部网格并排(宽屏两列)
|
|
2509
|
+
Section(M('概览', 'Overview'), M('版本、依赖、快照一眼看完', 'Versions, dependencies and snapshots at a glance'), [overview]),
|
|
2510
|
+
conflictCard
|
|
2511
|
+
? Section(M('同步冲突', 'Sync conflicts'), M('这些文件挡住了拉取:逐项选完保存,再点「立即拉取」', 'These files block the pull: pick per file, save, then pull'), [conflictCard])
|
|
2512
|
+
: null,
|
|
2513
|
+
Section(M('本机路径', 'Local paths'), M('每台机器只确认一次:仓库里的配置用占位符,落地时按这里的路径展开', 'Confirm once per machine: repo configs use placeholders, expanded with these paths'), [rootsCard]),
|
|
2514
|
+
Section(M('同步目标', 'Sync targets'), M('仓库与远端都是本机配置,改完立即生效', 'Repo and remote are local settings, applied at once'), [repoCard, remoteCard].filter(Boolean)),
|
|
2515
|
+
Section(M('自动化与插件更新', 'Automation & plugin update'), M('退出后自动做什么、插件自己怎么升级', 'What runs automatically after exit, and how the plugin upgrades'), [autoCard, updCard].filter(Boolean)),
|
|
2516
|
+
Section(M('退出后执行', 'After exit'), M('生成脚本 → 退出客户端后跑一遍;写回、推送、重开窗口都在这一步', 'Generate the script → it runs once the client quits; writing back, pushing and reopening live here'), [actionCard]),
|
|
2517
|
+
// 「还原备份」跟在动作卡之后:先看怎么生成脚本,再挑具体退回到哪份快照
|
|
2518
|
+
Section(M('还原备份', 'Restore backup'), M('点快照 → 确认差异 → 排队还原(退出客户端后执行)', 'Pick a snapshot → confirm the diff → queued restore (runs after the client quits)'), [restoreCard].filter(Boolean)),
|
|
2519
|
+
// 「同步内容」放在整页最下面:它是"细项配置",看清前面的状态与动作后才会来调整
|
|
2520
|
+
Section(M('同步内容', 'Sync content'), M('十二组内容,默认全勾;必需组锁定', 'Twelve groups, all checked; required groups are locked'), [scopeCard]),
|
|
2521
|
+
Section(M('插件数据与额外路径', 'Plugin data & extra paths'), M('新插件自己的配置与数据怎么跟着走:默认自动收,排除名单与单文件上限可改', 'How new plugins\' own config and data travel: collected automatically, with editable exclusions and a size cap'), [extraCard]),
|
|
2522
|
+
// 反馈放在最后一区:查完状态、调完配置,才轮到「有问题要报」
|
|
2523
|
+
Section(M('问题反馈', 'Feedback'), M('提交即建 GitHub Issue(label feedback),跨机器共用同一份;离线先进本机队列', 'Each report becomes a GitHub Issue (label feedback), shared across machines; offline ones queue locally first'), [feedbackCard]),
|
|
2524
|
+
),
|
|
2525
|
+
)
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* 本机路径确认卡。
|
|
2530
|
+
* 仓库里存的配置不写死盘符:{{APP_ROOT}} / {{DSH_HOME}} / {{WORKSPACE_HOME}} / {{ROOT:<key>}},
|
|
2531
|
+
* 落地前要换成这台机器的真实路径。以前只靠脚本自动探测,换机器就猜;现在探测值先填好给你改,
|
|
2532
|
+
* 确认过的存进 <dshHome>\config-sync-roots.json,下次不再问。
|
|
2533
|
+
*/
|
|
2534
|
+
function RootsCard(props) {
|
|
2535
|
+
const [data, setData] = react.useState(null)
|
|
2536
|
+
const [busy, setBusy] = react.useState(false)
|
|
2537
|
+
const [err, setErr] = react.useState('')
|
|
2538
|
+
const [msg, setMsg] = react.useState('')
|
|
2539
|
+
const [editing, setEditing] = react.useState(false)
|
|
2540
|
+
const [draft, setDraft] = react.useState(null)
|
|
2541
|
+
const [newKey, setNewKey] = react.useState('')
|
|
2542
|
+
const [newPath, setNewPath] = react.useState('')
|
|
2543
|
+
|
|
2544
|
+
const snap = (r) => ({
|
|
2545
|
+
appRoot: (r && r.roots && r.roots.appRoot) || '',
|
|
2546
|
+
dshHome: (r && r.roots && r.roots.dshHome) || '',
|
|
2547
|
+
workspaceHome: (r && r.roots && r.roots.workspaceHome) || '',
|
|
2548
|
+
custom: { ...((r && r.roots && r.roots.custom) || {}) },
|
|
2549
|
+
})
|
|
2550
|
+
|
|
2551
|
+
const load = async () => {
|
|
2552
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2553
|
+
try {
|
|
2554
|
+
const r = await callRoots()
|
|
2555
|
+
setData(r)
|
|
2556
|
+
if (editing) setDraft(snap(r))
|
|
2557
|
+
} catch (e) {
|
|
2558
|
+
setErr(String((e && e.message) || e))
|
|
2559
|
+
} finally { setBusy(false) }
|
|
2560
|
+
}
|
|
2561
|
+
react.useEffect(() => { load() }, [])
|
|
2562
|
+
|
|
2563
|
+
// 只读优先:进卡先只看不改,点「修改」才解锁;没探测到任何根时强制停在编辑态
|
|
2564
|
+
const detected = snap(data)
|
|
2565
|
+
const forced = !!data && !(detected.appRoot || detected.dshHome || detected.workspaceHome)
|
|
2566
|
+
const isEditing = editing || forced
|
|
2567
|
+
|
|
2568
|
+
const startEdit = () => { setDraft(snap(data)); setErr(''); setMsg(''); setEditing(true) }
|
|
2569
|
+
const cancelEdit = () => { setEditing(false); setDraft(null); setNewKey(''); setNewPath(''); setErr(''); setMsg('') }
|
|
2570
|
+
const setField = (k, v) => setDraft((f) => ({ ...(f || {}), [k]: v }))
|
|
2571
|
+
const setCustom = (k, v) => setDraft((f) => ({ ...(f || {}), custom: { ...((f && f.custom) || {}), [k]: v } }))
|
|
2572
|
+
const delCustom = (k) => setDraft((f) => {
|
|
2573
|
+
const c = { ...((f && f.custom) || {}) }
|
|
2574
|
+
delete c[k]
|
|
2575
|
+
return { ...(f || {}), custom: c }
|
|
2576
|
+
})
|
|
2577
|
+
const addCustom = () => {
|
|
2578
|
+
const k = newKey.trim()
|
|
2579
|
+
const p = newPath.trim()
|
|
2580
|
+
if (!k || !p) return
|
|
2581
|
+
setDraft((f) => ({ ...(f || {}), custom: { ...((f && f.custom) || {}), [k]: p } }))
|
|
2582
|
+
setNewKey(''); setNewPath('')
|
|
2583
|
+
}
|
|
2584
|
+
const save = async () => {
|
|
2585
|
+
if (!draft) return
|
|
2586
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2587
|
+
try {
|
|
2588
|
+
const r = await callRoots({ roots: draft })
|
|
2589
|
+
setMsg([r.note, ...((r.warns || []).map((w) => `⚠ ${w}`))].filter(Boolean).join(' '))
|
|
2590
|
+
setEditing(false)
|
|
2591
|
+
setDraft(null)
|
|
2592
|
+
await load()
|
|
2593
|
+
if (props && typeof props.onRootsSaved === 'function') props.onRootsSaved()
|
|
2594
|
+
} catch (e) {
|
|
2595
|
+
setErr(String((e && e.message) || e))
|
|
2596
|
+
} finally { setBusy(false) }
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
/**
|
|
2600
|
+
* 采纳一条推荐目录:记进本机自选目录(下次推送起这些路径变成占位符,对方机器拉取时换回自己的值)。
|
|
2601
|
+
* 不需要先进编辑态——一次点一个,写完就重新读,面板上那一行立刻变成「已采纳」。
|
|
2602
|
+
*/
|
|
2603
|
+
const adoptAbsolute = async (it) => {
|
|
2604
|
+
if (!data || busy || !it || !it.suggest) return
|
|
2605
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2606
|
+
try {
|
|
2607
|
+
const rootsNow = data.roots || {}
|
|
2608
|
+
const custom = { ...((rootsNow.custom) || {}) }
|
|
2609
|
+
const base = String(it.suggestKey || 'dir')
|
|
2610
|
+
let key = base
|
|
2611
|
+
let n = 2
|
|
2612
|
+
while (Object.keys(custom).some((k) => k.toLowerCase() === key.toLowerCase())) { key = `${base}${n}`; n += 1 }
|
|
2613
|
+
custom[key] = it.suggest
|
|
2614
|
+
const r = await callRoots({ roots: { appRoot: rootsNow.appRoot, dshHome: rootsNow.dshHome, workspaceHome: rootsNow.workspaceHome, custom } })
|
|
2615
|
+
setMsg([r.note, ...((r.warns || []).map((w) => `⚠ ${w}`))].filter(Boolean).join(' '))
|
|
2616
|
+
await load()
|
|
2617
|
+
if (props && typeof props.onRootsSaved === 'function') props.onRootsSaved()
|
|
2618
|
+
} catch (e) {
|
|
2619
|
+
setErr(String((e && e.message) || e))
|
|
2620
|
+
} finally { setBusy(false) }
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
// 这一区显不显示由父层决定(标题行那个按钮),组件自己不吞自己:
|
|
2624
|
+
// 以前在这里 return null,Section 收到的仍是 React 元素、照样渲染分区标题,
|
|
2625
|
+
// 页面上就留下一个空标题——那正是 0.3.37 要修掉的显示问题。
|
|
2626
|
+
const missing = (data && data.missing) || []
|
|
2627
|
+
const rootRows = [
|
|
2628
|
+
{ key: 'appRoot', label: M('客户端安装目录', 'Client install root'), token: '{{APP_ROOT}}', ph: 'D:\\DeepSeekHarness' },
|
|
2629
|
+
{ key: 'dshHome', label: M('.dsh 目录', '.dsh folder'), token: '{{DSH_HOME}}', ph: 'C:\\Users\\<user>\\.dsh' },
|
|
2630
|
+
{ key: 'workspaceHome', label: M('工作区根', 'Workspace root'), token: '{{WORKSPACE_HOME}}', ph: 'D:\\DeepSeekHarness\\workspace' },
|
|
2631
|
+
]
|
|
2632
|
+
const shown = isEditing ? draft : detected
|
|
2633
|
+
const customKeys = shown ? Object.keys(shown.custom || {}) : []
|
|
2634
|
+
const mono = { fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' }
|
|
2635
|
+
|
|
2636
|
+
const rootRow = (row) => h('div', { key: row.key, style: S.kvRow },
|
|
2637
|
+
h('div', { style: S.kvKey }, row.label),
|
|
2638
|
+
isEditing
|
|
2639
|
+
? h('div', { style: { display: 'flex', gap: '6px', alignItems: 'center', flex: 1 } },
|
|
2640
|
+
h('input', {
|
|
2641
|
+
type: 'text', style: S.input, value: ((shown && shown[row.key]) || ''), spellCheck: false,
|
|
2642
|
+
placeholder: row.ph,
|
|
2643
|
+
onChange: (e) => setField(row.key, e.target.value),
|
|
2644
|
+
}),
|
|
2645
|
+
// 填错想退回自动探测值:一键填回,免得手抄(appRoot 尤其不该手改)
|
|
2646
|
+
(data && data.detected && data.detected[row.key] && data.detected[row.key] !== ((shown && shown[row.key]) || ''))
|
|
2647
|
+
? h('button', {
|
|
2648
|
+
type: 'button', style: S.btn, disabled: busy,
|
|
2649
|
+
title: M('填回自动探测到的目录', 'Fill in the auto-detected folder'),
|
|
2650
|
+
onClick: () => setField(row.key, data.detected[row.key]),
|
|
2651
|
+
}, M('用探测值', 'Detected'))
|
|
2652
|
+
: null)
|
|
2653
|
+
: h('div', { style: S.kvVal },
|
|
2654
|
+
h('div', { style: { ...mono, color: (shown && shown[row.key]) ? 'inherit' : 'var(--dsw-alias-text-tertiary, #888)' } },
|
|
2655
|
+
(shown && shown[row.key]) || M('(没探测到,点「修改」填一个)', '(not detected - click Edit and fill one in)')),
|
|
2656
|
+
h('div', { style: S.footnote }, row.token)),
|
|
2657
|
+
)
|
|
2658
|
+
|
|
2659
|
+
|
|
2660
|
+
return h('div', { style: S.card },
|
|
2661
|
+
h('div', { style: S.cardHead },
|
|
2662
|
+
h('div', { style: S.cardTitle }, M('本机路径', 'Local paths')),
|
|
2663
|
+
h('div', { style: { flex: 1 } }, null),
|
|
2664
|
+
// 待确认也算告警:chip 用橙色
|
|
2665
|
+
missing.length
|
|
2666
|
+
? h('span', { style: { ...S.chip, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2667
|
+
M(`待确认 ${missing.length} 项`, `${missing.length} to confirm`))
|
|
2668
|
+
: (data
|
|
2669
|
+
? h('span', { style: { ...S.chip, color: 'var(--dsw-alias-state-success-primary, #2e7d32)' } }, M('已确认', 'Confirmed'))
|
|
2670
|
+
: null),
|
|
2671
|
+
isEditing && forced
|
|
2672
|
+
? h('div', { style: { ...S.hint, flex: 1 } }, M('没探测到路径,先填好再保存', 'Nothing detected - fill these in first'))
|
|
2673
|
+
: null,
|
|
2674
|
+
h('div', { style: S.actions },
|
|
2675
|
+
isEditing
|
|
2676
|
+
? h(react.Fragment, null,
|
|
2677
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !draft, onClick: save },
|
|
2678
|
+
busy ? M('保存中…', 'Saving…') : M('保存', 'Save')),
|
|
2679
|
+
forced ? null : h('button', { type: 'button', style: S.btn, disabled: busy, onClick: cancelEdit }, M('取消', 'Cancel')),
|
|
2680
|
+
)
|
|
2681
|
+
: h('button', { type: 'button', style: S.btn, disabled: !data || busy, onClick: startEdit }, M('修改', 'Edit')),
|
|
2682
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load },
|
|
2683
|
+
busy ? M('读取中…', 'Loading…') : M('重新读取', 'Reload')),
|
|
2684
|
+
),
|
|
2685
|
+
),
|
|
2686
|
+
// 待确认路径也算告警,块标题随徽标一起用橙色(明细列表照旧)
|
|
2687
|
+
missing.length
|
|
2688
|
+
? h('div', { style: { ...S.panel, gap: '4px' } },
|
|
2689
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2690
|
+
M(`上次拉取有 ${missing.length} 项配置没写进去(它们引用的目录这台机器还没确认):填好下面的路径再保存,之后重新拉取一次即可。`,
|
|
2691
|
+
`${missing.length} config(s) were skipped during the last pull (the folders they reference are not confirmed on this machine): fill in the paths below, save, then pull again.`)),
|
|
2692
|
+
missing.slice(0, 20).map((m, i) => h('div', { key: i, style: S.hint },
|
|
2693
|
+
`· ${m.token || '?'} — ${m.label || m.file || ''}${m.hint ? `:${m.hint}` : ''}`)))
|
|
2694
|
+
: null,
|
|
2695
|
+
shown
|
|
2696
|
+
? rootRows.map(rootRow)
|
|
2697
|
+
: h('div', { style: S.hint }, M('读取中…', 'Loading…')),
|
|
2698
|
+
shown && customKeys.length
|
|
2699
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
2700
|
+
h('div', { style: S.footnote }, M('自选目录(插件装在别处时要指定)', 'Custom folders (needed when plugins live elsewhere)')),
|
|
2701
|
+
customKeys.map((k) => h('div', { key: `c-${k}`, style: S.kvRow },
|
|
2702
|
+
h('div', { style: S.kvKey }, `ROOT:${k}`),
|
|
2703
|
+
isEditing
|
|
2704
|
+
? h('div', { style: { display: 'flex', gap: '8px', alignItems: 'flex-start' } },
|
|
2705
|
+
h('input', {
|
|
2706
|
+
type: 'text', style: S.input, value: (shown.custom && shown.custom[k]) || '', spellCheck: false,
|
|
2707
|
+
placeholder: M('这台机器上对应的绝对路径', 'Absolute path on this machine'),
|
|
2708
|
+
onChange: (e) => setCustom(k, e.target.value),
|
|
2709
|
+
}),
|
|
2710
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => delCustom(k) }, M('删除', 'Remove')),
|
|
2711
|
+
)
|
|
2712
|
+
: h('div', { style: S.kvVal },
|
|
2713
|
+
h('div', { style: mono }, (shown.custom && shown.custom[k]) || M('(空)', '(empty)')),
|
|
2714
|
+
h('div', { style: S.footnote }, `{{ROOT:${k}}}`)),
|
|
2715
|
+
)))
|
|
2716
|
+
: null,
|
|
2717
|
+
isEditing
|
|
2718
|
+
? h('div', { style: S.kvRow },
|
|
2719
|
+
h('div', { style: S.kvKey }, M('新增目录', 'Add folder')),
|
|
2720
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
2721
|
+
h('input', {
|
|
2722
|
+
type: 'text', style: { ...S.input, maxWidth: '160px' }, value: newKey, spellCheck: false,
|
|
2723
|
+
placeholder: M('键名,如 comfyui', 'key, e.g. comfyui'),
|
|
2724
|
+
onChange: (e) => setNewKey(e.target.value.replace(/[^A-Za-z0-9_.-]/g, '')),
|
|
2725
|
+
}),
|
|
2726
|
+
h('input', {
|
|
2727
|
+
type: 'text', style: { ...S.input, maxWidth: '320px' }, value: newPath, spellCheck: false,
|
|
2728
|
+
placeholder: M('这台机器上的绝对路径', 'Absolute path on this machine'),
|
|
2729
|
+
onChange: (e) => setNewPath(e.target.value),
|
|
2730
|
+
}),
|
|
2731
|
+
h('button', { type: 'button', style: S.btn, disabled: !newKey.trim() || !newPath.trim(), onClick: addCustom }, M('添加', 'Add')),
|
|
2732
|
+
))
|
|
2733
|
+
: null,
|
|
2734
|
+
data && data.detected && !isEditing
|
|
2735
|
+
? h('div', { style: S.footnote },
|
|
2736
|
+
M(
|
|
2737
|
+
`自动探测:安装目录 ${data.detected.appRoot || '(没找到)'};.dsh ${data.detected.dshHome || '?'};工作区根 ${data.detected.workspaceHome || '(从工作区登记表推不出来)'}`,
|
|
2738
|
+
`Detected: app root ${data.detected.appRoot || '(not found)'}; .dsh ${data.detected.dshHome || '?'}; workspace root ${data.detected.workspaceHome || '(could not infer from the workspace registry)'}`,
|
|
2739
|
+
))
|
|
2740
|
+
: null,
|
|
2741
|
+
// 跨机路径提示(0.3.43):只有这份配置确实是另一台机器推上来的才显示。
|
|
2742
|
+
// 本机自己推出去的路径在本机当然都在,列出来只会让人以为出了问题。
|
|
2743
|
+
data && data.absolutePaths && data.absolutePaths.total && data.absolutePaths.fromOtherMachine
|
|
2744
|
+
? (() => {
|
|
2745
|
+
const apItems = data.absolutePaths.items || [];
|
|
2746
|
+
const confItems = apItems.filter((it) => (it.scope || 'config') === 'config');
|
|
2747
|
+
const dataItems = apItems.filter((it) => it.scope === 'data');
|
|
2748
|
+
const rowOf = (it, i) => h('div', { key: `ap-${it.scope || 'c'}-${i}`, style: { display: 'flex', gap: '8px', alignItems: 'baseline', flexWrap: 'wrap', paddingBottom: '2px' } },
|
|
2749
|
+
h('div', { style: { ...S.hint, fontFamily: 'Consolas, ui-monospace, monospace', flex: '1 1 300px', wordBreak: 'break-all' } }, `· ${it.path}`),
|
|
2750
|
+
it.suggest
|
|
2751
|
+
? h(react.Fragment, null,
|
|
2752
|
+
h('div', { style: S.hint }, '→'),
|
|
2753
|
+
h('div', { style: { ...S.hint, fontFamily: 'Consolas, ui-monospace, monospace', wordBreak: 'break-all' } }, it.suggest),
|
|
2754
|
+
h('div', { style: S.footnote }, it.suggestNote || ''),
|
|
2755
|
+
it.adopted
|
|
2756
|
+
? h('span', { style: { ...S.chip, color: 'var(--dsw-alias-state-success-primary, #2e7d32)' } }, M('已采纳', 'Accepted'))
|
|
2757
|
+
: h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => adoptAbsolute(it) }, M('采纳', 'Accept')))
|
|
2758
|
+
: h('div', { style: S.hint }, M('本机没有等价目录:这条可以不管,或者自己改掉文件里的路径', 'No equivalent folder on this machine: skip it, or edit that path by hand')))
|
|
2759
|
+
return h('div', { style: { ...S.panel, gap: '6px' } },
|
|
2760
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2761
|
+
M(`这份配置是 ${data.absolutePaths.machine || '另一台机器'} 推送的:其中有 ${data.absolutePaths.total} 处绝对路径不属于本机任何已确认根。箭头右边是按本机情况推出来的目录,点「采纳」就记进本机自选目录——下次推送起它们变成占位符,哪台机器拉取都换回自己的路径。`,
|
|
2762
|
+
`This config was pushed from ${data.absolutePaths.machine || 'another machine'}: ${data.absolutePaths.total} absolute path(s) in it belong to no root confirmed on this machine. The folder after the arrow is what this machine would use - Accept records it as a custom root, so from the next push on they become placeholders that each machine expands to its own path.`)),
|
|
2763
|
+
confItems.length
|
|
2764
|
+
? h('div', { style: { ...S.footnote, fontWeight: 600 } }, M(`配置文件里的路径(${confItems.length} 条)`, `Paths inside config files (${confItems.length})`))
|
|
2765
|
+
: null,
|
|
2766
|
+
confItems.map(rowOf),
|
|
2767
|
+
dataItems.length
|
|
2768
|
+
? h('div', { style: { ...S.footnote, fontWeight: 600, marginTop: '6px' } }, M(`工作区与会话记录里的路径(${dataItems.length} 条)`, `Paths in workspace / session records (${dataItems.length})`))
|
|
2769
|
+
: null,
|
|
2770
|
+
dataItems.length
|
|
2771
|
+
? h('div', { style: S.footnote },
|
|
2772
|
+
M('这些决定工作区开在哪个目录、历史会话回到哪个目录。拉取时已经按工作区在本机的落点自动对齐;下面列的是仓库里还指着对方机器的那几条,要一起补成自选目录就点「采纳」。',
|
|
2773
|
+
'These decide which folder a workspace opens in and which folder a session returns to. The pull already aligns them with this machine\'s workspace locations; listed below are the records still pointing at the other machine - Accept adds them as custom roots too.'))
|
|
2774
|
+
: null,
|
|
2775
|
+
dataItems.map(rowOf),
|
|
2776
|
+
h('div', { style: S.footnote },
|
|
2777
|
+
M(`${data.absolutePaths.suggested || 0} 条有推荐、${data.absolutePaths.adoptedCount || 0} 条已采纳。清单来自 ${data.absolutePaths.machine || '对方机器'} 的推送(${data.absolutePaths.at || '时间未记'})。`,
|
|
2778
|
+
`${data.absolutePaths.suggested || 0} with a suggestion, ${data.absolutePaths.adoptedCount || 0} already accepted. List produced by the push from ${data.absolutePaths.machine || 'the other machine'} (${data.absolutePaths.at || 'no timestamp'}).`)))
|
|
2779
|
+
})()
|
|
2780
|
+
: null,
|
|
2781
|
+
data && data.overwrite && data.overwrite.total
|
|
2782
|
+
? h('div', { style: { ...S.panel, gap: '4px' } },
|
|
2783
|
+
h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-warn-primary)' } },
|
|
2784
|
+
M(`上次拉取覆盖了 ${data.overwrite.total} 份本机配置(覆盖前的版本已备份)。如果那些是你刚改的路径,得先「推送」再「拉取」才能保住。`,
|
|
2785
|
+
`The last pull overwrote ${data.overwrite.total} local config file(s) (previous versions are backed up). If those were your own edits, push first and pull after, or they are lost.`)),
|
|
2786
|
+
data.overwrite.items.slice(0, 6).map((it, i) => h('div', { key: `ov-${i}`, style: S.hint },
|
|
2787
|
+
`· ${it.label || it.repo}${it.backup ? `(备份 ${it.backup})` : ''}`)))
|
|
2788
|
+
: null,
|
|
2789
|
+
data && data.file
|
|
2790
|
+
? h('div', { style: S.footnote }, M(`存在:${data.file}(本机私有,不进仓库)`, `Stored at: ${data.file} (local only, never committed)`))
|
|
2791
|
+
: null,
|
|
2792
|
+
data
|
|
2793
|
+
? h('div', { style: S.footnote }, M(
|
|
2794
|
+
'改动只影响之后的推送/拉取:已经落到本机的配置,要再拉取一次才会用上新路径。',
|
|
2795
|
+
'Changes apply to the next push/pull: configs already applied on this machine pick up the new paths only on the next pull.'))
|
|
2796
|
+
: null,
|
|
2797
|
+
msg ? h('div', { style: S.hint }, msg) : null,
|
|
2798
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`失败:${err}`, `Failed: ${err}`)) : null,
|
|
2799
|
+
)
|
|
2800
|
+
}
|
|
2801
|
+
|
|
2802
|
+
/**
|
|
2803
|
+
* 问题反馈卡:写进仓库的 feedback\ 目录并推到云端,另一台机器拉取后同样能看到。
|
|
2804
|
+
* 推送失败不算失败:文件已经留在本机仓库里,下次推送会一起上去。
|
|
2805
|
+
*/
|
|
2806
|
+
/** 问题反馈:提交即建 GitHub Issue(label feedback),列表读 Issue,点「已解决」就关单。 */
|
|
2807
|
+
function FeedbackCard() {
|
|
2808
|
+
const empty = { connected: false, repo: '', label: 'feedback', items: [], counts: { open: 0, closed: 0, total: 0 }, outbox: [], error: '', ghFile: '', version: '', owner: '', login: '', canClose: false, readAnon: false, note: '' }
|
|
2809
|
+
const [st, setSt] = react.useState(empty)
|
|
2810
|
+
const [title, setTitle] = react.useState('')
|
|
2811
|
+
const [text, setText] = react.useState('')
|
|
2812
|
+
const [token, setToken] = react.useState('')
|
|
2813
|
+
const [askToken, setAskToken] = react.useState(false)
|
|
2814
|
+
const [busy, setBusy] = react.useState(false)
|
|
2815
|
+
const [msg, setMsg] = react.useState('')
|
|
2816
|
+
const [err, setErr] = react.useState('')
|
|
2817
|
+
// 筛选:状态走本地过滤(一次拉全量、计数才准),关键词也本地过,输入即筛,不打接口
|
|
2818
|
+
const [filter, setFilter] = react.useState('open')
|
|
2819
|
+
const [kw, setKw] = react.useState('')
|
|
2820
|
+
|
|
2821
|
+
const load = async () => {
|
|
2822
|
+
try {
|
|
2823
|
+
const r = await callFeedback(null)
|
|
2824
|
+
setSt({ ...empty, ...r })
|
|
2825
|
+
setErr(String(r.error || ''))
|
|
2826
|
+
} catch (e) {
|
|
2827
|
+
setErr(String((e && e.message) || e))
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
react.useEffect(() => { load() }, [])
|
|
2831
|
+
|
|
2832
|
+
const submit = async () => {
|
|
2833
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2834
|
+
try {
|
|
2835
|
+
const r = await callFeedback({ title, body: text })
|
|
2836
|
+
if (r && r.needToken && r.fallbackUrl) {
|
|
2837
|
+
// 没有令牌:把这单交给浏览器——预填好标题/正文/环境块,登录状态下点一下就建好了
|
|
2838
|
+
try { window.open(r.fallbackUrl, '_blank', 'noopener') } catch { }
|
|
2839
|
+
setMsg(M('没有令牌,已打开浏览器里的新建 issue 页面(标题和正文都填好了),点一下提交即可。', 'No token: opened the prefilled new-issue page in the browser - press submit there.'))
|
|
2840
|
+
} else if (r && r.number) {
|
|
2841
|
+
setMsg(M(`已建 Issue #${r.number},列表里能看到,网页上也点得开。`, `Issue #${r.number} created; it shows in the list and opens in the browser.`))
|
|
2842
|
+
setTitle('')
|
|
2843
|
+
setText('')
|
|
2844
|
+
} else {
|
|
2845
|
+
setMsg(M(`没连上 GitHub(${(r && r.error) || '网络不通'}),已存进本机待发队列(${r ? r.remaining : 0} 条),联网后点「补发」。`,
|
|
2846
|
+
`Could not reach GitHub (${(r && r.error) || 'network'}). Saved to the local queue (${r ? r.remaining : 0} item(s)); press Flush when online.`))
|
|
2847
|
+
}
|
|
2848
|
+
await load()
|
|
2849
|
+
} catch (e) {
|
|
2850
|
+
setErr(String((e && e.message) || e))
|
|
2851
|
+
} finally { setBusy(false) }
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
const saveToken = async () => {
|
|
2855
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2856
|
+
try {
|
|
2857
|
+
await callFeedback({ token }, { query: { action: 'token' } })
|
|
2858
|
+
setToken('')
|
|
2859
|
+
setAskToken(false)
|
|
2860
|
+
setMsg(M('令牌已存到本机(不进仓库),连接正常。', 'Token saved locally (never committed); connection works.'))
|
|
2861
|
+
await load()
|
|
2862
|
+
} catch (e) {
|
|
2863
|
+
setErr(String((e && e.message) || e))
|
|
2864
|
+
} finally { setBusy(false) }
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
const flush = async () => {
|
|
2868
|
+
setBusy(true); setErr(''); setMsg('')
|
|
2869
|
+
try {
|
|
2870
|
+
const r = await callFeedback({}, { query: { action: 'flush' } })
|
|
2871
|
+
setMsg(M(`补发 ${(r.sent || []).length} 条,还剩 ${r.remaining || 0} 条。`, `Flushed ${(r.sent || []).length}, ${r.remaining || 0} left.`))
|
|
2872
|
+
await load()
|
|
2873
|
+
} catch (e) {
|
|
2874
|
+
setErr(String((e && e.message) || e))
|
|
2875
|
+
} finally { setBusy(false) }
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
const setState = async (number, next) => {
|
|
2879
|
+
setBusy(true); setErr('')
|
|
2880
|
+
try {
|
|
2881
|
+
await callFeedback({ state: next }, { query: { number }, method: 'PATCH' })
|
|
2882
|
+
await load()
|
|
2883
|
+
} catch (e) {
|
|
2884
|
+
setErr(String((e && e.message) || e))
|
|
2885
|
+
} finally { setBusy(false) }
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
const fmt = (s) => {
|
|
2889
|
+
if (!s) return '?'
|
|
2890
|
+
try { return new Date(s).toLocaleString(localeNow(), { hour12: false }) } catch { return s }
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
const dot = (color) => h('span', {
|
|
2894
|
+
style: { display: 'inline-block', width: '7px', height: '7px', borderRadius: '50%', background: color, marginRight: '6px', verticalAlign: 'middle' },
|
|
2895
|
+
}, null)
|
|
2896
|
+
|
|
2897
|
+
const open = st.counts.open
|
|
2898
|
+
const closed = st.counts.closed
|
|
2899
|
+
const total = st.counts.total || st.items.length
|
|
2900
|
+
|
|
2901
|
+
// 关键词:编号、标题、作者、正文都算(正文是 Issue 的 body,含环境块)
|
|
2902
|
+
const shown = st.items.filter((it) => {
|
|
2903
|
+
if (filter === 'open' && it.state !== 'open') return false
|
|
2904
|
+
if (filter === 'closed' && it.state !== 'closed') return false
|
|
2905
|
+
const q = kw.trim().toLowerCase()
|
|
2906
|
+
if (!q) return true
|
|
2907
|
+
const hay = `${it.number} ${it.title || ''} ${it.user || ''} ${it.body || ''}`.toLowerCase()
|
|
2908
|
+
return hay.includes(q)
|
|
2909
|
+
})
|
|
2910
|
+
|
|
2911
|
+
const seg = (key, label) => h('button', {
|
|
2912
|
+
key,
|
|
2913
|
+
type: 'button',
|
|
2914
|
+
style: filter === key ? S.btnPrimary : S.btn,
|
|
2915
|
+
onClick: () => setFilter(key),
|
|
2916
|
+
}, label)
|
|
2917
|
+
|
|
2918
|
+
return h('div', { style: S.card },
|
|
2919
|
+
h('div', { style: S.cardHead },
|
|
2920
|
+
h('div', { style: S.cardTitle }, M('问题反馈', 'Feedback')),
|
|
2921
|
+
h('div', { style: { flex: 1 } }, null),
|
|
2922
|
+
h('span', { style: S.chip }, M(`${open} 待处理 / 共 ${total}`, `${open} open / ${total} total`)),
|
|
2923
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: load }, M('刷新', 'Refresh')),
|
|
2924
|
+
),
|
|
2925
|
+
h('div', { style: S.kvRow },
|
|
2926
|
+
h('div', { style: S.kvKey }, M('连接', 'Connect')),
|
|
2927
|
+
h('div', { style: S.kvVal },
|
|
2928
|
+
h('div', null,
|
|
2929
|
+
dot(st.canClose ? 'var(--dsw-alias-state-success-primary, #35a854)' : (st.items.length ? 'var(--dsw-alias-state-warning-primary, #d97706)' : 'var(--dsw-alias-state-error-primary)')),
|
|
2930
|
+
st.canClose
|
|
2931
|
+
? M(`GitHub ${st.repo} · 已用 ${st.login} 登录(可提交、可关单)`, `GitHub ${st.repo} · signed in as ${st.login} (can submit and close)`)
|
|
2932
|
+
: st.connected
|
|
2933
|
+
? M(`GitHub ${st.repo} · 令牌属于 ${st.login || '?'},不是仓库所有者,只能读和提交`, `GitHub ${st.repo} · token belongs to ${st.login || '?'}, not the repo owner: read and submit only`)
|
|
2934
|
+
: st.readAnon
|
|
2935
|
+
? M(`GitHub ${st.repo} · 匿名读取(公开仓库,不需要令牌;提交走浏览器)`, `GitHub ${st.repo} · anonymous read (public repo, no token; submit via browser)`)
|
|
2936
|
+
: M('还没连上 GitHub(令牌没取到或网络不通)', 'Not connected to GitHub (no token or no network)'),
|
|
2937
|
+
),
|
|
2938
|
+
h('div', { style: S.footnote },
|
|
2939
|
+
st.note || (st.ghFile ? M(`令牌/仓库记在 ${st.ghFile}(本机私有,不进仓库)`, `Token and repo live in ${st.ghFile} (local only, never committed)`) : null)),
|
|
2940
|
+
),
|
|
2941
|
+
),
|
|
2942
|
+
(askToken || !st.connected)
|
|
2943
|
+
? h('div', { style: S.kvRow },
|
|
2944
|
+
h('div', { style: S.kvKey }, M('令牌', 'Token')),
|
|
2945
|
+
h('div', { style: { ...S.kvVal, display: 'flex', gap: '8px' } },
|
|
2946
|
+
h('input', {
|
|
2947
|
+
type: 'password', style: S.input, value: token, spellCheck: false, autoComplete: 'off',
|
|
2948
|
+
placeholder: M('粘贴 GitHub 令牌(只需一次;留空则自动读本机 git 凭据)', 'Paste a GitHub token (once); leave empty to reuse the local git credential'),
|
|
2949
|
+
onChange: (e) => setToken(e.target.value),
|
|
2950
|
+
}),
|
|
2951
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !token.trim(), onClick: saveToken }, M('保存', 'Save')),
|
|
2952
|
+
),
|
|
2953
|
+
)
|
|
2954
|
+
: null,
|
|
2955
|
+
h('div', { style: S.kvRow },
|
|
2956
|
+
h('div', { style: S.kvKey }, M('标题', 'Title')),
|
|
2957
|
+
h('input', {
|
|
2958
|
+
type: 'text', style: S.input, value: title, spellCheck: false,
|
|
2959
|
+
placeholder: M('一句话说清是什么问题(例如:拉取后桌宠配置没跟着过来)', 'One line about the problem (e.g. pet config did not come over after a pull)'),
|
|
2960
|
+
onChange: (e) => setTitle(e.target.value),
|
|
2961
|
+
}),
|
|
2962
|
+
),
|
|
2963
|
+
h('div', { style: S.kvRow },
|
|
2964
|
+
h('div', { style: S.kvKey }, M('详情', 'Details')),
|
|
2965
|
+
h('textarea', {
|
|
2966
|
+
style: { ...S.input, minHeight: '64px', resize: 'vertical', fontFamily: 'inherit' },
|
|
2967
|
+
value: text, spellCheck: false, rows: 3,
|
|
2968
|
+
placeholder: M('现象、期望、怎么复现(版本、机器、时间会自动附在末尾)', 'What happened, what you expected, how to reproduce (version, machine and time are appended automatically)'),
|
|
2969
|
+
onChange: (e) => setText(e.target.value),
|
|
2970
|
+
}),
|
|
2971
|
+
),
|
|
2972
|
+
h('div', { style: S.actions },
|
|
2973
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !title.trim(), onClick: submit },
|
|
2974
|
+
busy ? M('提交中…', 'Submitting…') : M('提交到 GitHub', 'Submit to GitHub')),
|
|
2975
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: () => setAskToken(!askToken) },
|
|
2976
|
+
M(askToken ? '收起令牌' : '换令牌', askToken ? 'Hide token' : 'Change token')),
|
|
2977
|
+
st.outbox.length
|
|
2978
|
+
? h('button', { type: 'button', style: S.btn, disabled: busy, onClick: flush }, M(`补发 ${st.outbox.length} 条`, `Flush ${st.outbox.length}`))
|
|
2979
|
+
: null,
|
|
2980
|
+
h('div', { style: S.footnote }, M('反馈是 GitHub Issue,另一台机器打开面板看到的是同一份', 'Each report is a GitHub Issue; the other machine sees the same list')),
|
|
2981
|
+
),
|
|
2982
|
+
msg ? h('div', { style: S.hint }, msg) : null,
|
|
2983
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`失败:${err}`, `Failed: ${err}`)) : null,
|
|
2984
|
+
st.outbox.length
|
|
2985
|
+
? h('div', { style: S.hint }, M(`本机还有 ${st.outbox.length} 条没发出去(网络恢复后点「补发」)`, `${st.outbox.length} item(s) still queued locally (press Flush when the network is back)`))
|
|
2986
|
+
: null,
|
|
2987
|
+
st.items.length
|
|
2988
|
+
? h('div', { style: { ...S.panel, gap: '8px' } },
|
|
2989
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap' } },
|
|
2990
|
+
seg('open', M(`未解决 ${open}`, `Open ${open}`)),
|
|
2991
|
+
seg('closed', M(`已解决 ${closed}`, `Closed ${closed}`)),
|
|
2992
|
+
seg('all', M(`全部 ${total}`, `All ${total}`)),
|
|
2993
|
+
h('div', { style: { flex: 1 } }, null),
|
|
2994
|
+
h('input', {
|
|
2995
|
+
type: 'text', style: { ...S.input, maxWidth: '260px' }, value: kw, spellCheck: false,
|
|
2996
|
+
placeholder: M('搜索:编号 / 标题 / 内容', 'Search: number / title / body'),
|
|
2997
|
+
onChange: (e) => setKw(e.target.value),
|
|
2998
|
+
}),
|
|
2999
|
+
kw ? h('button', { type: 'button', style: S.btn, onClick: () => setKw('') }, M('清空', 'Clear')) : null,
|
|
3000
|
+
),
|
|
3001
|
+
h('div', { style: S.footnote },
|
|
3002
|
+
M(`显示 ${shown.length} / ${filter === 'all' ? total : (filter === 'open' ? open : closed)} 条${kw ? `(关键词「${kw}」)` : ''};列表最多读 50 条,更早的请点 GitHub 页`,
|
|
3003
|
+
`${shown.length} of ${filter === 'all' ? total : (filter === 'open' ? open : closed)} shown${kw ? ` (keyword "${kw}")` : ''}; at most 50 read, older ones on the GitHub page`)),
|
|
3004
|
+
shown.length
|
|
3005
|
+
? shown.slice(0, 20).map((it) => h('div', { key: it.number, style: S.kvRow },
|
|
3006
|
+
h('div', { style: { ...S.kvKey, width: '42px', minWidth: '42px' } }, `#${it.number}`),
|
|
3007
|
+
h('div', { style: S.kvVal },
|
|
3008
|
+
h('a', {
|
|
3009
|
+
href: it.url, target: '_blank', rel: 'noreferrer',
|
|
3010
|
+
style: { color: 'inherit', textDecoration: 'none', cursor: 'pointer' },
|
|
3011
|
+
}, it.title || '(无标题)'),
|
|
3012
|
+
h('div', { style: S.footnote },
|
|
3013
|
+
`${it.state} · ${fmt(it.createdAt)}${it.user ? ` · ${it.user}` : ''}${it.comments ? ` · ${it.comments} 条评论` : ''}`)),
|
|
3014
|
+
h('button', {
|
|
3015
|
+
type: 'button',
|
|
3016
|
+
style: S.btn,
|
|
3017
|
+
disabled: busy || !st.canClose,
|
|
3018
|
+
title: st.canClose ? '' : M('只有仓库所有者能关单', 'Only the repo owner can close issues'),
|
|
3019
|
+
onClick: () => setState(it.number, it.state === 'closed' ? 'open' : 'closed'),
|
|
3020
|
+
}, !st.canClose ? M('仅所有者', 'Owner only') : (it.state === 'closed' ? M('重开', 'Reopen') : M('已解决', 'Resolve'))),
|
|
3021
|
+
))
|
|
3022
|
+
: h('div', { style: S.footnote }, kw ? M('没有匹配的反馈,换个关键词或清空搜索。', 'Nothing matches; try another keyword or clear the search.') : M('这个状态下没有反馈。', 'No feedback in this state.')),
|
|
3023
|
+
)
|
|
3024
|
+
: h('div', { style: S.footnote }, M('还没有反馈记录。', 'No feedback yet.')),
|
|
3025
|
+
h('div', { style: S.footnote },
|
|
3026
|
+
M('读列表不需要令牌(公开仓库,匿名 60 次/小时);提交和关单要令牌,且只有仓库所有者能关单。没有令牌时提交会打开浏览器里预填好的新建 issue 页面。',
|
|
3027
|
+
'Reading needs no token (public repo, 60 anonymous requests/hour); submitting and closing do, and only the repo owner can close. Without a token, submitting opens a prefilled new-issue page in the browser.')),
|
|
3028
|
+
)
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
/** 侧栏行的图标:两条反向箭头(同步)。宿主会按 id 处理点击与选中态。 */
|
|
3032
|
+
function SidebarIcon(owner) {
|
|
3033
|
+
const size = (owner && owner.size) || 16
|
|
3034
|
+
return h('svg', {
|
|
3035
|
+
width: size, height: size, viewBox: '0 0 16 16', fill: 'none',
|
|
3036
|
+
stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round',
|
|
3037
|
+
'aria-hidden': 'true',
|
|
3038
|
+
},
|
|
3039
|
+
h('path', { d: 'M3 5.5h8.5' }),
|
|
3040
|
+
h('path', { d: 'M9.2 3.2 11.5 5.5 9.2 7.8' }),
|
|
3041
|
+
h('path', { d: 'M13 10.5H4.5' }),
|
|
3042
|
+
h('path', { d: 'M6.8 8.2 4.5 10.5 6.8 12.8' }),
|
|
3043
|
+
)
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
/** 设置 → 通用 里的一行摘要(保留入口,不重复大面板)。 */
|
|
3047
|
+
function ConfigSyncRow() {
|
|
3048
|
+
const { data, err, busy, made, refresh, prepare } = useSync()
|
|
3049
|
+
const [open, setOpen] = react.useState(false)
|
|
3050
|
+
const summary = summarize(data)
|
|
3051
|
+
|
|
3052
|
+
const head = h('div', { style: S.head },
|
|
3053
|
+
h('div', { style: S.headText },
|
|
3054
|
+
h('div', { style: S.title }, M('配置同步', 'Config Sync')),
|
|
3055
|
+
h('div', { style: S.sub }, busy ? M('检测中…', 'Checking…') : summary.text),
|
|
3056
|
+
data ? h('div', { style: S.sub }, `app ${data.version.local || '?'} / ${M('契约', 'contract')} ${data.version.contract || '?'}`) : null,
|
|
3057
|
+
),
|
|
3058
|
+
h('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexShrink: 0 } },
|
|
3059
|
+
h('span', { style: chipStyle(summary.kind) }, chipLabel(summary.kind)),
|
|
3060
|
+
h('button', { type: 'button', style: S.btn, onClick: () => setOpen((v) => !v) }, open ? M('收起', 'Collapse') : M('查看', 'View')),
|
|
3061
|
+
h('button', { type: 'button', style: S.btn, disabled: busy, onClick: refresh }, M('刷新', 'Refresh')),
|
|
3062
|
+
),
|
|
3063
|
+
)
|
|
3064
|
+
|
|
3065
|
+
if (!open) {
|
|
3066
|
+
return h('div', { style: S.row }, head,
|
|
3067
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`读取失败:${err}`, `Read failed: ${err}`)) : null)
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
return h('div', { style: S.row },
|
|
3071
|
+
head,
|
|
3072
|
+
err ? h('div', { style: { ...S.hint, color: 'var(--dsw-alias-state-error-primary)' } }, M(`读取失败:${err}`, `Read failed: ${err}`)) : null,
|
|
3073
|
+
h('div', { style: S.panel },
|
|
3074
|
+
data ? h(Kv, {
|
|
3075
|
+
k: M('仓库', 'Repo'),
|
|
3076
|
+
v: data.repo.exists
|
|
3077
|
+
? `${data.repo.path} (${data.repo.branch || '?'} @ ${data.repo.head || '?'})`
|
|
3078
|
+
: M('还没配置(请到面板里设置)', 'Not configured (set it in the panel)'),
|
|
3079
|
+
}) : null,
|
|
3080
|
+
data ? h(Kv, {
|
|
3081
|
+
k: M('远端', 'Remote'),
|
|
3082
|
+
v: data.repo.behind === null
|
|
3083
|
+
? M('读不到', 'Unavailable')
|
|
3084
|
+
: M(
|
|
3085
|
+
`落后 ${data.repo.behind} · 领先 ${data.repo.ahead} · 未提交 ${data.repo.dirty}`,
|
|
3086
|
+
`behind ${data.repo.behind} · ahead ${data.repo.ahead} · dirty ${data.repo.dirty}`,
|
|
3087
|
+
),
|
|
3088
|
+
}) : null,
|
|
3089
|
+
data ? h(Kv, {
|
|
3090
|
+
k: 'bundle',
|
|
3091
|
+
v: M(
|
|
3092
|
+
`${data.bundles.total} 项,解析不到 ${data.bundles.unresolved.length} 项` + (data.bundles.unresolved.length ? `:${data.bundles.unresolved.join(', ')}` : ''),
|
|
3093
|
+
`${data.bundles.total} total, ${data.bundles.unresolved.length} unresolved` + (data.bundles.unresolved.length ? `: ${data.bundles.unresolved.join(', ')}` : ''),
|
|
3094
|
+
),
|
|
3095
|
+
}) : null,
|
|
3096
|
+
data && data.remote ? h(Kv, { k: M('远端地址', 'Remote URL'), v: data.remote.url || M('(未配置)', '(not set)') }) : null,
|
|
3097
|
+
data && data.remote ? h(Kv, { k: M('SSH 私钥', 'SSH key'), v: data.remote.sshKey || M('(未配置)', '(not set)') }) : null,
|
|
3098
|
+
data ? h(Advice, { items: data.advice }) : null,
|
|
3099
|
+
h('div', { style: S.actions },
|
|
3100
|
+
h('button', { type: 'button', style: S.btnPrimary, disabled: busy || !data || !data.repo.exists, onClick: () => prepare('all') }, M('一键生成 推送 / 拉取 / 还原', 'Generate push / pull / restore')),
|
|
3101
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !data || !data.repo.exists, onClick: () => prepare('push') }, M('只生成推送', 'Push only')),
|
|
3102
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !data || !data.repo.exists, onClick: () => prepare('pull') }, M('只生成拉取', 'Pull only')),
|
|
3103
|
+
h('button', { type: 'button', style: S.btn, disabled: busy || !data || !data.repo.exists, onClick: () => prepare('restore') }, M('只生成还原', 'Restore only')),
|
|
3104
|
+
),
|
|
3105
|
+
h(MadeNote, { made }),
|
|
3106
|
+
),
|
|
3107
|
+
)
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
/**
|
|
3111
|
+
* 上次自动同步的结果是否该弹:15 分钟内 + 这次进程没弹过。
|
|
3112
|
+
* 返回提示文案,不该弹就返回空串;命中后立刻记进 localStorage(同一条只弹一次)。
|
|
3113
|
+
*/
|
|
3114
|
+
function takeFreshResult(last) {
|
|
3115
|
+
if (!last || !last.at) return ''
|
|
3116
|
+
const age = Date.now() - last.at
|
|
3117
|
+
if (age < 0 || age > 15 * 60 * 1000) return ''
|
|
3118
|
+
let seen = ''
|
|
3119
|
+
try { seen = window.localStorage.getItem('dsh-config-sync:lastResultAt') || '' } catch { }
|
|
3120
|
+
if (seen === String(last.at)) return ''
|
|
3121
|
+
try { window.localStorage.setItem('dsh-config-sync:lastResultAt', String(last.at)) } catch { }
|
|
3122
|
+
const who = last.mode === 'pull' ? M('自动拉取', 'Auto pull') : M('自动推送', 'Auto push')
|
|
3123
|
+
return last.ok
|
|
3124
|
+
? M(`${who}完成:${last.message}`, `${who} finished: ${last.message}`)
|
|
3125
|
+
: M(
|
|
3126
|
+
`${who}失败:${last.message}${last.log ? '(日志:' + last.log + ')' : ''}`,
|
|
3127
|
+
`${who} failed: ${last.message}${last.log ? ' (log: ' + last.log + ')' : ''}`,
|
|
3128
|
+
)
|
|
3129
|
+
}
|
|
3130
|
+
|
|
3131
|
+
/**
|
|
3132
|
+
* 客户端一打开就弹上次同步结果 —— 以前只在「配置同步」面板里弹,
|
|
3133
|
+
* 用户关掉 DSH 让它推送完、再打开 DSH 看到的却是毫无提示的主界面,必须自己点进面板才知道。
|
|
3134
|
+
* 这里不依赖面板挂载:直接查一次 status,自己 append 一个浮层,5 秒后收回。
|
|
3135
|
+
*/
|
|
3136
|
+
function showResultToast(text) {
|
|
3137
|
+
try {
|
|
3138
|
+
const box = document.createElement('div')
|
|
3139
|
+
box.textContent = text
|
|
3140
|
+
box.style.cssText = [
|
|
3141
|
+
'position:fixed', 'left:50%', 'top:24px', 'transform:translateX(-50%)',
|
|
3142
|
+
'z-index:2147483000', 'padding:10px 16px', 'border-radius:8px',
|
|
3143
|
+
'font-size:13px', 'line-height:1.5', 'max-width:70vw', 'word-break:break-all',
|
|
3144
|
+
'box-shadow:0 6px 18px var(--dsw-alias-border-l2)',
|
|
3145
|
+
'background:var(--dsw-alias-settings-card-fill)',
|
|
3146
|
+
'border:1px solid var(--dsw-alias-border-l2)',
|
|
3147
|
+
'color:var(--dsw-alias-label-primary)', 'pointer-events:none',
|
|
3148
|
+
].join('; ')
|
|
3149
|
+
document.body.appendChild(box)
|
|
3150
|
+
setTimeout(() => { try { box.remove() } catch { } }, 5000)
|
|
3151
|
+
} catch (error) {
|
|
3152
|
+
try { console.warn('[dsh-config-sync] startup toast failed:', error) } catch { }
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
|
|
3156
|
+
async function announceLastResult() {
|
|
3157
|
+
try {
|
|
3158
|
+
const res = await fetch('/config-sync/status', { cache: 'no-store', credentials: 'same-origin' })
|
|
3159
|
+
if (!res.ok) return
|
|
3160
|
+
const data = await res.json()
|
|
3161
|
+
const text = takeFreshResult(data && data.auto && data.auto.lastResult)
|
|
3162
|
+
if (text) showResultToast(text)
|
|
3163
|
+
} catch { /* 插件路由还没起好就静默跳过,面板里仍会显示同一结果 */ }
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
function apply(ctx) {
|
|
3167
|
+
// 侧栏行 + 配对面板:两个 slot 必须各自 inject(嵌套),再在作用域里成对 register。
|
|
3168
|
+
// 只 inject('main') 就向 sidebar.panellist 注册是无效的——区域还没被注入,注册落不下去。
|
|
3169
|
+
try {
|
|
3170
|
+
ctx.slots.inject('main', () => ctx.slots.inject('sidebar.panellist', () => {
|
|
3171
|
+
const offPanel = ctx.slots.register({ name: 'main', key: PANEL_ID }, ConfigSyncPanel)
|
|
3172
|
+
const offRow = ctx.slots.register({
|
|
3173
|
+
name: 'sidebar.panellist',
|
|
3174
|
+
id: PANEL_ID,
|
|
3175
|
+
order: 35,
|
|
3176
|
+
label: () => M('配置同步', 'Config Sync'),
|
|
3177
|
+
locale: 'config-sync',
|
|
3178
|
+
}, SidebarIcon)
|
|
3179
|
+
return () => {
|
|
3180
|
+
if (typeof offRow === 'function') offRow()
|
|
3181
|
+
if (typeof offPanel === 'function') offPanel()
|
|
3182
|
+
}
|
|
3183
|
+
}))
|
|
3184
|
+
} catch (error) {
|
|
3185
|
+
// 老版本宿主没有 sidebar.panellist 就静默降级到设置页;但要把原因留在控制台
|
|
3186
|
+
try { console.warn('[dsh-config-sync] sidebar entry registration failed:', error) } catch { }
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
try {
|
|
3190
|
+
ctx.slots.inject('settings.general.item', () => ctx.slots.register({
|
|
3191
|
+
name: 'settings.general.item',
|
|
3192
|
+
id: 'config-sync',
|
|
3193
|
+
order: 20,
|
|
3194
|
+
}, ConfigSyncRow))
|
|
3195
|
+
} catch (error) {
|
|
3196
|
+
try { console.warn('[dsh-config-sync] settings entry registration failed:', error) } catch { }
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
// 界面还没完全起来时 fetch 可能扑空,所以稍等一会儿再查;只查一次,不轮询。
|
|
3200
|
+
try { setTimeout(announceLastResult, 1500) } catch { }
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
exports.name = name
|
|
3204
|
+
exports.inject = inject
|
|
3205
|
+
exports.apply = apply
|
|
3206
|
+
return module.exports
|
|
3207
|
+
},
|
|
3208
|
+
})
|