dsh-go-plugin-sync 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -1,256 +1,325 @@
1
- window.__ModuleLoader__.load({
2
- id: 'dsh-go-plugin-sync',
3
- factory(require) {
4
- const React = require('react')
5
- const h = React.createElement
6
- const API = '/dsh-go-plugin-sync/api'
7
- const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
8
- const T = (cn, en) => (zh ? cn : en)
9
- const INPUT = {
10
- width: '100%',
11
- boxSizing: 'border-box',
12
- padding: '6px 8px',
13
- borderRadius: '6px',
14
- border: '1px solid rgba(128,128,128,.35)',
15
- background: 'transparent',
16
- color: 'inherit',
17
- font: 'inherit',
18
- fontSize: '13px',
19
- }
20
- const LABEL = { display: 'block', margin: '8px 0 0', fontSize: '12px', opacity: 0.7 }
21
- const BUTTON = {
22
- padding: '6px 12px',
23
- borderRadius: '6px',
24
- border: '1px solid rgba(128,128,128,.35)',
25
- background: 'transparent',
26
- color: 'inherit',
27
- font: 'inherit',
28
- fontSize: '13px',
29
- cursor: 'pointer',
30
- }
31
- const PRIMARY = { ...BUTTON, background: '#3D6FD6', borderColor: '#3D6FD6', color: '#fff' }
32
- const BADGE = {
33
- fontSize: '11px',
34
- lineHeight: '16px',
35
- padding: '0 6px',
36
- borderRadius: '8px',
37
- border: '1px solid rgba(128,128,128,.3)',
38
- opacity: 0.75,
39
- }
40
-
41
- function api(path, body) {
42
- const options = body === undefined
43
- ? {}
44
- : { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }
45
- return fetch(`${API}/${path}`, options).then((response) => response.json())
46
- }
47
-
48
- function Field({ label, value, onChange, placeholder, type }) {
49
- return h('label', { style: LABEL }, label,
50
- h('input', {
51
- type: type || 'text',
52
- value: value == null ? '' : String(value),
53
- placeholder: placeholder || '',
54
- onChange: (event) => onChange(event.target.value),
55
- style: { ...INPUT, marginTop: '4px' },
56
- }))
57
- }
58
-
59
- function SyncSettings() {
60
- const [rows, setRows] = React.useState([])
61
- const [results, setResults] = React.useState([])
62
- const [picked, setPicked] = React.useState({})
63
- const [code, setCode] = React.useState('')
64
- const [config, setConfig] = React.useState(null)
65
- const [status, setStatus] = React.useState('')
66
- const [tone, setTone] = React.useState('')
67
- const [busy, setBusy] = React.useState(false)
68
- const [configPath, setConfigPath] = React.useState('')
69
- const wasRunning = React.useRef(false)
70
-
71
- const note = (text, kind) => { setStatus(text); setTone(kind || '') }
72
-
73
- const load = () => api('state').then((snapshot) => {
74
- if (snapshot.error) { note(snapshot.error, 'bad'); return }
75
- setRows(snapshot.rows || [])
76
- setResults(snapshot.results || [])
77
- setConfig(snapshot.config || null)
78
- setConfigPath(snapshot.configPath || '')
79
- const next = {}
80
- for (const name of snapshot.selected || []) next[name] = true
81
- setPicked(next)
82
- }).catch((error) => note(String(error && error.message || error), 'bad'))
83
-
84
- React.useEffect(() => { load() }, [])
85
- React.useEffect(() => {
86
- const timer = setInterval(() => {
87
- api('status').then((snapshot) => {
88
- if (snapshot.results) setResults(snapshot.results)
89
- if (!snapshot.task) return
90
- if (snapshot.task.running) note(T('正在执行…', 'Running…'))
91
- else if (snapshot.task.ok === false) note(T(`上次失败 ${snapshot.task.failed} 项`, `Last run failed: ${snapshot.task.failed}`), 'bad')
92
- else note(T('上次完成', 'Last run finished'), 'good')
93
- if (wasRunning.current && !snapshot.task.running) load()
94
- wasRunning.current = snapshot.task.running
95
- }).catch(() => {})
96
- }, 3000)
97
- return () => clearInterval(timer)
98
- }, [])
99
-
100
- const kindLabel = (kind) => kind === 'native'
101
- ? T('手机原生', 'Phone native')
102
- : kind === 'both'
103
- ? T('两端可用', 'Both')
104
- : kind === 'bundle'
105
- ? T('电脑/网页', 'Desktop/web')
106
- : ''
107
- const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
108
- const all = (checked) => {
109
- const next = {}
110
- for (const row of rows) next[row.name] = checked
111
- setPicked(next)
112
- }
113
- const importCode = () => {
114
- if (!code.trim()) { note(T('先粘贴同步码', 'Paste a sync code first'), 'bad'); return }
115
- setBusy(true)
116
- api('import', { code }).then((result) => {
117
- setBusy(false)
118
- if (result.error) { note(result.error, 'bad'); return }
119
- setCode('')
120
- note(T(`已导入 ${result.count} 个插件,选中 ${result.selected} 个`, `Imported ${result.count}, selected ${result.selected}`), 'good')
121
- load()
122
- }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
123
- }
124
- const applySelected = () => {
125
- const names = rows.filter((row) => row.action && picked[row.name]).map((row) => row.name)
126
- if (names.length === 0) { note(T('先选择要安装的插件', 'Select plugins to install'), 'bad'); return }
127
- setBusy(true)
128
- api('apply', { names }).then((result) => {
129
- setBusy(false)
130
- if (result.error) { note(result.error, 'bad'); return }
131
- note(T(`已开始执行 ${result.count} 项`, `Running ${result.count}`), 'good')
132
- }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
133
- }
134
- const setPath = (path, value) => setConfig((previous) => {
135
- const next = { ...previous }
136
- const keys = path.split('.')
137
- let cursor = next
138
- for (let index = 0; index < keys.length - 1; index += 1) {
139
- cursor[keys[index]] = { ...(cursor[keys[index]] || {}) }
140
- cursor = cursor[keys[index]]
141
- }
142
- cursor[keys[keys.length - 1]] = value
143
- return next
144
- })
145
- const runAction = (action, message) => {
146
- setBusy(true)
147
- api('action', { action }).then((result) => {
148
- setBusy(false)
149
- if (result.error) { note(result.error, 'bad'); return }
150
- note(message, 'good')
151
- }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
152
- }
153
- const saveConfig = () => {
154
- if (!config) { note(T('配置还没加载完,稍后再试', 'Configuration is not loaded yet'), 'bad'); return }
155
- setBusy(true)
156
- api('config', { config }).then((result) => {
157
- setBusy(false)
158
- if (result.error) { note(result.error, 'bad'); return }
159
- setConfig(result.config)
160
- setConfigPath(result.path || configPath)
161
- note(T('配置已保存', 'Configuration saved'), 'good')
162
- }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
163
- }
164
-
165
- const relay = config && config.relay ? config.relay : { repo: '', branch: 'main', dir: 'dsh-go-plugins' }
166
- const ssh = config && config.ssh ? config.ssh : { host: '', port: 22, user: '', identity: '', remoteHome: '~/.dsh', dshPath: 'dsh', nodePath: 'node', profile: 'web' }
167
-
168
- return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
169
- h('div', { style: { fontSize: '13px', opacity: 0.7 } },
170
- T('从同步码安装缺少的插件;只增不删,冲突只提示。', 'Install missing plugins from a sync code. Add-only: conflicts are warnings.')),
171
-
172
- h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
173
- h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
174
- h('textarea', {
175
- value: code,
176
- rows: 4,
177
- placeholder: 'DSHSYNC1:…',
178
- onChange: (event) => setCode(event.target.value),
179
- style: { ...INPUT, fontFamily: 'ui-monospace, monospace', minHeight: '80px', resize: 'vertical' },
180
- }),
181
- h('div', { style: { display: 'flex', gap: '8px' } },
182
- h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: importCode }, T('导入同步码', 'Import code')),
183
- h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: load }, T('刷新', 'Refresh')))),
184
-
185
- rows.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
186
- h('div', { style: { fontWeight: 600 } }, T('待处理插件', 'Plugins')),
187
- ...rows.map((row) => h('label', {
188
- key: row.name,
189
- style: { display: 'flex', alignItems: 'center', gap: '8px', padding: '4px 0', opacity: row.action ? 1 : 0.55 },
190
- },
191
- h('input', {
192
- type: 'checkbox',
193
- checked: Boolean(picked[row.name]),
194
- disabled: !row.action,
195
- onChange: (event) => toggle(row.name, event.target.checked),
196
- }),
197
- h('span', { style: { fontWeight: 500 } }, row.name),
198
- row.kind && h('span', { style: BADGE }, kindLabel(row.kind)),
199
- h('span', { style: { marginLeft: 'auto', fontSize: '12px', opacity: 0.65 } }, row.subtitle || row.status))),
200
- h('div', { style: { display: 'flex', gap: '8px', marginTop: '4px' } },
201
- h('button', { type: 'button', style: BUTTON, onClick: () => all(true) }, T('全选', 'Select all')),
202
- h('button', { type: 'button', style: BUTTON, onClick: () => all(false) }, T('清空', 'Clear')),
203
- h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: applySelected }, T('执行选中', 'Run selected')))),
204
-
205
- status && h('div', { style: { fontSize: '13px', color: tone === 'bad' ? '#c62828' : tone === 'good' ? '#2e7d32' : 'inherit' } }, status),
206
- results.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
207
- ...results.map((item) => h('div', {
208
- key: `${item.action || ''}:${item.name}`,
209
- style: { fontSize: '12px', color: item.ok ? '#2e7d32' : '#c62828', wordBreak: 'break-word' },
210
- }, `${item.ok ? '✓' : '✗'} ${item.name}${item.message ? ` — ${item.message}` : ''}`))),
211
-
212
- h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
213
- h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
214
- h(Field, { label: T('仓库地址', 'Repository'), value: relay.repo, onChange: (value) => setPath('relay.repo', value), placeholder: 'https://gitee.com/you/dsh-plugins.git' }),
215
- h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
216
- h(Field, { label: T('分支', 'Branch'), value: relay.branch, onChange: (value) => setPath('relay.branch', value) }),
217
- h(Field, { label: T('目录', 'Directory'), value: relay.dir, onChange: (value) => setPath('relay.dir', value) }))),
218
-
219
- h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
220
- h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('SSH(可选)', 'SSH (optional)')),
221
- h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
222
- h(Field, { label: T('主机', 'Host'), value: ssh.host, onChange: (value) => setPath('ssh.host', value), placeholder: '192.168.1.10' }),
223
- h(Field, { label: T('端口', 'Port'), value: ssh.port, onChange: (value) => setPath('ssh.port', Number(value) || 22), type: 'number' }),
224
- h(Field, { label: T('用户', 'User'), value: ssh.user, onChange: (value) => setPath('ssh.user', value) }),
225
- h(Field, { label: T('私钥路径', 'Identity file'), value: ssh.identity, onChange: (value) => setPath('ssh.identity', value), placeholder: '~/.ssh/id_ed25519' }),
226
- h(Field, { label: T('远端 HOME', 'Remote home'), value: ssh.remoteHome, onChange: (value) => setPath('ssh.remoteHome', value) }),
227
- h(Field, { label: T('profile', 'Profile'), value: ssh.profile, onChange: (value) => setPath('ssh.profile', value) }))),
228
-
229
- h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' } },
230
- h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: saveConfig }, T('保存配置', 'Save configuration')),
231
- configPath && h('span', { style: { fontSize: '12px', opacity: 0.6, wordBreak: 'break-all' } }, configPath)),
232
-
233
- h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
234
- h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, T('同步通道', 'Channels')),
235
- h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap' } },
236
- h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-pull', T('正在拉取中转…', 'Pulling relay…')) }, T('拉取中转', 'Pull relay')),
237
- h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-push', T('正在推送中转…', 'Pushing relay…')) }, T('推送中转', 'Push relay')),
238
- h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-test', T('正在测试 SSH…', 'Testing SSH…')) }, T('测试 SSH', 'Test SSH')),
239
- h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-scan', T('正在拉远端清单…', 'Scanning remote…')) }, T('拉远端清单', 'Scan remote'))),
240
- h('div', { style: { fontSize: '12px', opacity: 0.6, marginTop: '6px' } },
241
- T('先保存配置再执行;SSH 只支持密钥或 agent,Git 使用系统凭据。', 'Save the configuration first. SSH uses a key or agent; Git uses system credentials.'))))
242
- }
243
-
244
- return {
245
- inject: ['slots'],
246
- apply(ctx) {
247
- ctx.slots.inject('settings.section', () => ctx.slots.register({
248
- name: 'settings.section',
249
- id: 'dsh-go-plugin-sync',
250
- order: 50,
251
- label: () => T('插件同步', 'Plugin sync'),
252
- }, SyncSettings))
253
- },
254
- }
255
- },
256
- })
1
+ window.__ModuleLoader__.load({
2
+ id: 'dsh-go-plugin-sync',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const API = '/dsh-go-plugin-sync/api'
7
+ const zh = (navigator.language || '').toLowerCase().indexOf('zh') === 0
8
+ const T = (cn, en) => (zh ? cn : en)
9
+ const INPUT = {
10
+ width: '100%',
11
+ boxSizing: 'border-box',
12
+ padding: '6px 8px',
13
+ borderRadius: '6px',
14
+ border: '1px solid rgba(128,128,128,.35)',
15
+ background: 'transparent',
16
+ color: 'inherit',
17
+ font: 'inherit',
18
+ fontSize: '13px',
19
+ }
20
+ const LABEL = { display: 'block', margin: '8px 0 0', fontSize: '12px', opacity: 0.7 }
21
+ const BUTTON = {
22
+ padding: '6px 12px',
23
+ borderRadius: '6px',
24
+ border: '1px solid rgba(128,128,128,.35)',
25
+ background: 'transparent',
26
+ color: 'inherit',
27
+ font: 'inherit',
28
+ fontSize: '13px',
29
+ cursor: 'pointer',
30
+ }
31
+ const PRIMARY = { ...BUTTON, background: '#3D6FD6', borderColor: '#3D6FD6', color: '#fff' }
32
+ const BADGE = {
33
+ fontSize: '11px',
34
+ lineHeight: '16px',
35
+ padding: '0 6px',
36
+ borderRadius: '8px',
37
+ border: '1px solid rgba(128,128,128,.3)',
38
+ opacity: 0.75,
39
+ }
40
+
41
+ function api(path, body) {
42
+ const options = body === undefined
43
+ ? {}
44
+ : { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }
45
+ return fetch(`${API}/${path}`, options).then((response) => response.json())
46
+ }
47
+
48
+ function Field({ label, value, onChange, placeholder, type }) {
49
+ return h('label', { style: LABEL }, label,
50
+ h('input', {
51
+ type: type || 'text',
52
+ value: value == null ? '' : String(value),
53
+ placeholder: placeholder || '',
54
+ onChange: (event) => onChange(event.target.value),
55
+ style: { ...INPUT, marginTop: '4px' },
56
+ }))
57
+ }
58
+
59
+ function SyncSettings() {
60
+ const [rows, setRows] = React.useState([])
61
+ const [results, setResults] = React.useState([])
62
+ const [picked, setPicked] = React.useState({})
63
+ const [code, setCode] = React.useState('')
64
+ const [config, setConfig] = React.useState(null)
65
+ const [status, setStatus] = React.useState('')
66
+ const [tone, setTone] = React.useState('')
67
+ const [busy, setBusy] = React.useState(false)
68
+ const [configPath, setConfigPath] = React.useState('')
69
+ const [task, setTask] = React.useState(null)
70
+ const [current, setCurrent] = React.useState(null)
71
+ const [cleared, setCleared] = React.useState(false)
72
+ const [queue, setQueue] = React.useState(null)
73
+ const wasRunning = React.useRef(false)
74
+
75
+ const note = (text, kind) => { setStatus(text); setTone(kind || '') }
76
+
77
+ const load = () => api('state').then((snapshot) => {
78
+ if (snapshot.error) { note(snapshot.error, 'bad'); return }
79
+ setRows(snapshot.rows || [])
80
+ setCleared(Boolean(snapshot.cleared))
81
+ setResults(snapshot.results || [])
82
+ setConfig(snapshot.config || null)
83
+ setConfigPath(snapshot.configPath || '')
84
+ const next = {}
85
+ for (const name of snapshot.selected || []) next[name] = true
86
+ setPicked(next)
87
+ }).catch((error) => note(String(error && error.message || error), 'bad'))
88
+
89
+ React.useEffect(() => { load() }, [])
90
+ React.useEffect(() => {
91
+ const tick = () => api('status').then((snapshot) => {
92
+ if (snapshot.results) setResults(snapshot.results)
93
+ setTask(snapshot.task || null)
94
+ setCurrent(snapshot.current || null)
95
+ if (!snapshot.task) return
96
+ if (wasRunning.current && !snapshot.task.running) {
97
+ note(snapshot.task.ok === false
98
+ ? T(`上次失败 ${snapshot.task.failed} 项`, `Last run failed: ${snapshot.task.failed}`)
99
+ : T('上次完成', 'Last run finished'), snapshot.task.ok === false ? 'bad' : 'good')
100
+ load()
101
+ }
102
+ wasRunning.current = Boolean(snapshot.task.running)
103
+ }).catch(() => {})
104
+ tick()
105
+ const timer = setInterval(tick, 1000)
106
+ return () => clearInterval(timer)
107
+ }, [])
108
+
109
+ const kindLabel = (kind) => kind === 'native'
110
+ ? T('手机原生', 'Phone native')
111
+ : kind === 'both'
112
+ ? T('两端可用', 'Both')
113
+ : kind === 'bundle'
114
+ ? T('电脑/网页', 'Desktop/web')
115
+ : ''
116
+ const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
117
+ const installedRows = rows.filter((row) => row.status === 'same')
118
+ const pendingRows = rows.filter((row) => row.status !== 'same')
119
+ const all = (checked) => {
120
+ const next = {}
121
+ for (const row of pendingRows) next[row.name] = checked
122
+ setPicked(next)
123
+ }
124
+ const rowView = (row) => h('label', {
125
+ key: row.name,
126
+ style: { display: 'flex', alignItems: 'center', gap: '8px', padding: '4px 0', opacity: row.action ? 1 : 0.55 },
127
+ },
128
+ h('input', {
129
+ type: 'checkbox',
130
+ checked: Boolean(picked[row.name]),
131
+ disabled: !row.action,
132
+ onChange: (event) => toggle(row.name, event.target.checked),
133
+ }),
134
+ h('span', { style: { fontWeight: 500 } }, row.name),
135
+ row.kind && h('span', { style: BADGE }, kindLabel(row.kind)),
136
+ h('span', { style: { marginLeft: 'auto', fontSize: '12px', opacity: 0.65 } }, row.subtitle || row.status))
137
+ const importCode = () => {
138
+ if (!code.trim()) { note(T('先粘贴同步码', 'Paste a sync code first'), 'bad'); return }
139
+ setBusy(true)
140
+ api('import', { code }).then((result) => {
141
+ setBusy(false)
142
+ if (result.error) { note(result.error, 'bad'); return }
143
+ setCode('')
144
+ note(T(`已导入 ${result.count} 个插件,选中 ${result.selected} 个`, `Imported ${result.count}, selected ${result.selected}`), 'good')
145
+ load()
146
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
147
+ }
148
+ const applySelected = () => {
149
+ const names = rows.filter((row) => row.action && picked[row.name]).map((row) => row.name)
150
+ if (names.length === 0) { note(T('先选择要安装的插件', 'Select plugins to install'), 'bad'); return }
151
+ setBusy(true)
152
+ api('apply', { names }).then((result) => {
153
+ setBusy(false)
154
+ if (result.error) { note(result.error, 'bad'); return }
155
+ setQueue({ names, at: Date.now() })
156
+ setResults([])
157
+ note(T(`已开始执行 ${result.count} 项`, `Running ${result.count}`), 'good')
158
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
159
+ }
160
+ const clearList = () => {
161
+ if (!window.confirm(T('清空待处理插件列表?导入新的同步码后会恢复。', 'Clear the pending list? Import a new sync code to restore it.'))) return
162
+ setBusy(true)
163
+ api('action', { action: 'clear' }).then((result) => {
164
+ setBusy(false)
165
+ if (result.error) { note(result.error, 'bad'); return }
166
+ note(T('列表已清空', 'List cleared'), 'good')
167
+ load()
168
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
169
+ }
170
+ const setPath = (path, value) => setConfig((previous) => {
171
+ const next = { ...previous }
172
+ const keys = path.split('.')
173
+ let cursor = next
174
+ for (let index = 0; index < keys.length - 1; index += 1) {
175
+ cursor[keys[index]] = { ...(cursor[keys[index]] || {}) }
176
+ cursor = cursor[keys[index]]
177
+ }
178
+ cursor[keys[keys.length - 1]] = value
179
+ return next
180
+ })
181
+ const runAction = (action, message) => {
182
+ setBusy(true)
183
+ api('action', { action }).then((result) => {
184
+ setBusy(false)
185
+ if (result.error) { note(result.error, 'bad'); return }
186
+ note(message, 'good')
187
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
188
+ }
189
+ const saveConfig = () => {
190
+ if (!config) { note(T('配置还没加载完,稍后再试', 'Configuration is not loaded yet'), 'bad'); return }
191
+ setBusy(true)
192
+ api('config', { config }).then((result) => {
193
+ setBusy(false)
194
+ if (result.error) { note(result.error, 'bad'); return }
195
+ setConfig(result.config)
196
+ setConfigPath(result.path || configPath)
197
+ note(T('配置已保存', 'Configuration saved'), 'good')
198
+ }).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
199
+ }
200
+
201
+ const relay = config && config.relay ? config.relay : { repo: '', branch: 'main', dir: 'dsh-go-plugins' }
202
+ const ssh = config && config.ssh ? config.ssh : { host: '', port: 22, user: '', identity: '', remoteHome: '~/.dsh', dshPath: 'dsh', nodePath: 'node', profile: 'web' }
203
+
204
+ const running = Boolean(task && task.running)
205
+ const doneCount = results.length
206
+ const total = queue && Array.isArray(queue.names) ? queue.names.length : 0
207
+ const elapsed = running && task && task.startedAt ? Math.max(0, Math.round((Date.now() - task.startedAt) / 1000)) : 0
208
+ const actionLabel = (kind) => kind === 'install' ? T('安装', 'install') : kind === 'apply' ? T('同步', 'sync') : T('执行', 'run')
209
+ const progress = task && h('div', {
210
+ style: {
211
+ display: 'flex', flexDirection: 'column', gap: '6px', padding: '10px 12px', borderRadius: '8px',
212
+ border: '1px solid rgba(61,111,214,.35)', background: 'rgba(61,111,214,.06)',
213
+ },
214
+ },
215
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '13px', fontWeight: 600 } },
216
+ running
217
+ ? T(`${actionLabel(task.kind)}中${current ? `:${current.name}` : '(准备中)'}`, `${actionLabel(task.kind)}${current ? `: ${current.name}` : ' (preparing)'}`)
218
+ : T(`上次${actionLabel(task.kind)}结束`, `Last ${actionLabel(task.kind)} ended`),
219
+ running && h('span', { style: { marginLeft: 'auto', fontSize: '12px', fontWeight: 400, opacity: 0.7 } }, `${elapsed}s`)),
220
+ running && h('div', { style: { height: '4px', borderRadius: '2px', background: 'rgba(128,128,128,.25)', overflow: 'hidden' } },
221
+ h('div', {
222
+ style: {
223
+ height: '100%',
224
+ width: total > 0 ? `${Math.min(100, Math.round((doneCount / total) * 100))}%` : '15%',
225
+ background: '#3D6FD6',
226
+ transition: 'width .3s',
227
+ },
228
+ })),
229
+ h('div', { style: { fontSize: '12px', opacity: 0.8 } },
230
+ running
231
+ ? T(`已完成 ${doneCount}${total > 0 ? ` / ${total}` : ''} 项${current ? `,正在处理 ${current.name}` : ''}`, `Done ${doneCount}${total > 0 ? ` / ${total}` : ''}${current ? `, processing ${current.name}` : ''}`)
232
+ : T(`成功 ${results.filter((item) => item.ok).length} 项,失败 ${results.filter((item) => !item.ok).length} 项`, `${results.filter((item) => item.ok).length} ok, ${results.filter((item) => !item.ok).length} failed`)),
233
+ running && elapsed >= 30 && h('div', { style: { fontSize: '12px', opacity: 0.65 } },
234
+ T('插件从 npm 下载,网络慢时可能要几分钟,请保持页面打开。', 'Plugins come from npm; slow networks can take minutes. Keep this page open.')))
235
+
236
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
237
+ h('div', { style: { fontSize: '13px', opacity: 0.7 } },
238
+ T('从同步码安装缺少的插件;只增不删,冲突只提示。', 'Install missing plugins from a sync code. Add-only: conflicts are warnings.')),
239
+
240
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
241
+ h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
242
+ h('textarea', {
243
+ value: code,
244
+ rows: 4,
245
+ placeholder: 'DSHSYNC1:…',
246
+ onChange: (event) => setCode(event.target.value),
247
+ style: { ...INPUT, fontFamily: 'ui-monospace, monospace', minHeight: '80px', resize: 'vertical' },
248
+ }),
249
+ h('div', { style: { display: 'flex', gap: '8px' } },
250
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: importCode }, T('导入同步码', 'Import code')),
251
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: load }, T('刷新', 'Refresh')))),
252
+
253
+ cleared && h('div', { style: { fontSize: '12px', opacity: 0.6 } },
254
+ T('待处理列表已清空,重新导入同步码后会恢复。', 'The pending list was cleared. Import a new sync code to restore it.')),
255
+
256
+ pendingRows.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
257
+ h('div', { style: { fontWeight: 600 } }, T('待处理插件', 'Pending plugins')),
258
+ ...pendingRows.map(rowView),
259
+ h('div', { style: { display: 'flex', gap: '8px', marginTop: '4px', flexWrap: 'wrap' } },
260
+ h('button', { type: 'button', style: BUTTON, onClick: () => all(true) }, T('全选', 'Select all')),
261
+ h('button', { type: 'button', style: BUTTON, onClick: () => all(false) }, T('取消全选', 'Deselect all')),
262
+ h('button', { type: 'button', style: PRIMARY, disabled: busy || running, onClick: applySelected }, T('执行选中', 'Run selected')),
263
+ h('button', { type: 'button', style: BUTTON, disabled: busy || running, onClick: clearList }, T('清空列表', 'Clear list')))),
264
+
265
+ installedRows.length > 0 && h('details', { style: { fontSize: '13px' } },
266
+ h('summary', { style: { cursor: 'pointer', opacity: 0.7 } },
267
+ T(`已安装 ${installedRows.length} 个(点击展开)`, `${installedRows.length} installed (expand)`)),
268
+ h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px', marginTop: '6px' } },
269
+ ...installedRows.map(rowView))),
270
+
271
+ progress,
272
+
273
+ status && h('div', { style: { fontSize: '13px', color: tone === 'bad' ? '#c62828' : tone === 'good' ? '#2e7d32' : 'inherit' } }, status),
274
+
275
+ results.length > 0 && h('div', { style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
276
+ ...results.map((item) => h('div', {
277
+ key: `${item.action || ''}:${item.name}`,
278
+ style: { fontSize: '12px', color: item.ok ? '#2e7d32' : '#c62828', wordBreak: 'break-word' },
279
+ }, `${item.ok ? '✓' : '✗'} ${item.name}${item.message ? ` — ${item.message}` : ''}`))),
280
+
281
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
282
+ h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('Git 中转(可选)', 'Git relay (optional)')),
283
+ h(Field, { label: T('仓库地址', 'Repository'), value: relay.repo, onChange: (value) => setPath('relay.repo', value), placeholder: 'https://gitee.com/you/dsh-plugins.git' }),
284
+ h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
285
+ h(Field, { label: T('分支', 'Branch'), value: relay.branch, onChange: (value) => setPath('relay.branch', value) }),
286
+ h(Field, { label: T('目录', 'Directory'), value: relay.dir, onChange: (value) => setPath('relay.dir', value) }))),
287
+
288
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
289
+ h('div', { style: { fontWeight: 600, marginBottom: '4px' } }, T('SSH(可选)', 'SSH (optional)')),
290
+ h('div', { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' } },
291
+ h(Field, { label: T('主机', 'Host'), value: ssh.host, onChange: (value) => setPath('ssh.host', value), placeholder: '192.168.1.10' }),
292
+ h(Field, { label: T('端口', 'Port'), value: ssh.port, onChange: (value) => setPath('ssh.port', Number(value) || 22), type: 'number' }),
293
+ h(Field, { label: T('用户', 'User'), value: ssh.user, onChange: (value) => setPath('ssh.user', value) }),
294
+ h(Field, { label: T('私钥路径', 'Identity file'), value: ssh.identity, onChange: (value) => setPath('ssh.identity', value), placeholder: '~/.ssh/id_ed25519' }),
295
+ h(Field, { label: T('远端 HOME', 'Remote home'), value: ssh.remoteHome, onChange: (value) => setPath('ssh.remoteHome', value) }),
296
+ h(Field, { label: T('profile', 'Profile'), value: ssh.profile, onChange: (value) => setPath('ssh.profile', value) }))),
297
+
298
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px', flexWrap: 'wrap' } },
299
+ h('button', { type: 'button', style: PRIMARY, disabled: busy, onClick: saveConfig }, T('保存配置', 'Save configuration')),
300
+ configPath && h('span', { style: { fontSize: '12px', opacity: 0.6, wordBreak: 'break-all' } }, configPath)),
301
+
302
+ h('div', { style: { borderTop: '1px solid rgba(128,128,128,.2)', paddingTop: '12px' } },
303
+ h('div', { style: { fontWeight: 600, marginBottom: '6px' } }, T('同步通道', 'Channels')),
304
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap' } },
305
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-pull', T('正在拉取中转…', 'Pulling relay…')) }, T('拉取中转', 'Pull relay')),
306
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('relay-push', T('正在推送中转…', 'Pushing relay…')) }, T('推送中转', 'Push relay')),
307
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-test', T('正在测试 SSH…', 'Testing SSH…')) }, T('测试 SSH', 'Test SSH')),
308
+ h('button', { type: 'button', style: BUTTON, disabled: busy, onClick: () => runAction('ssh-scan', T('正在拉远端清单…', 'Scanning remote…')) }, T('拉远端清单', 'Scan remote'))),
309
+ h('div', { style: { fontSize: '12px', opacity: 0.6, marginTop: '6px' } },
310
+ T('先保存配置再执行;SSH 只支持密钥或 agent,Git 使用系统凭据。', 'Save the configuration first. SSH uses a key or agent; Git uses system credentials.'))))
311
+ }
312
+
313
+ return {
314
+ inject: ['slots'],
315
+ apply(ctx) {
316
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
317
+ name: 'settings.section',
318
+ id: 'dsh-go-plugin-sync',
319
+ order: 50,
320
+ label: () => T('插件同步', 'Plugin sync'),
321
+ }, SyncSettings))
322
+ },
323
+ }
324
+ },
325
+ })