dsh-ui-smooth 0.1.0 → 0.1.1
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 +176 -173
- package/lib/client.js +1665 -1483
- package/lib/index.js +169 -248
- package/package.json +68 -68
- package/src/config.js +129 -140
- package/src/follow.js +68 -0
- package/src/keepawake.js +96 -70
- package/src/main.js +142 -136
- package/src/recycle.js +334 -262
- package/src/settings.js +201 -183
package/lib/index.js
CHANGED
|
@@ -1,248 +1,169 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Host loader entry for dsh-ui-smooth.
|
|
3
|
-
*
|
|
4
|
-
* The page does the
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
response.end(body)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function readBody(request) {
|
|
174
|
-
return new Promise((resolve) => {
|
|
175
|
-
const chunks = []
|
|
176
|
-
let size = 0
|
|
177
|
-
request.on('data', (chunk) => {
|
|
178
|
-
size += chunk.length
|
|
179
|
-
if (size > MAX_BODY) {
|
|
180
|
-
resolve(undefined)
|
|
181
|
-
request.destroy()
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
chunks.push(chunk)
|
|
185
|
-
})
|
|
186
|
-
request.on('end', () => {
|
|
187
|
-
try {
|
|
188
|
-
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')))
|
|
189
|
-
} catch (reason) {
|
|
190
|
-
resolve(undefined)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
request.on('error', () => resolve(undefined))
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function apply(ctx) {
|
|
198
|
-
const electron = loadElectron()
|
|
199
|
-
const throttle = createThrottleControl(electron)
|
|
200
|
-
let config = normalizeConfig(DEFAULTS)
|
|
201
|
-
|
|
202
|
-
const sync = (next) => {
|
|
203
|
-
config = normalizeConfig(next)
|
|
204
|
-
// The switch says "throttle me in the background", which is Electron's own
|
|
205
|
-
// default; turning it off is what buys a page that keeps rendering.
|
|
206
|
-
throttle.apply(config.backgroundThrottle)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
readConfig()
|
|
210
|
-
.then((stored) => sync(stored))
|
|
211
|
-
.catch(() => sync(DEFAULTS))
|
|
212
|
-
|
|
213
|
-
let unregister
|
|
214
|
-
try {
|
|
215
|
-
const server = ctx?.webServer ?? (typeof ctx?.get === 'function' ? ctx.get('webServer') : undefined)
|
|
216
|
-
if (server !== undefined && server !== null && typeof server.register === 'function') {
|
|
217
|
-
unregister = server.register({
|
|
218
|
-
kind: 'exact',
|
|
219
|
-
path: ROUTE,
|
|
220
|
-
handler: async (request, response) => {
|
|
221
|
-
const method = String(request?.method ?? 'GET').toUpperCase()
|
|
222
|
-
if (method === 'GET' || method === 'HEAD') {
|
|
223
|
-
return sendJson(response, 200, { config, electron: electron !== null })
|
|
224
|
-
}
|
|
225
|
-
if (method !== 'POST') return sendJson(response, 405, { status: 'method' })
|
|
226
|
-
const body = await readBody(request)
|
|
227
|
-
if (body === undefined) return sendJson(response, 400, { status: 'invalid' })
|
|
228
|
-
sync(body)
|
|
229
|
-
try {
|
|
230
|
-
await writeConfig(config)
|
|
231
|
-
} catch (reason) {
|
|
232
|
-
return sendJson(response, 500, { status: 'unstored', config, electron: electron !== null })
|
|
233
|
-
}
|
|
234
|
-
return sendJson(response, 200, { config, electron: electron !== null })
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
} catch (reason) {
|
|
239
|
-
unregister = undefined
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (typeof ctx?.effect === 'function') {
|
|
243
|
-
ctx.effect(() => () => {
|
|
244
|
-
if (typeof unregister === 'function') unregister()
|
|
245
|
-
throttle.dispose()
|
|
246
|
-
}, 'dsh-ui-smooth: host wiring')
|
|
247
|
-
}
|
|
248
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Host loader entry for dsh-ui-smooth.
|
|
3
|
+
*
|
|
4
|
+
* The page does the work; this half owns the one thing a page cannot do for
|
|
5
|
+
* itself: the config file. Both thresholds live in
|
|
6
|
+
* `$DSH_HOME/dsh-ui-smooth.json` and are served to the page over
|
|
7
|
+
* `/dsh-ui-smooth/config`, so the settings section reads and writes one value
|
|
8
|
+
* that survives a rebuild.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
12
|
+
import { homedir } from 'node:os'
|
|
13
|
+
import { dirname, join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
export const name = 'dsh-ui-smooth'
|
|
16
|
+
/** The route needs the HTTP server; a host without one simply does not mount this plugin. */
|
|
17
|
+
export const inject = ['webServer']
|
|
18
|
+
|
|
19
|
+
const ROUTE = '/dsh-ui-smooth/config'
|
|
20
|
+
const FILE_NAME = 'dsh-ui-smooth.json'
|
|
21
|
+
const MAX_BODY = 8 * 1024
|
|
22
|
+
|
|
23
|
+
const DEFAULTS = {
|
|
24
|
+
animations: true,
|
|
25
|
+
backgroundThrottle: true,
|
|
26
|
+
duringStream: true,
|
|
27
|
+
follow: true,
|
|
28
|
+
skip: { enabled: true, turns: 3, minutes: 5 },
|
|
29
|
+
unmount: { enabled: true, turns: 5, minutes: 16 },
|
|
30
|
+
release: { enabled: false, turns: 8, minutes: 20 }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function configPath() {
|
|
34
|
+
const home = process.env.DSH_HOME ?? join(homedir(), '.dsh')
|
|
35
|
+
return join(home, FILE_NAME)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function clampNumber(value, fallback, max) {
|
|
39
|
+
const number = Number(value)
|
|
40
|
+
if (!Number.isFinite(number) || number < 0) return fallback
|
|
41
|
+
return Math.min(max, Math.floor(number))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Accept only the shape the page is allowed to store. */
|
|
45
|
+
function normalizeTier(source, key) {
|
|
46
|
+
const tier = source?.[key] ?? {}
|
|
47
|
+
return {
|
|
48
|
+
enabled: tier.enabled !== false,
|
|
49
|
+
turns: clampNumber(tier.turns, DEFAULTS[key].turns, 10000),
|
|
50
|
+
minutes: clampNumber(tier.minutes, DEFAULTS[key].minutes, 10000)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The aggressive tier keeps a tail of turns and waits out a quiet period. */
|
|
55
|
+
function normalizeRelease(source) {
|
|
56
|
+
const tier = source?.release ?? {}
|
|
57
|
+
return {
|
|
58
|
+
enabled: tier.enabled === true,
|
|
59
|
+
turns: Math.max(2, clampNumber(tier.turns, DEFAULTS.release.turns, 10000)),
|
|
60
|
+
minutes: clampNumber(tier.minutes, DEFAULTS.release.minutes, 10000)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function normalizeConfig(raw) {
|
|
65
|
+
const source = raw !== null && typeof raw === 'object' ? raw : {}
|
|
66
|
+
return {
|
|
67
|
+
animations: source.animations !== false,
|
|
68
|
+
backgroundThrottle: source.backgroundThrottle !== false,
|
|
69
|
+
duringStream: source.duringStream !== false,
|
|
70
|
+
follow: source.follow !== false,
|
|
71
|
+
skip: normalizeTier(source, 'skip'),
|
|
72
|
+
unmount: normalizeTier(source, 'unmount'),
|
|
73
|
+
release: normalizeRelease(source)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function readConfig() {
|
|
78
|
+
try {
|
|
79
|
+
const text = await readFile(configPath(), 'utf8')
|
|
80
|
+
return normalizeConfig(JSON.parse(text))
|
|
81
|
+
} catch (reason) {
|
|
82
|
+
return normalizeConfig(DEFAULTS)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function writeConfig(config) {
|
|
87
|
+
const path = configPath()
|
|
88
|
+
await mkdir(dirname(path), { recursive: true })
|
|
89
|
+
await writeFile(path, `${JSON.stringify(config, null, 2)}\n`, 'utf8')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sendJson(response, status, payload) {
|
|
93
|
+
const body = JSON.stringify(payload)
|
|
94
|
+
response.statusCode = status
|
|
95
|
+
response.setHeader('content-type', 'application/json; charset=utf-8')
|
|
96
|
+
response.setHeader('cache-control', 'no-store')
|
|
97
|
+
response.end(body)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function readBody(request) {
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
const chunks = []
|
|
103
|
+
let size = 0
|
|
104
|
+
request.on('data', (chunk) => {
|
|
105
|
+
size += chunk.length
|
|
106
|
+
if (size > MAX_BODY) {
|
|
107
|
+
resolve(undefined)
|
|
108
|
+
request.destroy()
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
chunks.push(chunk)
|
|
112
|
+
})
|
|
113
|
+
request.on('end', () => {
|
|
114
|
+
try {
|
|
115
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString('utf8')))
|
|
116
|
+
} catch (reason) {
|
|
117
|
+
resolve(undefined)
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
request.on('error', () => resolve(undefined))
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function apply(ctx) {
|
|
125
|
+
let config = normalizeConfig(DEFAULTS)
|
|
126
|
+
|
|
127
|
+
const sync = (next) => {
|
|
128
|
+
config = normalizeConfig(next)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
readConfig()
|
|
132
|
+
.then((stored) => sync(stored))
|
|
133
|
+
.catch(() => sync(DEFAULTS))
|
|
134
|
+
|
|
135
|
+
let unregister
|
|
136
|
+
try {
|
|
137
|
+
const server = ctx?.webServer ?? (typeof ctx?.get === 'function' ? ctx.get('webServer') : undefined)
|
|
138
|
+
if (server !== undefined && server !== null && typeof server.register === 'function') {
|
|
139
|
+
unregister = server.register({
|
|
140
|
+
kind: 'exact',
|
|
141
|
+
path: ROUTE,
|
|
142
|
+
handler: async (request, response) => {
|
|
143
|
+
const method = String(request?.method ?? 'GET').toUpperCase()
|
|
144
|
+
if (method === 'GET' || method === 'HEAD') {
|
|
145
|
+
return sendJson(response, 200, { config })
|
|
146
|
+
}
|
|
147
|
+
if (method !== 'POST') return sendJson(response, 405, { status: 'method' })
|
|
148
|
+
const body = await readBody(request)
|
|
149
|
+
if (body === undefined) return sendJson(response, 400, { status: 'invalid' })
|
|
150
|
+
sync(body)
|
|
151
|
+
try {
|
|
152
|
+
await writeConfig(config)
|
|
153
|
+
} catch (reason) {
|
|
154
|
+
return sendJson(response, 500, { status: 'unstored', config })
|
|
155
|
+
}
|
|
156
|
+
return sendJson(response, 200, { config })
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
} catch (reason) {
|
|
161
|
+
unregister = undefined
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof ctx?.effect === 'function') {
|
|
165
|
+
ctx.effect(() => () => {
|
|
166
|
+
if (typeof unregister === 'function') unregister()
|
|
167
|
+
}, 'dsh-ui-smooth: host wiring')
|
|
168
|
+
}
|
|
169
|
+
}
|
package/package.json
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-ui-smooth",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Web UI smoothness budget for DeepSeek Harness: keeps idle animations off the main thread, recycles old transcript turns, unloads old history from memory, and stops the desktop shell from freezing the page in the background.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"license": "GPL-3.0-or-later",
|
|
8
|
-
"author": "knight <knight-z@foxmail.com>",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/XKPU/dsh-ui-smooth.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/XKPU/dsh-ui-smooth/issues"
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://github.com/XKPU/dsh-ui-smooth#readme",
|
|
17
|
-
"icon": "./icon.svg",
|
|
18
|
-
"keywords": [
|
|
19
|
-
"dsh",
|
|
20
|
-
"dsh-plugin",
|
|
21
|
-
"deepseek-harness",
|
|
22
|
-
"performance",
|
|
23
|
-
"animation",
|
|
24
|
-
"layout",
|
|
25
|
-
"memory",
|
|
26
|
-
"cpu",
|
|
27
|
-
"web-ui"
|
|
28
|
-
],
|
|
29
|
-
"engines": {
|
|
30
|
-
"dsh": ">=0.2.0 <=0.2.3"
|
|
31
|
-
},
|
|
32
|
-
"exports": {
|
|
33
|
-
".": {
|
|
34
|
-
"default": "./lib/index.js"
|
|
35
|
-
},
|
|
36
|
-
"./client": {
|
|
37
|
-
"default": "./lib/client.js"
|
|
38
|
-
},
|
|
39
|
-
"./package.json": "./package.json",
|
|
40
|
-
"./locale/*.json": "./locale/*.json"
|
|
41
|
-
},
|
|
42
|
-
"files": [
|
|
43
|
-
"lib",
|
|
44
|
-
"src",
|
|
45
|
-
"scripts",
|
|
46
|
-
"cordis.patch.yml",
|
|
47
|
-
"icon.svg",
|
|
48
|
-
"README.md",
|
|
49
|
-
"CHANGELOG.md",
|
|
50
|
-
"LICENSE",
|
|
51
|
-
"locale"
|
|
52
|
-
],
|
|
53
|
-
"scripts": {
|
|
54
|
-
"build": "node scripts/build.mjs",
|
|
55
|
-
"pretest": "node scripts/build.mjs",
|
|
56
|
-
"test": "node test/engine.test.mjs"
|
|
57
|
-
},
|
|
58
|
-
"dsh": {
|
|
59
|
-
"manifestVersion": 1,
|
|
60
|
-
"bundle": {
|
|
61
|
-
"patch": "./cordis.patch.yml"
|
|
62
|
-
},
|
|
63
|
-
"client": {
|
|
64
|
-
"platform": "web",
|
|
65
|
-
"inject": []
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-ui-smooth",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Web UI smoothness budget for DeepSeek Harness: keeps idle animations off the main thread, recycles old transcript turns, unloads old history from memory, and stops the desktop shell from freezing the page in the background.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"license": "GPL-3.0-or-later",
|
|
8
|
+
"author": "knight <knight-z@foxmail.com>",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/XKPU/dsh-ui-smooth.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/XKPU/dsh-ui-smooth/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/XKPU/dsh-ui-smooth#readme",
|
|
17
|
+
"icon": "./icon.svg",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"dsh",
|
|
20
|
+
"dsh-plugin",
|
|
21
|
+
"deepseek-harness",
|
|
22
|
+
"performance",
|
|
23
|
+
"animation",
|
|
24
|
+
"layout",
|
|
25
|
+
"memory",
|
|
26
|
+
"cpu",
|
|
27
|
+
"web-ui"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"dsh": ">=0.2.0 <=0.2.3"
|
|
31
|
+
},
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"default": "./lib/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./client": {
|
|
37
|
+
"default": "./lib/client.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json",
|
|
40
|
+
"./locale/*.json": "./locale/*.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"lib",
|
|
44
|
+
"src",
|
|
45
|
+
"scripts",
|
|
46
|
+
"cordis.patch.yml",
|
|
47
|
+
"icon.svg",
|
|
48
|
+
"README.md",
|
|
49
|
+
"CHANGELOG.md",
|
|
50
|
+
"LICENSE",
|
|
51
|
+
"locale"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "node scripts/build.mjs",
|
|
55
|
+
"pretest": "node scripts/build.mjs",
|
|
56
|
+
"test": "node test/engine.test.mjs"
|
|
57
|
+
},
|
|
58
|
+
"dsh": {
|
|
59
|
+
"manifestVersion": 1,
|
|
60
|
+
"bundle": {
|
|
61
|
+
"patch": "./cordis.patch.yml"
|
|
62
|
+
},
|
|
63
|
+
"client": {
|
|
64
|
+
"platform": "web",
|
|
65
|
+
"inject": []
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|