dsh-reload-buttons 0.1.3 → 0.1.4
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.en.md +1 -1
- package/README.md +2 -1
- package/assets/restart-app.mjs +40 -2
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -39,7 +39,7 @@ Restart DSH afterwards. Replace `desktop` with your own profile name if you use
|
|
|
39
39
|
|
|
40
40
|
Requirements: the DSH desktop app (the restart button needs the shell to close and relaunch). On `dsh web` the reload button works and restart just ends the kernel process. Node follows DSH; no extra runtime is needed.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
Requires DSH >= 0.2.1-alpha.3; verified on 0.2.1-alpha.3 and 0.2.2-rc.1, later versions untested.
|
|
43
43
|
|
|
44
44
|
## Where the buttons live
|
|
45
45
|
|
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ dsh plugin --profile desktop add dsh-reload-buttons
|
|
|
39
39
|
|
|
40
40
|
要求:DSH 桌面端(重启按钮要关壳重开)。`dsh web` 下刷新可用,重启等于结束内核进程。Node 版本跟随 DSH,不需要额外运行时。
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
要求 DSH >= 0.2.1-alpha.3;实测 0.2.1-alpha.3、0.2.2-rc.1,更高版本未验证。
|
|
43
43
|
|
|
44
44
|
## 界面位置
|
|
45
45
|
|
|
@@ -50,6 +50,7 @@ dsh plugin --profile desktop add dsh-reload-buttons
|
|
|
50
50
|
- 宿主半边注册一条 `POST /dsh-reload-buttons/api/restart`:只接受回环地址(`127.*`、`::1`、`::ffff:127.*`),只接受 POST。远程访问的 DSH 上点重启会被 403 拒绝。
|
|
51
51
|
- 桌面端把重启交棒给 `assets/restart-app.mjs`(detached spawn):等 1.2 秒让 HTTP 响应交回浏览器 → 关掉 Electron 主进程 → 等端口释放(12 秒不放就结束内核)→ 拉起 exe 并按新进程 pid 探活(8 秒不稳就再试一次)。
|
|
52
52
|
- 桌面端每次启动端口都不同,探活只看进程 pid,不看端口。
|
|
53
|
+
- 拉起 exe 之前顺手清一次累积的 `dsh-auth-*` 会话 Cookie(超过 30 条才清,先备份):桌面端每次启动换端口,Cookie 名里编着「域名:端口」,而 Cookie 按域名存、不区分端口——每启动一次多一条,堆到约 70 条、请求头过 16 KB 后,下次启动会报 `desktop welcome: Web authentication failed`。清不了只记日志,不影响重启。
|
|
53
54
|
- 重启日志写在 `$DSH_HOME/logs/dsh-reload-buttons-restart.log`。
|
|
54
55
|
- 刷新按钮是纯浏览器侧行为,不需要宿主。
|
|
55
56
|
- 不联网、不上传任何内容。
|
package/assets/restart-app.mjs
CHANGED
|
@@ -79,7 +79,45 @@ if (!released) {
|
|
|
79
79
|
}
|
|
80
80
|
log(`port ${released ? 'released' : 'STILL BUSY'}`)
|
|
81
81
|
|
|
82
|
-
// 4)
|
|
82
|
+
// 4) 清一次累积的浏览器会话 Cookie。此刻应用已完全退出,数据库没人占着。
|
|
83
|
+
// DSH 每次启动换端口,Cookie 名里编着「域名:端口」,而 Cookie 按域名存、不区分端口,
|
|
84
|
+
// 所以每启动一次多一条;堆到约 70 条、请求头过 16 KB,下次启动会报认证失败。
|
|
85
|
+
async function pruneAuthCookies() {
|
|
86
|
+
try {
|
|
87
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
88
|
+
const { join } = await import('node:path')
|
|
89
|
+
const { homedir } = await import('node:os')
|
|
90
|
+
const { existsSync, copyFileSync } = await import('node:fs')
|
|
91
|
+
const dbPath = join(homedir(), 'AppData', 'Roaming', '@deepseek-ai', 'dsh-desktop', 'Network', 'Cookies')
|
|
92
|
+
if (!existsSync(dbPath)) {
|
|
93
|
+
log('cookie db missing, skip')
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
const db = new DatabaseSync(dbPath)
|
|
97
|
+
const count = () => db.prepare(
|
|
98
|
+
"select count(*) as n from cookies where host_key = '127.0.0.1' and name like 'dsh-auth-%'",
|
|
99
|
+
).get().n
|
|
100
|
+
const before = count()
|
|
101
|
+
if (before <= 30) {
|
|
102
|
+
db.close()
|
|
103
|
+
log(`cookies ${before} <= 30, skip`)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)
|
|
107
|
+
copyFileSync(dbPath, `${dbPath}.bak-${stamp}`)
|
|
108
|
+
db.exec("delete from cookies where host_key = '127.0.0.1' and name like 'dsh-auth-%'")
|
|
109
|
+
db.exec('vacuum')
|
|
110
|
+
const after = count()
|
|
111
|
+
db.close()
|
|
112
|
+
log(`cookies pruned ${before} -> ${after}`)
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// 清不了不影响重启:重启本身必须先完成。
|
|
115
|
+
log(`cookie prune skipped: ${error.message}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
await pruneAuthCookies()
|
|
119
|
+
|
|
120
|
+
// 5) 重新拉起应用
|
|
83
121
|
if (!exePath) {
|
|
84
122
|
log('no exe path, stop')
|
|
85
123
|
process.exit(1)
|
|
@@ -121,7 +159,7 @@ async function waitAlive(pid, ms) {
|
|
|
121
159
|
|
|
122
160
|
const first = launchApp('first launch')
|
|
123
161
|
|
|
124
|
-
//
|
|
162
|
+
// 6) 起来了吗?起不来就再试一次(第二次失败只能让用户手动开)
|
|
125
163
|
if (await waitAlive(first.pid, 8000)) {
|
|
126
164
|
log(`ok: app is back (pid ${first.pid} alive)`)
|
|
127
165
|
process.exit(0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-reload-buttons",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "在 DSH 界面左上角放两个按钮:刷新界面、重启应用。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"engines": {
|
|
26
26
|
"node": "^22.19.0 || >=24.0.0",
|
|
27
|
-
"dsh": ">=0.2.1-0
|
|
27
|
+
"dsh": ">=0.2.1-0"
|
|
28
28
|
},
|
|
29
29
|
"dsh": {
|
|
30
30
|
"client": {
|