dsh-go-plugin-sync 0.4.0 → 0.4.2
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 +14 -0
- package/lib/client.js +21 -5
- package/lib/index.js +98 -38
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.2 — 2026-12-04
|
|
4
|
+
|
|
5
|
+
### 修复
|
|
6
|
+
- 任务卡死可处理:任务状态里记录进程号,电脑端与 dsh-go 面板的进行中任务旁新增「取消任务」,会终止任务进程并把状态标记为已取消
|
|
7
|
+
- 单个安装命令超过 600 秒自动终止并记为失败(此前 pnpm 卡住时任务会一直显示运行中),POSIX 上使用 `timeout`,Windows 的 Node 任务器内置同样的超时
|
|
8
|
+
- 待处理列表把可安装项排在前面,不能安装的项在电脑端保持浅色弱化,dsh-go 面板同样按可安装优先排序
|
|
9
|
+
|
|
10
|
+
## 0.4.1 — 2026-12-04
|
|
11
|
+
|
|
12
|
+
### 改进
|
|
13
|
+
- 导入同步码 / 清单文件 / 拉取中转或 SSH 后,只自动选中“双端兼容(kind=both)且本机还没装”的插件,其余保持不选
|
|
14
|
+
- 每个插件的兼容与状态提示缩短,例如「1.2.3 · 可安装」「1.2.3 · npm 安装」
|
|
15
|
+
- 冲突项以本机为准:不再提示更新,更新交给 DSH 本体处理;电脑端与 dsh-go 面板文案同步
|
|
16
|
+
|
|
3
17
|
## 0.4.0 — 2026-12-04
|
|
4
18
|
|
|
5
19
|
0.3.10 之后的功能合并发布(npm 从 0.3.6 直接到本版)。
|
package/lib/client.js
CHANGED
|
@@ -111,15 +111,16 @@ window.__ModuleLoader__.load({
|
|
|
111
111
|
}, [])
|
|
112
112
|
|
|
113
113
|
const kindLabel = (kind) => kind === 'native'
|
|
114
|
-
? T('
|
|
114
|
+
? T('手机端', 'Phone')
|
|
115
115
|
: kind === 'both'
|
|
116
|
-
? T('
|
|
116
|
+
? T('双端', 'Both')
|
|
117
117
|
: kind === 'bundle'
|
|
118
|
-
? T('
|
|
118
|
+
? T('电脑端', 'Desktop')
|
|
119
119
|
: ''
|
|
120
120
|
const toggle = (name, checked) => setPicked((previous) => ({ ...previous, [name]: checked }))
|
|
121
121
|
const installedRows = rows.filter((row) => row.status === 'same')
|
|
122
122
|
const pendingRows = rows.filter((row) => row.status !== 'same')
|
|
123
|
+
.slice().sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
|
|
123
124
|
const all = (checked) => {
|
|
124
125
|
const next = {}
|
|
125
126
|
for (const row of pendingRows) next[row.name] = checked
|
|
@@ -193,6 +194,16 @@ window.__ModuleLoader__.load({
|
|
|
193
194
|
load()
|
|
194
195
|
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
195
196
|
}
|
|
197
|
+
const stopRun = () => {
|
|
198
|
+
if (!window.confirm(T('取消当前任务?已完成的项不会回滚。', 'Stop the running task? Finished items are not rolled back.'))) return
|
|
199
|
+
setBusy(true)
|
|
200
|
+
api('action', { action: 'stop' }).then((result) => {
|
|
201
|
+
setBusy(false)
|
|
202
|
+
if (result.error) { note(result.error, 'bad'); return }
|
|
203
|
+
note(T('已取消任务', 'Task cancelled'), 'good')
|
|
204
|
+
load()
|
|
205
|
+
}).catch((error) => { setBusy(false); note(String(error && error.message || error), 'bad') })
|
|
206
|
+
}
|
|
196
207
|
const setPath = (path, value) => setConfig((previous) => {
|
|
197
208
|
const next = { ...previous }
|
|
198
209
|
const keys = path.split('.')
|
|
@@ -242,7 +253,12 @@ window.__ModuleLoader__.load({
|
|
|
242
253
|
running
|
|
243
254
|
? T(`${actionLabel(task.kind)}中${current ? `:${current.name}` : '(准备中)'}`, `${actionLabel(task.kind)}${current ? `: ${current.name}` : ' (preparing)'}`)
|
|
244
255
|
: T(`上次${actionLabel(task.kind)}结束`, `Last ${actionLabel(task.kind)} ended`),
|
|
245
|
-
running && h('
|
|
256
|
+
running && h('button', {
|
|
257
|
+
type: 'button',
|
|
258
|
+
style: { ...BUTTON, marginLeft: 'auto', padding: '1px 8px', fontSize: '12px' },
|
|
259
|
+
onClick: stopRun,
|
|
260
|
+
}, T('取消任务', 'Stop')),
|
|
261
|
+
running && h('span', { style: { fontSize: '12px', fontWeight: 400, opacity: 0.7 } }, `${elapsed}s`)),
|
|
246
262
|
running && h('div', { style: { height: '4px', borderRadius: '2px', background: 'rgba(128,128,128,.25)', overflow: 'hidden' } },
|
|
247
263
|
h('div', {
|
|
248
264
|
style: {
|
|
@@ -261,7 +277,7 @@ window.__ModuleLoader__.load({
|
|
|
261
277
|
|
|
262
278
|
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '14px', maxWidth: '760px' } },
|
|
263
279
|
h('div', { style: { fontSize: '13px', opacity: 0.7 } },
|
|
264
|
-
T('
|
|
280
|
+
T('从同步码安装缺少的插件;已有版本不动,冲突以本机为准,更新交给 DSH 本体。', 'Install missing plugins from a sync code; conflicts keep the local copy and updates are left to DSH.')),
|
|
265
281
|
|
|
266
282
|
h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
267
283
|
h('div', { style: { fontWeight: 600 } }, T('同步码', 'Sync code')),
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { spawn } from 'node:child_process'
|
|
16
16
|
import { createHash } from 'node:crypto'
|
|
17
17
|
import {
|
|
18
|
-
accessSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
|
|
18
|
+
accessSync, appendFileSync, constants, existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync,
|
|
19
19
|
} from 'node:fs'
|
|
20
20
|
import { homedir } from 'node:os'
|
|
21
21
|
import { basename, dirname, extname, join, relative, resolve, sep } from 'node:path'
|
|
@@ -267,7 +267,7 @@ function codeFromSubmit(value) {
|
|
|
267
267
|
return ''
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
/** Decode a sync code, materialize files, and preselect
|
|
270
|
+
/** Decode a sync code, materialize files, and preselect double-end plugins missing here. */
|
|
271
271
|
function applySyncCode(scope, text, sourceName, host = {}) {
|
|
272
272
|
const decoded = decodeSyncCode(text)
|
|
273
273
|
if (decoded.error) return { error: decoded.error }
|
|
@@ -281,16 +281,7 @@ function applySyncCode(scope, text, sourceName, host = {}) {
|
|
|
281
281
|
resetUiState()
|
|
282
282
|
writeCodeFiles(decoded)
|
|
283
283
|
const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, host)
|
|
284
|
-
const
|
|
285
|
-
state.selected.clear()
|
|
286
|
-
let selected = 0
|
|
287
|
-
for (const row of rows) {
|
|
288
|
-
if (!manifestNames.has(row.name)) continue
|
|
289
|
-
if (!row.action) continue
|
|
290
|
-
if (host.dshGo === true && row.kind === 'bundle') continue
|
|
291
|
-
state.selected.add(row.name)
|
|
292
|
-
selected++
|
|
293
|
-
}
|
|
284
|
+
const selected = preselectRows(state, host)
|
|
294
285
|
return {
|
|
295
286
|
count: decoded.manifest.plugins.length,
|
|
296
287
|
selected,
|
|
@@ -620,6 +611,21 @@ function diffRows(local, manifest, source, host = {}) {
|
|
|
620
611
|
return rows
|
|
621
612
|
}
|
|
622
613
|
|
|
614
|
+
/** Auto-select only double-end plugins (kind=both) that this host does not have yet. */
|
|
615
|
+
function preselectRows(state, host = {}) {
|
|
616
|
+
const rows = diffRows(localPlugins(), state.manifest, state.manifestSource, host)
|
|
617
|
+
const names = new Set((state.manifest?.plugins ?? []).map((plugin) => plugin.name))
|
|
618
|
+
state.selected.clear()
|
|
619
|
+
for (const row of rows) {
|
|
620
|
+
if (!names.has(row.name)) continue
|
|
621
|
+
if (row.kind !== 'both') continue
|
|
622
|
+
if (row.status !== 'installable') continue
|
|
623
|
+
if (!row.action) continue
|
|
624
|
+
state.selected.add(row.name)
|
|
625
|
+
}
|
|
626
|
+
return state.selected.size
|
|
627
|
+
}
|
|
628
|
+
|
|
623
629
|
// ---------------------------------------------------------------- state
|
|
624
630
|
|
|
625
631
|
function stateKey(scope) {
|
|
@@ -675,7 +681,7 @@ function loadManifestFrom(path, kind, pluginsDir) {
|
|
|
675
681
|
}
|
|
676
682
|
|
|
677
683
|
/** Refresh the state manifest from relay / ssh results when those files are newer. */
|
|
678
|
-
function refreshManifests(state, cfg) {
|
|
684
|
+
function refreshManifests(state, cfg, host = {}) {
|
|
679
685
|
const relay = loadManifestFrom(relayManifestFile(), 'relay', join(relayWorkDir(), cfg.relay.dir, 'plugins'))
|
|
680
686
|
if (relay?.manifest && relay.manifest.plugins.length > 0 && relay.mtime > state.relayLoadedAt) {
|
|
681
687
|
state.manifest = relay.manifest
|
|
@@ -684,7 +690,7 @@ function refreshManifests(state, cfg) {
|
|
|
684
690
|
state.sourceName = 'Git 中转'
|
|
685
691
|
state.showAll = false
|
|
686
692
|
state.relayLoadedAt = relay.mtime
|
|
687
|
-
state
|
|
693
|
+
preselectRows(state, host)
|
|
688
694
|
}
|
|
689
695
|
const ssh = loadManifestFrom(sshManifestFile(), 'ssh', null)
|
|
690
696
|
if (ssh?.manifest && ssh.manifest.plugins.length > 0 && ssh.mtime > state.sshLoadedAt) {
|
|
@@ -694,7 +700,7 @@ function refreshManifests(state, cfg) {
|
|
|
694
700
|
state.sourceName = 'SSH 远端'
|
|
695
701
|
state.showAll = false
|
|
696
702
|
state.sshLoadedAt = ssh.mtime
|
|
697
|
-
state
|
|
703
|
+
preselectRows(state, host)
|
|
698
704
|
}
|
|
699
705
|
}
|
|
700
706
|
|
|
@@ -704,7 +710,7 @@ function readTaskStatus() {
|
|
|
704
710
|
try {
|
|
705
711
|
const parts = readFileSync(taskStatusPath(), 'utf8').trim().split(/\s+/)
|
|
706
712
|
const started = Number(parts[1]) || 0
|
|
707
|
-
if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '' }
|
|
713
|
+
if (parts[0] === 'running') return { running: true, startedAt: started * 1000, kind: parts[2] || '', pid: Number(parts[3]) || 0 }
|
|
708
714
|
if (parts[0] === 'done') {
|
|
709
715
|
const failed = Number(parts[2]) || 0
|
|
710
716
|
return { running: false, finishedAt: started * 1000, failed, kind: parts[3] || '', ok: failed === 0 }
|
|
@@ -792,6 +798,34 @@ function taskRunning() {
|
|
|
792
798
|
return Boolean(status?.running && Date.now() - status.startedAt < 15 * 60 * 1000)
|
|
793
799
|
}
|
|
794
800
|
|
|
801
|
+
/** Kill the running task (its status line carries the pid) and mark it cancelled. */
|
|
802
|
+
function stopTask() {
|
|
803
|
+
const status = readTaskStatus()
|
|
804
|
+
if (!status?.running) return { ok: false, error: '没有在运行的任务' }
|
|
805
|
+
const pid = Number(status.pid) || 0
|
|
806
|
+
if (pid > 0) {
|
|
807
|
+
try {
|
|
808
|
+
if (process.platform === 'win32') {
|
|
809
|
+
spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore' })
|
|
810
|
+
} else {
|
|
811
|
+
try { process.kill(-pid, 'SIGTERM') } catch { try { process.kill(pid, 'SIGTERM') } catch {} }
|
|
812
|
+
}
|
|
813
|
+
} catch {}
|
|
814
|
+
}
|
|
815
|
+
const current = readTaskCurrent()
|
|
816
|
+
try {
|
|
817
|
+
let note = `@@ stop ${Math.floor(Date.now() / 1000)}\n`
|
|
818
|
+
if (current) note += `@@ ${current.action} ${current.name} fail\n`
|
|
819
|
+
note += '任务被用户取消\n'
|
|
820
|
+
appendFileSync(taskLogPath(), note)
|
|
821
|
+
} catch {}
|
|
822
|
+
const failed = readTaskResults().filter((result) => !result.ok).length
|
|
823
|
+
try {
|
|
824
|
+
writeFileSync(taskStatusPath(), `done ${Math.floor(Date.now() / 1000)} ${Math.max(1, failed)} ${status.kind || 'apply'}\n`)
|
|
825
|
+
} catch {}
|
|
826
|
+
return { ok: true, pid }
|
|
827
|
+
}
|
|
828
|
+
|
|
795
829
|
/** Start one background task; returns `{ ok }` or an explanation of why it did not start. */
|
|
796
830
|
function startTask(kind, lines, win) {
|
|
797
831
|
if (taskRunning()) return { ok: false, error: '已有任务在运行,等它结束再试' }
|
|
@@ -804,7 +838,9 @@ function startTask(kind, lines, win) {
|
|
|
804
838
|
`STATUS=${shQuote(taskStatusPath())}`,
|
|
805
839
|
`PROFILE=${shQuote(profileName())}`,
|
|
806
840
|
'DSH_BIN="${DSH_BIN:-$(command -v dsh || echo /usr/local/bin/dsh)}"',
|
|
841
|
+
'TIMEOUT=""; if command -v timeout >/dev/null 2>&1; then TIMEOUT="timeout 600"; fi',
|
|
807
842
|
': > "$LOG"',
|
|
843
|
+
`echo "running $(date +%s) ${kind} $$" > "$STATUS"`,
|
|
808
844
|
'failed=0',
|
|
809
845
|
'say() { echo "$@" >> "$LOG"; }',
|
|
810
846
|
...lines,
|
|
@@ -871,10 +907,15 @@ const spec = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))
|
|
|
871
907
|
const log = fs.openSync(spec.log, 'w')
|
|
872
908
|
const say = (line) => fs.writeSync(log, line + '\\n')
|
|
873
909
|
const status = (line) => fs.writeFileSync(spec.status, line + '\\n')
|
|
874
|
-
status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind)
|
|
910
|
+
status('running ' + Math.floor(Date.now() / 1000) + ' ' + spec.kind + ' ' + process.pid)
|
|
875
911
|
function run(command, args) {
|
|
876
912
|
return new Promise((resolve) => {
|
|
877
913
|
let child
|
|
914
|
+
let timer = null
|
|
915
|
+
const finish = (code) => {
|
|
916
|
+
if (timer) { clearTimeout(timer); timer = null }
|
|
917
|
+
resolve(code)
|
|
918
|
+
}
|
|
878
919
|
try {
|
|
879
920
|
child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env })
|
|
880
921
|
} catch (error) {
|
|
@@ -882,10 +923,15 @@ function run(command, args) {
|
|
|
882
923
|
resolve(1)
|
|
883
924
|
return
|
|
884
925
|
}
|
|
926
|
+
timer = setTimeout(() => {
|
|
927
|
+
say('超过 600 秒没有结束,终止:' + command + ' ' + args.join(' '))
|
|
928
|
+
try { child.kill() } catch {}
|
|
929
|
+
finish(1)
|
|
930
|
+
}, 600000)
|
|
885
931
|
child.stdout.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
886
932
|
child.stderr.on('data', (chunk) => fs.writeSync(log, chunk))
|
|
887
|
-
child.on('error', (error) => { say(String(error && error.message ? error.message : error));
|
|
888
|
-
child.on('exit', (code) =>
|
|
933
|
+
child.on('error', (error) => { say(String(error && error.message ? error.message : error)); finish(1) })
|
|
934
|
+
child.on('exit', (code) => finish(code === 0 ? 0 : 1))
|
|
889
935
|
})
|
|
890
936
|
}
|
|
891
937
|
;(async () => {
|
|
@@ -910,7 +956,7 @@ function run(command, args) {
|
|
|
910
956
|
}
|
|
911
957
|
|
|
912
958
|
function localAddCommand(dir) {
|
|
913
|
-
return
|
|
959
|
+
return `\${TIMEOUT} "$DSH_BIN" plugin --profile "$PROFILE" add ${shQuote(dir)}`
|
|
914
960
|
}
|
|
915
961
|
|
|
916
962
|
/** The plugin manager reports a failed operation as `error` + `application:"failed"`, not `ok:false`. */
|
|
@@ -1330,20 +1376,20 @@ function enableText(caps) {
|
|
|
1330
1376
|
function statusLine(row, en) {
|
|
1331
1377
|
let text = {
|
|
1332
1378
|
same: en ? 'same' : '一致',
|
|
1333
|
-
conflict: en ? '
|
|
1334
|
-
install: en ? 'not installed
|
|
1335
|
-
installable: en ? '
|
|
1336
|
-
missing: en ? 'files
|
|
1337
|
-
extra: en ? 'not
|
|
1338
|
-
push: en ? '
|
|
1339
|
-
'native-only': en ? 'phone-only
|
|
1340
|
-
'web-only': en ? '
|
|
1379
|
+
conflict: en ? 'local wins' : '本机优先',
|
|
1380
|
+
install: en ? 'not installed' : '未安装',
|
|
1381
|
+
installable: en ? 'ready' : '可安装',
|
|
1382
|
+
missing: en ? 'no files' : '缺文件',
|
|
1383
|
+
extra: en ? 'not listed' : '清单外',
|
|
1384
|
+
push: en ? 'pushable' : '可推送',
|
|
1385
|
+
'native-only': en ? 'phone-only' : '手机专用',
|
|
1386
|
+
'web-only': en ? 'web-only' : '电脑/网页专用',
|
|
1341
1387
|
}[row.status] || row.status
|
|
1342
1388
|
if (row.status !== 'web-only' && row.status !== 'native-only') {
|
|
1343
|
-
if (row.action === 'install' && row.registrySpec) text = en ? '
|
|
1344
|
-
else if (row.action === 'install' && row.localDir) text = en ? '
|
|
1345
|
-
else if (row.action === 'pull') text = en ? '
|
|
1346
|
-
else if (row.action === 'push-npm') text = en ? 'remote
|
|
1389
|
+
if (row.action === 'install' && row.registrySpec) text = en ? 'via npm' : 'npm 安装'
|
|
1390
|
+
else if (row.action === 'install' && row.localDir) text = en ? 'via files' : '文件安装'
|
|
1391
|
+
else if (row.action === 'pull') text = en ? 'from remote' : '远端拉取'
|
|
1392
|
+
else if (row.action === 'push-npm') text = en ? 'remote via npm' : '远端 npm'
|
|
1347
1393
|
}
|
|
1348
1394
|
const version = row.status === 'conflict' && row.remoteVersion && row.remoteVersion !== row.version
|
|
1349
1395
|
? `${row.version} → ${row.remoteVersion}`
|
|
@@ -1374,7 +1420,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1374
1420
|
const en = enableText(caps)
|
|
1375
1421
|
const cfg = loadConfig(ctx, scope)
|
|
1376
1422
|
const state = stateFor(scope)
|
|
1377
|
-
refreshManifests(state, cfg)
|
|
1423
|
+
refreshManifests(state, cfg, { dshGo: true })
|
|
1378
1424
|
const local = localPluginsCached()
|
|
1379
1425
|
const rows = diffRows(local, state.manifest, state.manifestSource, { dshGo: true })
|
|
1380
1426
|
const components = Array.isArray(caps?.components) ? caps.components : []
|
|
@@ -1382,8 +1428,8 @@ function buildView(scope, caps, ctx) {
|
|
|
1382
1428
|
const children = []
|
|
1383
1429
|
|
|
1384
1430
|
children.push({ type: 'text', text: en
|
|
1385
|
-
? 'Copy a sync code (all or selected), or paste one below. Sync only installs missing plugins;
|
|
1386
|
-
: '
|
|
1431
|
+
? 'Copy a sync code (all or selected), or paste one below. Sync only installs missing plugins; conflicts keep the local copy, updates are left to DSH.'
|
|
1432
|
+
: '复制同步码(全部或选中),或在下面粘贴导入。同步只安装缺少的插件,已有版本不动;冲突以本机为准,更新交给 DSH 本体。' })
|
|
1387
1433
|
|
|
1388
1434
|
if (canForm) {
|
|
1389
1435
|
children.push({ type: 'form', submit: 'import-code', submitLabel: en ? 'Import code' : '导入同步码', children: [
|
|
@@ -1429,7 +1475,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1429
1475
|
en ? `elapsed ${elapsed}` : `已用 ${elapsed}`,
|
|
1430
1476
|
].filter(Boolean).join(' · ')
|
|
1431
1477
|
children.push({ type: 'callout', tone: stale ? 'warn' : 'info', text: stale
|
|
1432
|
-
? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log.` : `${taskLabel(task.kind, false)}运行太久(${progressText}
|
|
1478
|
+
? (en ? `${taskLabel(task.kind, true)} running too long (${progressText}); check the log, or tap Stop task.` : `${taskLabel(task.kind, false)}运行太久(${progressText}),看下日志,或点「取消任务」。`)
|
|
1433
1479
|
: (en ? `${taskLabel(task.kind, true)} running: ${progressText}` : `${taskLabel(task.kind, false)}中:${progressText}`) })
|
|
1434
1480
|
} else if (task && task.ok === false) {
|
|
1435
1481
|
children.push({ type: 'callout', tone: 'bad', text: en
|
|
@@ -1487,7 +1533,8 @@ function buildView(scope, caps, ctx) {
|
|
|
1487
1533
|
|
|
1488
1534
|
const pending = rows.filter((row) => row.status !== 'same')
|
|
1489
1535
|
const installed = rows.filter((row) => row.status === 'same')
|
|
1490
|
-
const visible = state.showAll ? rows : pending
|
|
1536
|
+
const visible = (state.showAll ? rows : pending).slice()
|
|
1537
|
+
.sort((a, b) => Number(Boolean(b.action)) - Number(Boolean(a.action)))
|
|
1491
1538
|
if (rows.length === 0) {
|
|
1492
1539
|
children.push({ type: 'callout', tone: 'good', text: en ? 'The two hosts match.' : '两边完全一致。' })
|
|
1493
1540
|
} else {
|
|
@@ -1521,6 +1568,7 @@ function buildView(scope, caps, ctx) {
|
|
|
1521
1568
|
}
|
|
1522
1569
|
|
|
1523
1570
|
const primary = [
|
|
1571
|
+
...(task?.running ? [{ label: en ? 'Stop task' : '取消任务', action: 'stop-task' }] : []),
|
|
1524
1572
|
{ label: en ? 'Copy code' : '复制同步码', action: 'copy-code' },
|
|
1525
1573
|
{ label: en ? 'Select all' : '全选', action: 'select-all' },
|
|
1526
1574
|
{ label: en ? 'Clear' : '清空', action: 'clear' },
|
|
@@ -1660,7 +1708,7 @@ function webSnapshot(ctx) {
|
|
|
1660
1708
|
const scope = { sessionId: 'web-ui' }
|
|
1661
1709
|
const state = stateFor(scope)
|
|
1662
1710
|
const cfg = loadConfig(ctx, scope)
|
|
1663
|
-
refreshManifests(state, cfg)
|
|
1711
|
+
refreshManifests(state, cfg, { dshGo: Boolean(ctx.get?.('dshGo')) })
|
|
1664
1712
|
const local = localPlugins()
|
|
1665
1713
|
const cleared = uiCleared()
|
|
1666
1714
|
const rows = cleared
|
|
@@ -1817,6 +1865,12 @@ export function apply(ctx) {
|
|
|
1817
1865
|
actions: {
|
|
1818
1866
|
'copy-code': copyCode,
|
|
1819
1867
|
|
|
1868
|
+
'stop-task'() {
|
|
1869
|
+
const result = stopTask()
|
|
1870
|
+
if (!result.ok) return { toast: result.error || '没有在运行的任务' }
|
|
1871
|
+
return [{ toast: '已取消任务' }, { refresh: true }]
|
|
1872
|
+
},
|
|
1873
|
+
|
|
1820
1874
|
'import-code'(scope, event) {
|
|
1821
1875
|
const text = codeFromSubmit(event?.value)
|
|
1822
1876
|
if (text === '') return { toast: '先粘贴同步码' }
|
|
@@ -1995,6 +2049,7 @@ export function apply(ctx) {
|
|
|
1995
2049
|
state.selected.clear()
|
|
1996
2050
|
persistImported(state)
|
|
1997
2051
|
resetUiState()
|
|
2052
|
+
preselectRows(state, { dshGo: true })
|
|
1998
2053
|
return [{ toast: `已导入 ${manifest.plugins.length} 个插件` }, { refresh: true }]
|
|
1999
2054
|
}
|
|
2000
2055
|
})
|
|
@@ -2026,6 +2081,11 @@ export function apply(ctx) {
|
|
|
2026
2081
|
webJson(res, 200, { ok: true })
|
|
2027
2082
|
return
|
|
2028
2083
|
}
|
|
2084
|
+
if (action === 'stop') {
|
|
2085
|
+
const result = stopTask()
|
|
2086
|
+
webJson(res, 200, result.ok ? { ok: true } : { error: result.error || '没有在运行的任务' })
|
|
2087
|
+
return
|
|
2088
|
+
}
|
|
2029
2089
|
if (action === 'relay-pull') {
|
|
2030
2090
|
if (!cfg.relay.repo) { webJson(res, 200, { error: '先配置中转仓' }); return }
|
|
2031
2091
|
state.relayLoadedAt = 0
|