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