@moonsand/dsh-ui-optimize 0.12.3 → 0.12.5
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/README.md +1 -1
- package/README.zh.md +1 -1
- package/client.js +119 -8
- package/desktop-restart.host.js +128 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ The plugin page gets an **Updates** tab. It reads what is installed from the hos
|
|
|
43
43
|
|
|
44
44
|
Only releases **published at least 24 hours ago** are installed. Anything younger is listed with the time left and skipped: a release published hours ago can still be withdrawn or patched. A release whose publish time cannot be read is skipped too — the rule cannot be confirmed, so it is not claimed. Releases the host marks **incompatible with the running DSH version** (its `engines.dsh` or a DSH peer package is not satisfied) get their own section, state the version they need, and are never picked by *Update all* — so right after a DSH upgrade the tab tells you what is waiting on the plugins instead of failing mid-update.
|
|
45
45
|
|
|
46
|
-
Updates run through the host plugin manager, i.e. the same path the plugin page uses when you update one entry by hand; progress and failure codes come back from it. Reload the page afterwards: the new client half only loads on a fresh page.
|
|
46
|
+
Updates run through the host plugin manager, i.e. the same path the plugin page uses when you update one entry by hand; progress and failure codes come back from it. Releases that are already loaded cannot be swapped in a running host, so that batch is staged instead: on the Linux host DSH stops once, the batch is installed with pnpm, and DSH starts again; in the desktop app the same batch is installed while the app restarts itself. Reload the page afterwards: the new client half only loads on a fresh page.
|
|
47
47
|
|
|
48
48
|
If the host's plugin manager is unavailable, the tab says so instead of pretending to check.
|
|
49
49
|
|
package/README.zh.md
CHANGED
|
@@ -58,7 +58,7 @@ dsh plugin 或 GUI 插件管理:安装 @moonsand/dsh-ui-optimize
|
|
|
58
58
|
|
|
59
59
|
只装**发布满 24 小时**的版本;更年轻的会列出剩余时间并跳过——刚发几小时的版本还可能被撤回或补丁。读不到发布时间的同样跳过:规则无法确认,就不假装确认过。宿主判定**与当前 DSH 版本不兼容**的版本(`engines.dsh` 或某个 DSH peer 包不满足)单列一区,写明它要求的版本,并且永远不被「一键更新」带上——刚升级完 DSH 时,页签告诉你是哪些插件还没跟上,而不是等你点下去才失败。
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
更新走宿主插件管理服务,和你手点单个插件的更新是同一条路径;进度与失败码由它回报。已经被宿主加载的插件不能就地替换,所以这批会先排进队列:Linux 宿主上 DSH 停一次、整批用 pnpm 装完、再启动;桌面版则在应用自身重启的过程中把这一批装好。更新完刷新页面:新的客户端代码只在重新加载时生效。
|
|
62
62
|
|
|
63
63
|
宿主的插件管理服务拿不到时,页签直接说明查不了,不会假装在检查。
|
|
64
64
|
|
package/client.js
CHANGED
|
@@ -137,7 +137,11 @@ window.__ModuleLoader__.load({
|
|
|
137
137
|
'updates.section.blocked': 'Not loadable on this DSH',
|
|
138
138
|
'updates.section.blockedHint': 'The running DSH version cannot load these releases. Upgrade DSH first, or wait for the plugin to publish a compatible one.',
|
|
139
139
|
'updates.compatTag': 'Needs {version}',
|
|
140
|
+
'updates.pendingUnsupported':
|
|
141
|
+
'This host is not Linux ({platform}), so DSH cannot be stopped from here. While DSH is stopped, run: {command}',
|
|
140
142
|
'updates.applyStarted': '{n} loaded plugin(s) are queued: DSH stops once, installs the whole batch, then starts once — not one restart per plugin. The page reconnects on its own.',
|
|
143
|
+
'updates.logTitle': 'Install log — the batch runs in the background, this is its own output',
|
|
144
|
+
'updates.logWaiting': 'Waiting for the installer to write its first line…',
|
|
141
145
|
'updates.applyFailed': 'Could not start the background install. Try again in a moment.',
|
|
142
146
|
'updates.waitingRestart': 'waiting for restart',
|
|
143
147
|
'updates.compatTagUnknown': 'Not loadable on this DSH',
|
|
@@ -254,7 +258,11 @@ window.__ModuleLoader__.load({
|
|
|
254
258
|
'updates.section.blocked': '与当前 DSH 不兼容',
|
|
255
259
|
'updates.section.blockedHint': '当前运行的 DSH 版本加载不了这些版本。先升级 DSH,或等插件发布兼容版本。',
|
|
256
260
|
'updates.compatTag': '需要 {version}',
|
|
261
|
+
'updates.pendingUnsupported':
|
|
262
|
+
'这个宿主不是 Linux({platform}),没法从这里停机安装。请在 DSH 停止时手动执行:{command}',
|
|
257
263
|
'updates.applyStarted': '{n} 个插件正在运行的,会一起停机安装:DSH 先退出、这批一次装完、再启动一次(不是每个插件重启一遍)。装完页面会自动重连。',
|
|
264
|
+
'updates.logTitle': '安装日志——这批在后台跑,下面是它自己的输出',
|
|
265
|
+
'updates.logWaiting': '等安装脚本写出第一行……',
|
|
258
266
|
'updates.applyFailed': '后台安装没能启动,稍后再试一次。',
|
|
259
267
|
'updates.waitingRestart': '等待重启',
|
|
260
268
|
'updates.compatTagUnknown': '与当前 DSH 不兼容',
|
|
@@ -2812,6 +2820,35 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
2812
2820
|
}
|
|
2813
2821
|
}
|
|
2814
2822
|
|
|
2823
|
+
/* The restart batch runs pnpm inside a detached child, so the only progress it
|
|
2824
|
+
* can honestly report is its own log. Same URL discipline as every other route:
|
|
2825
|
+
* try the base-URI-relative form first (reverse proxies rewrite the root), and
|
|
2826
|
+
* require real JSON — the fnOS gateway answers unknown paths with 200 + text. */
|
|
2827
|
+
async function readApplyLog() {
|
|
2828
|
+
const candidates = []
|
|
2829
|
+
try {
|
|
2830
|
+
candidates.push(new URL('ui-optimize/desktop/apply/log', document.baseURI).toString())
|
|
2831
|
+
} catch {
|
|
2832
|
+
/* baseURI can be opaque in tests; the absolute path below still works */
|
|
2833
|
+
}
|
|
2834
|
+
candidates.push('/ui-optimize/desktop/apply/log')
|
|
2835
|
+
for (const url of candidates) {
|
|
2836
|
+
try {
|
|
2837
|
+
const response = await fetch(url, {
|
|
2838
|
+
credentials: 'same-origin',
|
|
2839
|
+
headers: { 'x-ui-optimize-apply': '1' },
|
|
2840
|
+
})
|
|
2841
|
+
if (!response.ok) continue
|
|
2842
|
+
const text = await response.text()
|
|
2843
|
+
const data = JSON.parse(text)
|
|
2844
|
+
if (data && typeof data === 'object' && Array.isArray(data.lines)) return data
|
|
2845
|
+
} catch {
|
|
2846
|
+
/* try the next candidate */
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
return null
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2815
2852
|
function UpdatesTab() {
|
|
2816
2853
|
const [phase, setPhase] = React.useState(updateRun.busy ? 'ready' : 'loading')
|
|
2817
2854
|
/* Mirror of `phase` for timers: reading a ref avoids calling one
|
|
@@ -2832,6 +2869,35 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
2832
2869
|
function setChecked(next) { updateRun.set({ checked: next }) }
|
|
2833
2870
|
function setBusy(next) { updateRun.set({ busy: next }) }
|
|
2834
2871
|
const [message, setMessage] = React.useState('')
|
|
2872
|
+
const [pendingNote, setPendingNote] = React.useState('')
|
|
2873
|
+
const [applyLog, setApplyLog] = React.useState([])
|
|
2874
|
+
const [applyRunning, setApplyRunning] = React.useState(false)
|
|
2875
|
+
/* A queued batch is "applied" until DSH restarts and the page reloads, which is
|
|
2876
|
+
* a ~40 second silence. Poll its log so the click shows movement instead of a
|
|
2877
|
+
* frozen list. */
|
|
2878
|
+
const batchQueued = rows.some(function (row) { return row.state === 'applied' })
|
|
2879
|
+
React.useEffect(function () {
|
|
2880
|
+
if (!batchQueued) {
|
|
2881
|
+
setApplyLog([])
|
|
2882
|
+
setApplyRunning(false)
|
|
2883
|
+
return undefined
|
|
2884
|
+
}
|
|
2885
|
+
let stopped = false
|
|
2886
|
+
function tick() {
|
|
2887
|
+
readApplyLog().then(function (data) {
|
|
2888
|
+
if (!stopped && data) {
|
|
2889
|
+
setApplyLog(data.lines.slice(-8))
|
|
2890
|
+
setApplyRunning(data.running === true)
|
|
2891
|
+
}
|
|
2892
|
+
})
|
|
2893
|
+
}
|
|
2894
|
+
tick()
|
|
2895
|
+
const timer = setInterval(tick, 1500)
|
|
2896
|
+
return function () {
|
|
2897
|
+
stopped = true
|
|
2898
|
+
clearInterval(timer)
|
|
2899
|
+
}
|
|
2900
|
+
}, [batchQueued])
|
|
2835
2901
|
const [open, setOpen] = React.useState({})
|
|
2836
2902
|
const [notes, setNotes] = React.useState({})
|
|
2837
2903
|
const [settings, setSettings] = React.useState(store.state)
|
|
@@ -3093,6 +3159,14 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3093
3159
|
continue
|
|
3094
3160
|
}
|
|
3095
3161
|
if (!response.ok || payload.ok !== true) {
|
|
3162
|
+
/* A non-Linux host cannot run the staged helper at all; carry the
|
|
3163
|
+
* reason up so the panel can print the manual command instead of a
|
|
3164
|
+
* bare HTTP code the user can do nothing with. */
|
|
3165
|
+
if (payload.reason === 'unsupported-platform') {
|
|
3166
|
+
const error = new Error('unsupported-platform')
|
|
3167
|
+
error.unsupportedPlatform = String(payload.platform || '')
|
|
3168
|
+
throw error
|
|
3169
|
+
}
|
|
3096
3170
|
lastError = new Error('HTTP ' + response.status + ' ' + String(payload.reason || ''))
|
|
3097
3171
|
continue
|
|
3098
3172
|
}
|
|
@@ -3113,6 +3187,7 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3113
3187
|
if (targets.length === 0 && pendingRows.length === 0) return
|
|
3114
3188
|
setBusy(true)
|
|
3115
3189
|
setMessage('')
|
|
3190
|
+
setPendingNote('')
|
|
3116
3191
|
let restarts = 0
|
|
3117
3192
|
let refreshes = 0
|
|
3118
3193
|
for (let index = 0; index < targets.length; index += 1) {
|
|
@@ -3193,7 +3268,17 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3193
3268
|
})
|
|
3194
3269
|
} catch (err) {
|
|
3195
3270
|
applyFailed = true
|
|
3196
|
-
|
|
3271
|
+
if (err && err.unsupportedPlatform !== undefined) {
|
|
3272
|
+
const command = 'pnpm add ' + pendingRows.map(function (row) {
|
|
3273
|
+
const target = targetOf(row)
|
|
3274
|
+
return row.name + '@' + String((target && target.version) || row.latest)
|
|
3275
|
+
}).join(' ')
|
|
3276
|
+
applyError = translate('updates.pendingUnsupported')
|
|
3277
|
+
.replace('{platform}', String(err.unsupportedPlatform || 'unknown'))
|
|
3278
|
+
.replace('{command}', command)
|
|
3279
|
+
} else {
|
|
3280
|
+
applyError = err && err.message ? String(err.message) : String(err)
|
|
3281
|
+
}
|
|
3197
3282
|
}
|
|
3198
3283
|
}
|
|
3199
3284
|
setBusy(false)
|
|
@@ -3201,7 +3286,7 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3201
3286
|
if (applyFailed) {
|
|
3202
3287
|
setMessage(translate('updates.applyFailed') + (applyError ? '(' + applyError + ')' : ''))
|
|
3203
3288
|
} else if (appliedPending > 0) {
|
|
3204
|
-
|
|
3289
|
+
setPendingNote(translate('updates.applyStarted').replace('{n}', String(appliedPending)))
|
|
3205
3290
|
} else {
|
|
3206
3291
|
setMessage(
|
|
3207
3292
|
restarts > 0
|
|
@@ -3331,6 +3416,11 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3331
3416
|
* `!row.state` was therefore never true and every row looked "busy",
|
|
3332
3417
|
* which is what pushed the wait label back onto finished rows. */
|
|
3333
3418
|
const idle = !row.state || row.state === 'idle'
|
|
3419
|
+
/* A queued restart-install keeps state 'applied' until the host comes back.
|
|
3420
|
+
* While the batch is still running it wears the same yellow + moving bar as
|
|
3421
|
+
* a live install; once the log says it is done it turns green like any other
|
|
3422
|
+
* finished row, so the pending area reads the same way as the ready one. */
|
|
3423
|
+
const shownState = row.state === 'applied' ? (applyRunning ? 'running' : 'succeeded') : row.state
|
|
3334
3424
|
const usingFallback = !!target && target.fallback
|
|
3335
3425
|
const fallbackShown = usingFallback ? target.version : ''
|
|
3336
3426
|
/* A running or finished row speaks with its state, not with the plan:
|
|
@@ -3339,7 +3429,10 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3339
3429
|
/* A row the host cannot load is not a failed update to retry: it reads
|
|
3340
3430
|
* as one fact ("this DSH cannot load it"), with the raw failure code
|
|
3341
3431
|
* left in the log rather than on the card. */
|
|
3342
|
-
const
|
|
3432
|
+
const stateLabel = row.state === 'applied' && !applyRunning
|
|
3433
|
+
? translate('updates.succeeded')
|
|
3434
|
+
: updateLabel(row)
|
|
3435
|
+
const label = row.compat ? '' : (idle ? (quiet || usingFallback ? '' : updateLabel(row)) : stateLabel)
|
|
3343
3436
|
/* Nothing to install yet: say how far the nearest candidate is, so a
|
|
3344
3437
|
* row that is "waiting" does not look like the plugin forgot it.
|
|
3345
3438
|
* Only idle rows: a finished row must not read "已更新 · 剩余 5.1 小时". */
|
|
@@ -3355,9 +3448,9 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3355
3448
|
'div',
|
|
3356
3449
|
{
|
|
3357
3450
|
className: 'dsuik-up-row'
|
|
3358
|
-
+ (
|
|
3359
|
-
+ (
|
|
3360
|
-
+ (
|
|
3451
|
+
+ (shownState === 'running' ? ' is-running' : '')
|
|
3452
|
+
+ (shownState === 'succeeded' ? ' is-ok' : '')
|
|
3453
|
+
+ (shownState === 'failed' && !row.compat ? ' is-fail' : '')
|
|
3361
3454
|
+ (isOpen ? ' is-open' : ''),
|
|
3362
3455
|
style: { animationDelay: String(Math.min(index, 12) * 18) + 'ms' },
|
|
3363
3456
|
},
|
|
@@ -3404,7 +3497,7 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3404
3497
|
),
|
|
3405
3498
|
h('span', { className: 'dsuik-up-chev', 'aria-hidden': 'true' }, isOpen ? '▾' : '▸'),
|
|
3406
3499
|
),
|
|
3407
|
-
|
|
3500
|
+
shownState === 'running'
|
|
3408
3501
|
? (row.percent === null
|
|
3409
3502
|
? h('div', { className: 'dsuik-up-bar is-indef' }, h('i'))
|
|
3410
3503
|
: h('div', { className: 'dsuik-up-bar' }, h('i', { style: { width: String(row.percent || 0) + '%' } })))
|
|
@@ -3504,11 +3597,24 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3504
3597
|
? sectionArea(
|
|
3505
3598
|
'updates.section.pending',
|
|
3506
3599
|
groups.pending,
|
|
3507
|
-
|
|
3600
|
+
false,
|
|
3508
3601
|
groups.pending.length > 0 ? 'updates.section.pendingHint' : 'updates.section.pendingEmpty',
|
|
3509
3602
|
true,
|
|
3510
3603
|
)
|
|
3511
3604
|
: null,
|
|
3605
|
+
/* Both of these belong to the restart batch, so they sit under its own
|
|
3606
|
+
* heading instead of under the (often empty) ready list. */
|
|
3607
|
+
phase === 'ready' && pendingNote ? h('p', { className: 'dsuik-up-note is-after-pending' }, pendingNote) : null,
|
|
3608
|
+
phase === 'ready' && batchQueued
|
|
3609
|
+
? h('div', { className: 'dsuik-up-log' },
|
|
3610
|
+
h('div', { className: 'dsuik-up-log-head' }, translate('updates.logTitle')),
|
|
3611
|
+
applyLog.length > 0
|
|
3612
|
+
? applyLog.map(function (line, index) {
|
|
3613
|
+
return h('div', { className: 'dsuik-up-log-line', key: 'log' + index }, line)
|
|
3614
|
+
})
|
|
3615
|
+
: h('div', { className: 'dsuik-up-log-line is-empty' }, translate('updates.logWaiting')),
|
|
3616
|
+
)
|
|
3617
|
+
: null,
|
|
3512
3618
|
phase === 'ready' ? sectionArea('updates.section.waiting', groups.waiting, true, 'updates.section.waitingHint', false) : null,
|
|
3513
3619
|
phase === 'ready'
|
|
3514
3620
|
? sectionArea(
|
|
@@ -3550,6 +3656,11 @@ button.muik-shelf-row:focus-visible{outline:2px solid var(--dsw-alias-brand-prim
|
|
|
3550
3656
|
.dsuik-up-section-title{margin:0;font-size:12.5px;font-weight:600;letter-spacing:.01em;color:var(--dsw-alias-label-primary);}
|
|
3551
3657
|
.dsuik-up-section.is-muted .dsuik-up-row{opacity:.7;background:transparent;}
|
|
3552
3658
|
.dsuik-up-note.is-after-ready{margin-top:-4px;}
|
|
3659
|
+
.dsuik-up-note.is-after-pending{margin-top:-2px;}
|
|
3660
|
+
.dsuik-up-log{margin:-4px 0 2px;padding:8px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);max-height:150px;overflow:auto;}
|
|
3661
|
+
.dsuik-up-log-head{font-size:11.5px;font-weight:600;color:var(--dsw-alias-label-secondary);margin-bottom:4px;}
|
|
3662
|
+
.dsuik-up-log-line{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:1.5;color:var(--dsw-alias-label-secondary);white-space:pre-wrap;word-break:break-all;}
|
|
3663
|
+
.dsuik-up-log-line.is-empty{font-style:italic;}
|
|
3553
3664
|
.dsuik-up-note.is-empty{padding:10px 12px;border:1px dashed var(--dsw-alias-border-l1);border-radius:10px;}
|
|
3554
3665
|
.dsuik-up-loading{display:flex;align-items:center;justify-content:center;gap:8px;padding:34px 0 30px;font-size:13px;color:var(--dsw-alias-label-secondary);animation:dsuik-up-in .2s ease-out both;}
|
|
3555
3666
|
@media (prefers-reduced-motion: reduce){.dsuik-up-section,.dsuik-up-row,.dsuik-up-loading{animation:none;}}
|
package/desktop-restart.host.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
* @module @moonsand/dsh-desktop-restart
|
|
30
30
|
*/
|
|
31
31
|
import { spawn } from 'node:child_process'
|
|
32
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
32
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
33
33
|
import { tmpdir } from 'node:os'
|
|
34
34
|
import { join } from 'node:path'
|
|
35
35
|
|
|
@@ -56,6 +56,7 @@ const DIAGNOSE_PATH = `${PREFIX}/diagnose`
|
|
|
56
56
|
* does the pnpm run *after* this reply flushes, then asks the fnOS gateway to
|
|
57
57
|
* restart DSH so the new versions are what actually loads. */
|
|
58
58
|
const APPLY_PATH = `${PREFIX}/apply`
|
|
59
|
+
const APPLY_LOG_PATH = `${PREFIX}/apply/log`
|
|
59
60
|
|
|
60
61
|
/** Where the detached apply run keeps its log and backups. */
|
|
61
62
|
const APPLY_DIR = join(process.env.DSH_HOME || tmpdir(), '.ui-optimize')
|
|
@@ -752,8 +753,12 @@ function writeApplyScript(specs) {
|
|
|
752
753
|
' cp -p pnpm-lock.yaml.bak-' + stamp + ' pnpm-lock.yaml 2>/dev/null || true',
|
|
753
754
|
'else',
|
|
754
755
|
' echo "pnpm ok — asking the gateway to restart DSH"',
|
|
755
|
-
|
|
756
|
-
|
|
756
|
+
/* Fire and forget: the gateway answers only after it has stopped this process, so
|
|
757
|
+
* waiting for the response here can only ever end in a timeout — and a timeout that
|
|
758
|
+
* leaves DSH running, which is exactly what happened on 2026-11-23 01:00. */
|
|
759
|
+
' ( curl -sS -m 3 --unix-socket ' + JSON.stringify(process.env.DSH_GATEWAY_SOCK || '/vol1/@appcenter/fn-deepseek-harness/app.sock') +
|
|
760
|
+
' -X POST -H "x-requested-with: fetch" -H "x-trim-isadmin: true" http://localhost/__fnos-gateway/control/web/restart >/dev/null 2>&1 & )',
|
|
761
|
+
' echo "restart requested — not waiting, the gateway is about to stop this process"',
|
|
757
762
|
'fi',
|
|
758
763
|
'echo "== $(date -Is) apply done (rc=$rc) =="',
|
|
759
764
|
]
|
|
@@ -761,6 +766,69 @@ function writeApplyScript(specs) {
|
|
|
761
766
|
return script
|
|
762
767
|
}
|
|
763
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Windows (the desktop app) has no POSIX shell, so the staged helper is written as a
|
|
771
|
+
* plain Node script instead and started with this very executable. Same contract:
|
|
772
|
+
* back up the manifests, `pnpm add` the batch, roll back on failure, restart only on
|
|
773
|
+
* success — the difference is that the restart goes through our own HTTP route, since
|
|
774
|
+
* the fnOS gateway socket does not exist here.
|
|
775
|
+
*/
|
|
776
|
+
function writeApplyNodeScript(specs, port) {
|
|
777
|
+
mkdirSync(APPLY_DIR, { recursive: true })
|
|
778
|
+
const profile = join(process.env.DSH_HOME || '', 'profiles', 'web')
|
|
779
|
+
const script = join(APPLY_DIR, 'apply.mjs')
|
|
780
|
+
const log = join(APPLY_DIR, 'apply.log')
|
|
781
|
+
const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)
|
|
782
|
+
const body = `import { spawnSync } from 'node:child_process'
|
|
783
|
+
import { appendFileSync, copyFileSync, existsSync } from 'node:fs'
|
|
784
|
+
import { join } from 'node:path'
|
|
785
|
+
|
|
786
|
+
const log = ${JSON.stringify(log)}
|
|
787
|
+
const profile = ${JSON.stringify(profile)}
|
|
788
|
+
const specs = ${JSON.stringify(specs)}
|
|
789
|
+
const stamp = ${JSON.stringify(stamp)}
|
|
790
|
+
const port = ${JSON.stringify(String(port))}
|
|
791
|
+
const say = (line) => appendFileSync(log, line + '\\n')
|
|
792
|
+
|
|
793
|
+
say('== ' + new Date().toISOString() + ' apply start (node) ==')
|
|
794
|
+
const pkg = join(profile, 'package.json')
|
|
795
|
+
const lock = join(profile, 'pnpm-lock.yaml')
|
|
796
|
+
copyFileSync(pkg, pkg + '.bak-' + stamp)
|
|
797
|
+
if (existsSync(lock)) copyFileSync(lock, lock + '.bak-' + stamp)
|
|
798
|
+
|
|
799
|
+
const useShell = process.platform === 'win32'
|
|
800
|
+
const bin = useShell ? 'pnpm.cmd' : 'pnpm'
|
|
801
|
+
const result = spawnSync(bin, ['add', ...specs, '--registry=' + ${JSON.stringify('https://registry.npmjs.org/')}], {
|
|
802
|
+
cwd: profile,
|
|
803
|
+
shell: useShell,
|
|
804
|
+
encoding: 'utf8',
|
|
805
|
+
})
|
|
806
|
+
|
|
807
|
+
say((result.stdout || '') + (result.stderr || ''))
|
|
808
|
+
if (result.status !== 0) {
|
|
809
|
+
say('pnpm failed rc=' + String(result.status) + ' — rolling back')
|
|
810
|
+
copyFileSync(pkg + '.bak-' + stamp, pkg)
|
|
811
|
+
if (existsSync(lock + '.bak-' + stamp)) copyFileSync(lock + '.bak-' + stamp, lock)
|
|
812
|
+
say('== ' + new Date().toISOString() + ' apply done (rolled back) ==')
|
|
813
|
+
process.exit(1)
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
say('pnpm ok — asking DSH to restart')
|
|
817
|
+
try {
|
|
818
|
+
const response = await fetch('http://127.0.0.1:' + port + '/ui-optimize/desktop/restart', {
|
|
819
|
+
method: 'POST',
|
|
820
|
+
headers: { 'x-ui-optimize-apply': '1' },
|
|
821
|
+
})
|
|
822
|
+
say('restart response ' + response.status)
|
|
823
|
+
} catch (error) {
|
|
824
|
+
say('restart request failed: ' + String(error && error.message ? error.message : error))
|
|
825
|
+
}
|
|
826
|
+
say('== ' + new Date().toISOString() + ' apply done ==')
|
|
827
|
+
`
|
|
828
|
+
writeFileSync(script, body, { mode: 0o700 })
|
|
829
|
+
return script
|
|
830
|
+
}
|
|
831
|
+
|
|
764
832
|
async function handleRequest(ctx, request, response) {
|
|
765
833
|
const reply = (status, body) => {
|
|
766
834
|
response.writeHead(status, {
|
|
@@ -808,6 +876,38 @@ async function handleRequest(ctx, request, response) {
|
|
|
808
876
|
logPath: HELPER_LOG_PATH,
|
|
809
877
|
})
|
|
810
878
|
}
|
|
879
|
+
if (pathname === APPLY_LOG_PATH) {
|
|
880
|
+
// Progress for the restart batch: the child does all its work in one pnpm run, so the
|
|
881
|
+
// only honest progress report is its own log. Reading it costs one small file read.
|
|
882
|
+
if (request.method !== 'GET') return reply(405, { ok: false, reason: 'method-not-allowed' })
|
|
883
|
+
const logPath = join(APPLY_DIR, 'apply.log')
|
|
884
|
+
if (!existsSync(logPath)) return reply(200, { ok: true, lines: [], running: false, mtime: null })
|
|
885
|
+
let text = ''
|
|
886
|
+
try {
|
|
887
|
+
text = readFileSync(logPath, 'utf8')
|
|
888
|
+
} catch {
|
|
889
|
+
text = ''
|
|
890
|
+
}
|
|
891
|
+
const all = text.split('\n').filter(function (line) { return line.trim().length > 0 })
|
|
892
|
+
let mtime = null
|
|
893
|
+
try {
|
|
894
|
+
mtime = statSync(logPath).mtime.toISOString()
|
|
895
|
+
} catch {
|
|
896
|
+
mtime = null
|
|
897
|
+
}
|
|
898
|
+
let lastStart = -1
|
|
899
|
+
for (let i = all.length - 1; i >= 0; i -= 1) {
|
|
900
|
+
if (all[i].indexOf('apply start') !== -1) {
|
|
901
|
+
lastStart = i
|
|
902
|
+
break
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const running = lastStart >= 0 && !all.slice(lastStart).some(function (line) { return line.indexOf('apply done') !== -1 })
|
|
906
|
+
/* Only the current run: older runs are history, and showing them made a finished
|
|
907
|
+
* batch look like it was still installing. */
|
|
908
|
+
const current = lastStart >= 0 ? all.slice(lastStart) : []
|
|
909
|
+
return reply(200, { ok: true, lines: current.slice(-60), running, mtime })
|
|
910
|
+
}
|
|
811
911
|
if (pathname === APPLY_PATH) {
|
|
812
912
|
if (request.method !== 'POST') return reply(405, { ok: false, reason: 'method-not-allowed' })
|
|
813
913
|
if (!sameOriginCaller(request)) return reply(403, { ok: false, reason: 'cross-origin' })
|
|
@@ -827,8 +927,31 @@ async function handleRequest(ctx, request, response) {
|
|
|
827
927
|
})
|
|
828
928
|
}
|
|
829
929
|
try {
|
|
830
|
-
|
|
831
|
-
|
|
930
|
+
// Two shapes, one contract: Linux stages a bash script and asks the fnOS gateway
|
|
931
|
+
// socket to restart; Windows (the desktop app) stages a Node script and restarts
|
|
932
|
+
// through our own HTTP route. Anything else refuses instead of guessing.
|
|
933
|
+
const windows = process.platform === 'win32'
|
|
934
|
+
const script = windows
|
|
935
|
+
? writeApplyNodeScript(specs, process.env.DSH_UPSTREAM_PORT || '3080')
|
|
936
|
+
: writeApplyScript(specs)
|
|
937
|
+
const child = windows
|
|
938
|
+
? spawn(process.execPath, [script], {
|
|
939
|
+
detached: true,
|
|
940
|
+
stdio: 'ignore',
|
|
941
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
|
|
942
|
+
})
|
|
943
|
+
: spawn('/bin/bash', [script], { detached: true, stdio: 'ignore' })
|
|
944
|
+
// Never let a failed exec kill the host: without this listener Node rethrows.
|
|
945
|
+
child.on('error', function (error) {
|
|
946
|
+
try {
|
|
947
|
+
appendFileSync(
|
|
948
|
+
join(APPLY_DIR, 'apply.log'),
|
|
949
|
+
'== ' + new Date().toISOString() + ' spawn failed: ' + (error && error.message ? error.message : String(error)) + ' ==\n',
|
|
950
|
+
)
|
|
951
|
+
} catch {
|
|
952
|
+
/* logging must never be the thing that breaks the request */
|
|
953
|
+
}
|
|
954
|
+
})
|
|
832
955
|
child.unref()
|
|
833
956
|
return reply(202, { ok: true, specs: specs.length, logPath: join(APPLY_DIR, 'apply.log') })
|
|
834
957
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonsand/dsh-ui-optimize",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Switches that tune how DeepSeek Harness looks and behaves across the whole interface, not just a few screens — each works on its own and more arrive as the shell grows: an eight-theme minimalist gallery, sidebar panel folding, and reload/restart buttons at the sidebar foot. · 调 DeepSeek Harness 整体观感与操作的开关集合,管的是整套界面而不只是某几块;每个开关独立生效,随宿主能力增长继续增加:8 套极简主题画廊、侧栏面板收纳,以及侧栏底部的刷新界面与重启应用按钮。",
|
|
6
6
|
"license": "MIT",
|