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/CHANGELOG.md +135 -112
- package/README.md +149 -149
- package/cordis.patch.yml +4 -4
- package/lib/client.js +325 -256
- package/lib/index.js +2062 -1938
- package/package.json +102 -102
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
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
setBusy(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
h('div', {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
h('div', { style: {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
h('div', { style: {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
+
})
|