dsh-plugin-update-center 1.0.5 → 1.0.7
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/client.js +43 -23
- package/index.js +8 -4
- package/lib/http.js +1 -1
- package/lib/restart.js +95 -32
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -61,6 +61,7 @@ window.__ModuleLoader__.load({
|
|
|
61
61
|
'done.restartButton': '完整重启',
|
|
62
62
|
'done.restarting': '正在重启 DSH…',
|
|
63
63
|
'done.restartUnavailable': '自动重启不可用,请手动退出并重新打开 DSH。',
|
|
64
|
+
'done.restartTimeout': '自动重启未完成,请手动重启 DSH。',
|
|
64
65
|
'done.refresh': '更新已安装;如界面仍是旧版本,请刷新页面或重启 DSH。',
|
|
65
66
|
'done.snapshot': '更新前快照:{path}',
|
|
66
67
|
'risk.boot': '启动关键',
|
|
@@ -156,6 +157,7 @@ window.__ModuleLoader__.load({
|
|
|
156
157
|
'done.restartButton': 'Restart DSH',
|
|
157
158
|
'done.restarting': 'Restarting DSH…',
|
|
158
159
|
'done.restartUnavailable': 'Automatic restart is unavailable. Quit and reopen DSH manually.',
|
|
160
|
+
'done.restartTimeout': 'The automatic restart did not finish. Restart DSH manually.',
|
|
159
161
|
'done.refresh': 'Updates are installed. Refresh the page or restart DSH if the UI still shows the old version.',
|
|
160
162
|
'done.snapshot': 'Pre-update snapshot: {path}',
|
|
161
163
|
'risk.boot': 'Boot-critical',
|
|
@@ -574,14 +576,6 @@ window.__ModuleLoader__.load({
|
|
|
574
576
|
const rollbackText = unreconciled?.rollback == null
|
|
575
577
|
? ''
|
|
576
578
|
: ' ' + (unreconciled.rollback.ok === true ? t('done.rollbackOk') : t('done.rollbackFailed'))
|
|
577
|
-
const retryButton = failures.length > 0
|
|
578
|
-
? h('button', {
|
|
579
|
-
type: 'button',
|
|
580
|
-
className: 'dshpu-link',
|
|
581
|
-
disabled: retryBusy === true,
|
|
582
|
-
onClick: () => { void retryFailed?.() },
|
|
583
|
-
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
584
|
-
: null
|
|
585
579
|
|
|
586
580
|
return h(React.Fragment, null,
|
|
587
581
|
waiting
|
|
@@ -639,8 +633,7 @@ window.__ModuleLoader__.load({
|
|
|
639
633
|
),
|
|
640
634
|
job.state === 'failed' && failureText !== null
|
|
641
635
|
? h(StatusNote, { tone: 'error', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
642
|
-
failureText + rollbackText + ' ' + t('done.unreconciled')
|
|
643
|
-
retryButton)
|
|
636
|
+
failureText + rollbackText + ' ' + t('done.unreconciled'))
|
|
644
637
|
: null,
|
|
645
638
|
job.state === 'done' && failures.length === 0
|
|
646
639
|
? h(StatusNote, { tone: 'success', icon: h(UI.IconCheckCircleOutlineRegular, { size: 16 }) },
|
|
@@ -648,8 +641,7 @@ window.__ModuleLoader__.load({
|
|
|
648
641
|
: null,
|
|
649
642
|
job.state === 'done' && failures.length > 0
|
|
650
643
|
? h(StatusNote, { tone: 'warn', icon: h(UI.IconWarningOutlineMedium, { size: 16 }) },
|
|
651
|
-
t('done.partial', { updated: successes.length, failed: failures.length }) + ' ' + t('done.retryHint')
|
|
652
|
-
retryButton)
|
|
644
|
+
t('done.partial', { updated: successes.length, failed: failures.length }) + ' ' + t('done.retryHint'))
|
|
653
645
|
: null,
|
|
654
646
|
skipped.length > 0
|
|
655
647
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
@@ -657,16 +649,7 @@ window.__ModuleLoader__.load({
|
|
|
657
649
|
: null,
|
|
658
650
|
job.state === 'done' && failures.length === 0 && job.restartRequired === true
|
|
659
651
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconInfoOutlineRegular, { size: 16 }) },
|
|
660
|
-
t('done.restart')
|
|
661
|
-
h('button', {
|
|
662
|
-
type: 'button',
|
|
663
|
-
className: 'dshpu-restart',
|
|
664
|
-
disabled: restarting === true,
|
|
665
|
-
onClick: () => { void restartApp?.() },
|
|
666
|
-
}, restarting === true ? t('done.restarting') : t('done.restartButton')),
|
|
667
|
-
restartError !== null && restartError !== undefined
|
|
668
|
-
? h('span', { className: 'dshpu-restartError' }, t('done.restartUnavailable'))
|
|
669
|
-
: null)
|
|
652
|
+
t('done.restart'))
|
|
670
653
|
: null,
|
|
671
654
|
job.state === 'done' && refresh?.reloaded === true
|
|
672
655
|
? h(StatusNote, { tone: 'info', icon: h(UI.IconRefreshOutlineRegular, { size: 16 }) }, t('refresh.done'))
|
|
@@ -859,17 +842,45 @@ window.__ModuleLoader__.load({
|
|
|
859
842
|
else body = h(ListView, { state, updates, selected, toggle, busy, queueOffer, desktopBlocked, desktopPhase })
|
|
860
843
|
|
|
861
844
|
const queueWaiting = showJob && (job.state === 'queued' || job.state === 'starting')
|
|
845
|
+
const failedResults = (job?.results ?? []).filter((entry) => entry.ok !== true && entry.skipped !== true)
|
|
846
|
+
const unreconciled = job?.unreconciled === true || failedResults.some((entry) => entry.reconciled !== true)
|
|
847
|
+
const canRetry = showJob && failedResults.length > 0 && !['queued', 'starting', 'running'].includes(job.state)
|
|
848
|
+
const canRestart = showJob && job.state === 'done' && job.restartRequired === true && unreconciled !== true
|
|
849
|
+
const partial = failedResults.length > 0
|
|
850
|
+
const restartErrorText = restartError === null || restartError === undefined
|
|
851
|
+
? null
|
|
852
|
+
: restartError === 'restart-timeout' ? t('done.restartTimeout') : t('done.restartUnavailable')
|
|
862
853
|
const footer = h('div', { className: 'dshpu-actions' },
|
|
863
854
|
actionError !== null
|
|
864
855
|
? h('div', { className: 'dshpu-footerError' }, message(actionError))
|
|
865
856
|
: null,
|
|
857
|
+
restartErrorText !== null
|
|
858
|
+
? h('div', { className: 'dshpu-footerError' }, restartErrorText)
|
|
859
|
+
: null,
|
|
866
860
|
showJob && job.state === 'running'
|
|
867
861
|
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.background'))
|
|
868
862
|
: null,
|
|
869
863
|
queueWaiting
|
|
870
864
|
? h(UI.Button, { variant: 'outline', onClick: () => { void cancelQueued() } }, t('queue.cancel'))
|
|
871
865
|
: null,
|
|
872
|
-
showJob && !queueWaiting && job.state !== 'running'
|
|
866
|
+
showJob && !queueWaiting && job.state !== 'running' && (canRetry || canRestart)
|
|
867
|
+
? h(UI.Button, { variant: 'outline', onClick: handleClose }, t('panel.done'))
|
|
868
|
+
: null,
|
|
869
|
+
canRestart
|
|
870
|
+
? h(UI.Button, {
|
|
871
|
+
variant: partial ? 'outline' : 'primary',
|
|
872
|
+
disabled: restarting === true,
|
|
873
|
+
onClick: () => { void restartApp() },
|
|
874
|
+
}, restarting === true ? t('done.restarting') : t('done.restartButton'))
|
|
875
|
+
: null,
|
|
876
|
+
canRetry
|
|
877
|
+
? h(UI.Button, {
|
|
878
|
+
variant: 'primary',
|
|
879
|
+
disabled: retryBusy === true,
|
|
880
|
+
onClick: () => { void retryFailed() },
|
|
881
|
+
}, retryBusy === true ? t('done.retryBusy') : t('done.retryFailed'))
|
|
882
|
+
: null,
|
|
883
|
+
showJob && !queueWaiting && job.state !== 'running' && !canRetry && !canRestart
|
|
873
884
|
? h(UI.Button, { variant: 'primary', onClick: handleClose }, t('panel.done'))
|
|
874
885
|
: null,
|
|
875
886
|
!showJob
|
|
@@ -1098,6 +1109,15 @@ window.__ModuleLoader__.load({
|
|
|
1098
1109
|
setRestartError(null)
|
|
1099
1110
|
}, [job?.id])
|
|
1100
1111
|
|
|
1112
|
+
useEffect(() => {
|
|
1113
|
+
if (restarting !== true) return
|
|
1114
|
+
const timer = setTimeout(() => {
|
|
1115
|
+
setRestarting(false)
|
|
1116
|
+
setRestartError('restart-timeout')
|
|
1117
|
+
}, 6000)
|
|
1118
|
+
return () => clearTimeout(timer)
|
|
1119
|
+
}, [restarting])
|
|
1120
|
+
|
|
1101
1121
|
const retryFailed = async () => {
|
|
1102
1122
|
if (retryBusy === true || job === null) return
|
|
1103
1123
|
const names = (job.results ?? [])
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* delegated to the official `pluginManager`; nothing here writes the profile.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { dirname } from 'node:path'
|
|
9
|
+
import { dirname, join } from 'node:path'
|
|
10
10
|
import { createBackup } from './lib/backup.js'
|
|
11
11
|
import { createEngine } from './lib/engine.js'
|
|
12
12
|
import { createHandler, ROUTE } from './lib/http.js'
|
|
@@ -37,9 +37,9 @@ function readActivity(ctx) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function apply(ctx) {
|
|
40
|
-
let manager
|
|
40
|
+
let manager
|
|
41
41
|
try {
|
|
42
|
-
manager = ctx.get?.('pluginManager')
|
|
42
|
+
manager = ctx.get?.('pluginManager')
|
|
43
43
|
} catch {
|
|
44
44
|
// A profile without the service still loads the plugin in fallback mode.
|
|
45
45
|
}
|
|
@@ -81,7 +81,11 @@ export function apply(ctx) {
|
|
|
81
81
|
const residue = profileDir !== undefined
|
|
82
82
|
? createResidueService({ profileDir, homeDir, manager, backup })
|
|
83
83
|
: null
|
|
84
|
-
const restart = createRestartService(
|
|
84
|
+
const restart = createRestartService({
|
|
85
|
+
logPath: homeDir === undefined
|
|
86
|
+
? join(process.env.TEMP ?? '.', 'dsh-plugin-update-center-restart.log')
|
|
87
|
+
: join(homeDir, 'plugin-updates', 'restart.log'),
|
|
88
|
+
})
|
|
85
89
|
|
|
86
90
|
const engine = createEngine({
|
|
87
91
|
manager,
|
package/lib/http.js
CHANGED
|
@@ -121,7 +121,7 @@ export function createHandler(engine, residue = null, restart = null) {
|
|
|
121
121
|
if (restart === null || typeof restart.restart !== 'function') {
|
|
122
122
|
return respond({ ok: false, code: 'restart-unavailable' }, 501)
|
|
123
123
|
}
|
|
124
|
-
const result = restart.restart()
|
|
124
|
+
const result = await restart.restart()
|
|
125
125
|
if (result?.ok !== true) {
|
|
126
126
|
return respond({ ok: false, code: result?.code ?? 'restart-unavailable' }, 501)
|
|
127
127
|
}
|
package/lib/restart.js
CHANGED
|
@@ -3,45 +3,73 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A page reload only replaces the renderer; the DSH Host keeps running the old
|
|
5
5
|
* plugin code, which is exactly how the client/Host mismatch crash happens.
|
|
6
|
-
* The desktop app exposes no restart bridge to plugins,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* The desktop app exposes no restart bridge to plugins, and a PowerShell child
|
|
7
|
+
* of the Host can be killed together with its process tree. Instead the Host
|
|
8
|
+
* writes a small batch file and opens its VBS launcher through Explorer: the
|
|
9
|
+
* launcher lives outside the DSH process tree, waits, kills the whole app,
|
|
10
|
+
* waits again, and starts the same executable.
|
|
9
11
|
*/
|
|
10
12
|
|
|
11
13
|
import { spawn } from 'node:child_process'
|
|
12
|
-
import { existsSync } from 'node:fs'
|
|
13
|
-
import { basename } from 'node:path'
|
|
14
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { basename, dirname, join } from 'node:path'
|
|
14
16
|
|
|
15
17
|
const APP_EXE = /^DeepSeek Harness\.exe$/i
|
|
16
18
|
|
|
17
|
-
/** Quote
|
|
18
|
-
function
|
|
19
|
-
return `
|
|
19
|
+
/** Quote a path for a cmd.exe line. */
|
|
20
|
+
function quoteCmd(value) {
|
|
21
|
+
return `"${String(value).replaceAll('"', '""')}"`
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
+
/** Quote a path as a VBScript string literal. */
|
|
25
|
+
function quoteVbs(value) {
|
|
26
|
+
return `"${String(value).replaceAll('"', '""')}"`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Build the batch that stops and relaunches the desktop app. */
|
|
30
|
+
export function buildRestartBatch(execPath, logPath = null) {
|
|
31
|
+
const log = logPath === null ? null : quoteCmd(logPath)
|
|
32
|
+
const logLine = (message) => log === null
|
|
33
|
+
? `echo %DATE% %TIME% ${message}`
|
|
34
|
+
: `echo %DATE% %TIME% ${message} >> ${log}`
|
|
35
|
+
return [
|
|
36
|
+
'@echo off',
|
|
37
|
+
'ping -n 2 127.0.0.1 >nul',
|
|
38
|
+
logLine('restart start'),
|
|
39
|
+
`taskkill /IM "DeepSeek Harness.exe" /T /F >> ${log ?? 'nul'} 2>&1`,
|
|
40
|
+
logLine('stopped'),
|
|
41
|
+
'ping -n 3 127.0.0.1 >nul',
|
|
42
|
+
`start "" ${quoteCmd(execPath)}`,
|
|
43
|
+
logLine('relaunched'),
|
|
44
|
+
'',
|
|
45
|
+
].join('\r\n')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Build a hidden VBS launcher for the batch. */
|
|
49
|
+
export function buildRestartLauncher(batchPath) {
|
|
24
50
|
return [
|
|
25
|
-
'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
'Start-Sleep -Milliseconds 1200',
|
|
29
|
-
'Start-Process -FilePath $exe',
|
|
51
|
+
'Set sh = CreateObject("WScript.Shell")',
|
|
52
|
+
`sh.Run "cmd.exe /c " & Chr(34) & ${quoteVbs(batchPath)} & Chr(34), 0, False`,
|
|
53
|
+
'',
|
|
30
54
|
].join('\r\n')
|
|
31
55
|
}
|
|
32
56
|
|
|
33
57
|
/**
|
|
34
58
|
* @param {object} [options]
|
|
35
|
-
* @param {string} [options.execPath] desktop executable
|
|
59
|
+
* @param {string} [options.execPath] desktop executable
|
|
36
60
|
* @param {NodeJS.Platform} [options.platform]
|
|
37
61
|
* @param {Function} [options.spawn]
|
|
38
62
|
* @param {Function} [options.exists]
|
|
63
|
+
* @param {string | null} [options.logPath]
|
|
64
|
+
* @param {object} [options.environment]
|
|
39
65
|
*/
|
|
40
66
|
export function createRestartService({
|
|
41
67
|
execPath = process.execPath,
|
|
42
68
|
platform = process.platform,
|
|
43
69
|
spawn: spawnChild = spawn,
|
|
44
70
|
exists = existsSync,
|
|
71
|
+
logPath = null,
|
|
72
|
+
environment = process.env,
|
|
45
73
|
} = {}) {
|
|
46
74
|
function canRestart() {
|
|
47
75
|
if (platform !== 'win32') return false
|
|
@@ -53,24 +81,59 @@ export function createRestartService({
|
|
|
53
81
|
}
|
|
54
82
|
}
|
|
55
83
|
|
|
56
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Write the batch + launcher, then ask Explorer to run the launcher. Resolve
|
|
86
|
+
* only after Explorer spawned so a failure reaches the client instead of
|
|
87
|
+
* leaving the UI on "restarting" forever.
|
|
88
|
+
*/
|
|
89
|
+
async function restart() {
|
|
57
90
|
if (!canRestart()) return { ok: false, code: 'restart-unavailable' }
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
91
|
+
const root = environment.SystemRoot ?? environment.windir ?? 'C:\\Windows'
|
|
92
|
+
const explorer = join(root, 'explorer.exe')
|
|
93
|
+
if (!exists(explorer)) return { ok: false, code: 'restart-unavailable' }
|
|
94
|
+
const dir = join(environment.TEMP ?? environment.TMP ?? '.', 'dsh-plugin-update-center-restart')
|
|
95
|
+
const stamp = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
96
|
+
const batchPath = join(dir, `restart-${stamp}.cmd`)
|
|
97
|
+
const launcherPath = join(dir, `restart-${stamp}.vbs`)
|
|
98
|
+
const log = logPath === null ? join(dir, 'restart.log') : logPath
|
|
99
|
+
try {
|
|
100
|
+
mkdirSync(dir, { recursive: true })
|
|
101
|
+
mkdirSync(dirname(log), { recursive: true })
|
|
102
|
+
writeFileSync(batchPath, buildRestartBatch(execPath, log), 'utf8')
|
|
103
|
+
writeFileSync(launcherPath, buildRestartLauncher(batchPath), 'utf8')
|
|
104
|
+
} catch (error) {
|
|
105
|
+
return { ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) }
|
|
106
|
+
}
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
let settled = false
|
|
109
|
+
const finish = (value) => {
|
|
110
|
+
if (settled) return
|
|
111
|
+
settled = true
|
|
112
|
+
resolve(value)
|
|
113
|
+
}
|
|
114
|
+
let child
|
|
115
|
+
try {
|
|
116
|
+
child = spawnChild(explorer, [launcherPath], {
|
|
117
|
+
detached: true,
|
|
118
|
+
stdio: 'ignore',
|
|
119
|
+
windowsHide: true,
|
|
120
|
+
})
|
|
121
|
+
} catch (error) {
|
|
122
|
+
finish({ ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) })
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
child.once?.('error', (error) => {
|
|
126
|
+
finish({ ok: false, code: 'restart-unavailable', error: String(error?.message ?? error) })
|
|
127
|
+
})
|
|
128
|
+
child.once?.('spawn', () => {
|
|
129
|
+
child.unref?.()
|
|
130
|
+
finish({ ok: true })
|
|
131
|
+
})
|
|
132
|
+
if (typeof child.once !== 'function') {
|
|
133
|
+
child.unref?.()
|
|
134
|
+
finish({ ok: true })
|
|
135
|
+
}
|
|
71
136
|
})
|
|
72
|
-
child.unref?.()
|
|
73
|
-
return { ok: true }
|
|
74
137
|
}
|
|
75
138
|
|
|
76
139
|
return { canRestart, restart }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-update-center",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "尊重 DSH 原始风格的插件更新插件:在侧边栏检查、排队更新已安装插件,支持快照回滚、安装后校验、卸载残留清理与离线恢复。 A DSH-native plugin update center for the sidebar with snapshots, rollback, queued updates and leftover cleanup.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|