dsh-screensaver 0.2.0 → 0.4.0
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/LICENSE-ASSETS.md +6 -6
- package/README.md +92 -28
- package/README.zh-CN.md +75 -24
- package/app/main.js +11 -9
- package/app/saver.js +63 -16
- package/app/screens.js +36 -0
- package/app/shell/index.html +2 -0
- package/app/shell/main.js +42 -11
- package/app/themes.js +5 -3
- package/bin/dsh-screensaver.js +14 -6
- package/cordis.patch.yml +3 -2
- package/docs/themes.md +22 -3
- package/lib/cli.js +182 -0
- package/lib/command.js +8 -5
- package/lib/index.js +4 -3
- package/lib/settings.js +99 -0
- package/llms.txt +11 -8
- package/native/unlock/main.swift +41 -10
- package/package.json +13 -3
- package/themes/magic-tower/LICENSE +9 -0
- package/themes/magic-tower/README.md +60 -0
- package/themes/magic-tower/THIRD_PARTY_NOTICES.md +20 -0
- package/themes/magic-tower/index.html +5023 -0
- package/themes/magic-tower/saver.json +1 -0
- package/themes/subspace/LICENSE +9 -0
- package/themes/subspace/README.md +52 -0
- package/themes/subspace/THIRD_PARTY_NOTICES.md +15 -0
- package/themes/subspace/index.html +4512 -0
- package/themes/subspace/saver.json +1 -0
package/app/saver.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 先进 simpleFullScreen(老式全屏,不新开桌面空间)再开 kiosk,不然 kiosk 会走原生全屏,把屏保放进单独的空间。
|
|
5
5
|
// - 窗口不是完全不透明(网页背景留一点点透明):完全挡住的话 Chrome 会把被挡的窗口当成隐藏,定时器和动画降频,
|
|
6
6
|
// 被挡住的浏览器里的 agent(靠扩展驱动的那种)也跟着降频。
|
|
7
|
-
// -
|
|
7
|
+
// - 屏保开着时不让系统睡、也不关屏;合盖睡眠也关掉(lidawake.js,lidAwake 默认开,写 false 才不管;没授权只提示一句)。
|
|
8
8
|
// - 解锁两条路(都是 native/unlock/ 的 desk-unlock,LocalAuthentication):
|
|
9
9
|
// 1. 直接摸 Touch ID:屏保一开就起 `desk-unlock --listen`。它在主屏上盖一层看不见的窗口(屏保上一层),
|
|
10
10
|
// 底部放系统的指纹小图标,并且自己当前台程序(Touch ID 只认前台程序,所以这期间屏保不抢焦点,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// - 主屏右上角跟系统菜单栏一样放电池、Wi-Fi、日期时间:`desk-unlock --status` 读(IOKit + CoreWLAN),每 20 秒一次。
|
|
16
16
|
// - 屏保里放什么由主题决定(themes.js 找到的目录,沙盒 iframe 里跑)。
|
|
17
17
|
// saver.json 写了 "sessions": true 的主题,屏保开着时才去读本机 agent 会话(agents.js),推给它显示。
|
|
18
|
+
// - 每块屏幕可以放不同的主题:配置 screens(主屏第一,其余从左到右;屏幕多出来的用最后一个),见 screens.js。
|
|
18
19
|
//
|
|
19
20
|
// 这不是安全边界:长按电源键之类的拦不住。它挡的是路过的人看屏幕、碰键盘。
|
|
20
21
|
import { execFile, spawn } from 'node:child_process'
|
|
@@ -27,6 +28,7 @@ import { dataDir } from './dirs.js'
|
|
|
27
28
|
import { ensureHelper } from './helper.js'
|
|
28
29
|
import { LidAwake } from './lidawake.js'
|
|
29
30
|
import { loadShell, mountTheme, preloadPath, themeUrl } from './paths.js'
|
|
31
|
+
import { assignThemes } from './screens.js'
|
|
30
32
|
import { DEFAULT_THEME, listThemes } from './themes.js'
|
|
31
33
|
|
|
32
34
|
export const DEFAULT_SHORTCUT = process.platform === 'darwin' ? 'Control+Alt+Command+L' : 'Control+Alt+Shift+L'
|
|
@@ -47,11 +49,15 @@ const SAY = {
|
|
|
47
49
|
en: "This Mac can't verify your identity, so the screen saver only covers the screen: a click opens it",
|
|
48
50
|
},
|
|
49
51
|
lidRecovered: { zh: '上次合盖不睡没关掉,已经恢复睡眠了', en: 'Lid-closed sleep was left disabled last time; restored it' },
|
|
52
|
+
lidUnauthorized: {
|
|
53
|
+
zh: '合盖不睡还没授权,合上盖子电脑照样睡:dsh 里输 /screensaver lid authorize,或终端跑 dsh-screensaver lid authorize(输一次管理员密码)',
|
|
54
|
+
en: 'Lid-closed awake is not authorized, so closing the lid still sleeps the Mac: run /screensaver lid authorize in dsh, or dsh-screensaver lid authorize in a terminal (admin password once)',
|
|
55
|
+
},
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
export class Screensaver {
|
|
53
59
|
/**
|
|
54
|
-
* @param {{ theme?: string, lidAwake?: boolean, idleMinutes?: number, shortcut?: string }} config
|
|
60
|
+
* @param {{ theme?: string, screens?: string[], lidAwake?: boolean, idleMinutes?: number, shortcut?: string }} config
|
|
55
61
|
* @param {{ say?: (text: string) => void, onState?: (active: boolean) => void }} hooks
|
|
56
62
|
* say:给人看的一句话(dsh 里打到日志);onState:屏保开了 / 关了
|
|
57
63
|
*/
|
|
@@ -60,7 +66,8 @@ export class Screensaver {
|
|
|
60
66
|
this.hooks = hooks
|
|
61
67
|
this.wins = new Map() // display.id → 窗口
|
|
62
68
|
this.kioskWin = null
|
|
63
|
-
|
|
69
|
+
/** 这次屏保的安排:明说的主题、每块屏幕的列表(屏幕插拔时按它重排) */
|
|
70
|
+
this.plan = null
|
|
64
71
|
this.blocker = null
|
|
65
72
|
this.authing = false
|
|
66
73
|
this.agents = new AgentWatcher()
|
|
@@ -77,7 +84,7 @@ export class Screensaver {
|
|
|
77
84
|
this.lidManual = false
|
|
78
85
|
this.helper = null
|
|
79
86
|
this.shortcut = null
|
|
80
|
-
this.onDisplayAdded = (_e, d) => this.cover(d)
|
|
87
|
+
this.onDisplayAdded = (_e, d) => this.cover(d, d.id === screen.getPrimaryDisplay().id)
|
|
81
88
|
this.onDisplayRemoved = (_e, d) => {
|
|
82
89
|
this.wins.get(d.id)?.destroy()
|
|
83
90
|
this.wins.delete(d.id)
|
|
@@ -161,25 +168,50 @@ export class Screensaver {
|
|
|
161
168
|
for (const w of win ? [win] : this.wins.values()) if (!w.isDestroyed()) w.webContents.send('saver:sessions', payload)
|
|
162
169
|
}
|
|
163
170
|
|
|
164
|
-
|
|
171
|
+
/** 这次屏保每块屏幕的主题:Map(display.id → 主题);明说了主题就所有屏幕都用它,否则按 screens(screens.js) */
|
|
172
|
+
screenThemes(plan = this.plan) {
|
|
173
|
+
const ids = assignThemes(screen.getAllDisplays(), screen.getPrimaryDisplay().id, {
|
|
174
|
+
theme: plan?.theme,
|
|
175
|
+
screens: plan?.theme ? undefined : plan?.screens,
|
|
176
|
+
})
|
|
177
|
+
const out = new Map()
|
|
178
|
+
for (const [id, themeId] of ids) {
|
|
179
|
+
const theme = this.theme(themeId)
|
|
180
|
+
if (theme) out.set(id, theme)
|
|
181
|
+
}
|
|
182
|
+
return out
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 开屏保。themeId:这一次所有屏幕都用这个主题(不给就按配置的 screens / theme)。
|
|
187
|
+
* opts.lidAwake:这一次要不要合盖不睡(`--now` 交给已经在跑的这个时带过来的),不给就看配置,配置没写算开。
|
|
188
|
+
* opts.screens:这一次每块屏幕的主题(同上,交给已经在跑的这个时带过来的),不给就看配置。
|
|
189
|
+
*/
|
|
190
|
+
async start(themeId, opts = {}) {
|
|
165
191
|
if (this.active) return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
192
|
+
this.plan = { theme: themeId, screens: opts.screens ?? this.config.screens }
|
|
193
|
+
const themes = [...this.screenThemes().values()]
|
|
194
|
+
if (!themes.length) {
|
|
195
|
+
this.plan = null
|
|
196
|
+
return this.say('[dsh-screensaver] no theme found')
|
|
197
|
+
}
|
|
198
|
+
for (const t of themes) mountTheme(t.id, t.dir)
|
|
170
199
|
if (!this.canAuthenticate()) this.say(SAY.noAuth[saverLang()])
|
|
171
|
-
if (this.config.lidAwake && !this.lid.active) {
|
|
200
|
+
if ((opts.lidAwake ?? this.config.lidAwake) !== false && !this.lid.active && this.lid.supported) {
|
|
172
201
|
try {
|
|
173
202
|
if (await this.lid.authorized()) {
|
|
174
203
|
await this.lid.on()
|
|
175
204
|
this.lidBySaver = this.lid.active
|
|
205
|
+
} else if (!this.lidHinted) {
|
|
206
|
+
this.lidHinted = true
|
|
207
|
+
this.say(SAY.lidUnauthorized[saverLang()])
|
|
176
208
|
}
|
|
177
209
|
} catch (e) {
|
|
178
210
|
this.say(`[dsh-screensaver] lid-awake failed: ${e?.message ?? e}`)
|
|
179
211
|
}
|
|
180
212
|
}
|
|
181
213
|
if (this.blocker === null) this.blocker = powerSaveBlocker.start('prevent-display-sleep')
|
|
182
|
-
this.wantsSessions =
|
|
214
|
+
this.wantsSessions = themes.some((t) => t.sessions)
|
|
183
215
|
if (this.wantsSessions) {
|
|
184
216
|
this.agents.lang = saverLang()
|
|
185
217
|
this.agents.start((list) => this.sendSessions(list))
|
|
@@ -194,7 +226,19 @@ export class Screensaver {
|
|
|
194
226
|
}
|
|
195
227
|
|
|
196
228
|
cover(d, primary = false) {
|
|
197
|
-
if (this.wins.has(d.id) || !this.
|
|
229
|
+
if (this.wins.has(d.id) || !this.plan) return
|
|
230
|
+
// 插上的屏幕会改变排序,所以每次按现在的屏幕重排一遍;只给还没盖的这块用,已经开着的不动
|
|
231
|
+
const theme = this.screenThemes().get(d.id) ?? this.theme(this.plan.theme)
|
|
232
|
+
if (!theme) return
|
|
233
|
+
mountTheme(theme.id, theme.dir)
|
|
234
|
+
if (process.env.DSH_SCREENSAVER_DEBUG) this.say(`[debug] screen ${d.id}${primary ? ' (main)' : ''} → ${theme.id}`)
|
|
235
|
+
if (theme.sessions && !this.wantsSessions) {
|
|
236
|
+
this.wantsSessions = true
|
|
237
|
+
this.agents.lang = saverLang()
|
|
238
|
+
this.agents.start((list) => this.sendSessions(list))
|
|
239
|
+
powerMonitor.on('on-battery', this.onPowerChange)
|
|
240
|
+
powerMonitor.on('on-ac', this.onPowerChange)
|
|
241
|
+
}
|
|
198
242
|
const b = d.bounds
|
|
199
243
|
const win = new BrowserWindow({
|
|
200
244
|
...b,
|
|
@@ -216,7 +260,7 @@ export class Screensaver {
|
|
|
216
260
|
win.setAlwaysOnTop(true, 'screen-saver')
|
|
217
261
|
if (process.platform === 'darwin') win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true, skipTransformProcessType: true })
|
|
218
262
|
this.wins.set(d.id, win)
|
|
219
|
-
void loadShell(win, { theme: themeUrl(
|
|
263
|
+
void loadShell(win, { theme: themeUrl(theme.id), primary: primary ? '1' : '', lang: saverLang(), hud: theme.hud ? '1' : '' }).catch((e) =>
|
|
220
264
|
this.say(`[dsh-screensaver] screen failed to load: ${e?.message ?? e}`),
|
|
221
265
|
)
|
|
222
266
|
win.webContents.on('render-process-gone', (_e, d) => this.say(`[dsh-screensaver] screen renderer gone: ${d.reason}`))
|
|
@@ -310,12 +354,14 @@ export class Screensaver {
|
|
|
310
354
|
const child = spawn(this.helper, ['--listen', '--lang', lang, REASON[lang]], { stdio: ['ignore', 'pipe', 'pipe'] })
|
|
311
355
|
this.listener = child
|
|
312
356
|
let out = ''
|
|
313
|
-
//
|
|
357
|
+
// 摸到传感器打一行 touch match(认出来了)/ touch miss(没认出来):让主屏把 30 秒后藏起来的提示、状态栏露出来,
|
|
358
|
+
// 自己画提示的主题("hud": true)还拿它做反馈。老版本只打 touch。
|
|
314
359
|
// 输出一块块来,一行可能被切成两块,所以先拼成整行再认
|
|
315
360
|
const readLine = lineReader((line) => {
|
|
316
|
-
|
|
361
|
+
const m = /^touch(?: (match|miss))?$/.exec(line)
|
|
362
|
+
if (!m) return
|
|
317
363
|
const win = this.kioskWin
|
|
318
|
-
if (win && !win.isDestroyed()) win.webContents.send('saver:touch')
|
|
364
|
+
if (win && !win.isDestroyed()) win.webContents.send('saver:touch', m[1] ?? '')
|
|
319
365
|
})
|
|
320
366
|
child.stdout?.on('data', (b) => {
|
|
321
367
|
out += b
|
|
@@ -365,6 +411,7 @@ export class Screensaver {
|
|
|
365
411
|
powerMonitor.off('on-battery', this.onPowerChange)
|
|
366
412
|
powerMonitor.off('on-ac', this.onPowerChange)
|
|
367
413
|
this.wantsSessions = false
|
|
414
|
+
this.plan = null
|
|
368
415
|
if (this.kioskWin && !this.kioskWin.isDestroyed()) {
|
|
369
416
|
this.kioskWin.setKiosk(false)
|
|
370
417
|
if (process.platform === 'darwin') this.kioskWin.setSimpleFullScreen(false)
|
package/app/screens.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// 每块屏幕放哪个主题。不碰 Electron,好测。
|
|
2
|
+
//
|
|
3
|
+
// 配置 screens 是一串主题 id,按屏幕顺序排:第一个给主屏,后面的给其余屏幕(从左到右,左右一样再从上到下)。
|
|
4
|
+
// 屏幕比列表多时,多出来的用最后一个:["magic-tower", "subspace"] 就是「主屏魔法书斋,别的屏都是亚空间」。
|
|
5
|
+
// screens 空着(默认)所有屏幕用同一个主题(theme)。
|
|
6
|
+
// 开屏保时明说了一个主题(`--now subspace`、/screensaver subspace),这一次所有屏幕都用它,不看 screens。
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 屏幕排顺序:主屏第一,其余从左到右,左右一样再从上到下。
|
|
10
|
+
* @param {{ id: number, bounds: { x: number, y: number } }[]} displays
|
|
11
|
+
* @param {number} primaryId
|
|
12
|
+
*/
|
|
13
|
+
export function orderDisplays(displays, primaryId) {
|
|
14
|
+
const rest = displays.filter((d) => d.id !== primaryId).sort((a, b) => a.bounds.x - b.bounds.x || a.bounds.y - b.bounds.y)
|
|
15
|
+
const primary = displays.find((d) => d.id === primaryId)
|
|
16
|
+
return primary ? [primary, ...rest] : rest
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** 第 index 块屏幕(0 = 主屏)用哪个主题 id;screens 空着就是 fallback */
|
|
20
|
+
export function themeForScreen(index, screens, fallback) {
|
|
21
|
+
const list = Array.isArray(screens) ? screens.filter((s) => typeof s === 'string' && s) : []
|
|
22
|
+
if (!list.length) return fallback
|
|
23
|
+
return list[Math.min(index, list.length - 1)]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 每块屏幕的主题 id:Map(display.id → 主题 id)。
|
|
28
|
+
* @param {{ id: number, bounds: { x: number, y: number } }[]} displays
|
|
29
|
+
* @param {number} primaryId
|
|
30
|
+
* @param {{ theme?: string, screens?: string[] }} plan theme:明说的 / 配置的主题;screens:每块屏幕的
|
|
31
|
+
*/
|
|
32
|
+
export function assignThemes(displays, primaryId, { theme, screens } = {}) {
|
|
33
|
+
const out = new Map()
|
|
34
|
+
orderDisplays(displays, primaryId).forEach((d, i) => out.set(d.id, themeForScreen(i, screens, theme)))
|
|
35
|
+
return out
|
|
36
|
+
}
|
package/app/shell/index.html
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
/* 纯享:进屏保 30 秒没人动,底部那行字、右上角状态栏都淡掉(主题那边同时藏会话播报),只剩画面 */
|
|
21
21
|
#hint, #status { transition: opacity 1.2s ease; }
|
|
22
22
|
body.pure #hint, body.pure #status { opacity: 0; }
|
|
23
|
+
/* 主题自己画状态栏和提示(saver.json 的 "hud": true):外壳的藏起来,但照样算好内容转给主题 */
|
|
24
|
+
body.theme-hud #hint, body.theme-hud #status { visibility: hidden; }
|
|
23
25
|
/* 右上角:电池、Wi-Fi、日期时间,位置、大小、写法照着系统菜单栏(「11月15日 周日 下午6:10」) */
|
|
24
26
|
#status {
|
|
25
27
|
position: fixed; top: 6px; right: 14px; height: 24px; display: flex; align-items: center; gap: 13px;
|
package/app/shell/main.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// 通过了主进程会关掉所有屏保窗口。
|
|
4
4
|
// 主屏照着系统锁屏:底部一行「使用触控 ID 或输入密码」,右上角电池、Wi-Fi、菜单栏样式的日期时间;副屏只放主题画面。
|
|
5
5
|
// 纯享:30 秒没人动,这些连同主题里的会话播报都淡掉,只剩画面;动鼠标、按键、摸 Touch ID 再露出来。
|
|
6
|
+
// 主题的 saver.json 写了 "hud": true(地址带 hud=1):右上角状态栏、底部提示由主题自己画,位置不变。
|
|
7
|
+
// 外壳自己的藏起来,电池 / Wi-Fi(desk:status)、提示(desk:hint)、摸了指纹(desk:touch)照样算好转给主题。
|
|
6
8
|
const desk = window.desk // preload.cjs 给的
|
|
7
9
|
const q = new URLSearchParams(location.search)
|
|
8
10
|
const primary = q.get('primary') === '1'
|
|
@@ -10,6 +12,12 @@ const frame = document.getElementById('theme')
|
|
|
10
12
|
const hint = document.getElementById('hint')
|
|
11
13
|
const $ = (id) => document.getElementById(id)
|
|
12
14
|
const theme = q.get('theme')
|
|
15
|
+
const hud = primary && q.get('hud') === '1'
|
|
16
|
+
if (hud) document.body.classList.add('theme-hud')
|
|
17
|
+
/** 发给主题(沙盒 iframe,没有同源,只能 postMessage) */
|
|
18
|
+
function toTheme(msg) {
|
|
19
|
+
frame.contentWindow?.postMessage(msg, '*')
|
|
20
|
+
}
|
|
13
21
|
// 主题也拿到语言(?lang=zh|en),自己决定日期之类怎么写
|
|
14
22
|
if (theme) frame.src = `${theme}?lang=${q.get('lang') === 'zh' ? 'zh' : 'en'}`
|
|
15
23
|
// 文案照抄系统锁屏
|
|
@@ -35,12 +43,19 @@ let IDLE_HINT = ''
|
|
|
35
43
|
let busy = false
|
|
36
44
|
let hideTimer = 0
|
|
37
45
|
let hintTimer = 0
|
|
46
|
+
/** 现在底部那行字和它是哪种:idle 平时 / verifying 验证中 / failed 没解开(hud 主题拿去画) */
|
|
47
|
+
let hintNow = { text: '', state: 'idle' }
|
|
48
|
+
function showHint(text, state) {
|
|
49
|
+
hint.textContent = text
|
|
50
|
+
hintNow = { text, state }
|
|
51
|
+
if (hud) toTheme({ type: 'desk:hint', ...hintNow })
|
|
52
|
+
}
|
|
38
53
|
/** 底部那行字:平时是 IDLE_HINT,验证中、没解开时临时换一句,过一会儿换回来 */
|
|
39
|
-
function say(text, ms = 0) {
|
|
54
|
+
function say(text, ms = 0, state = 'idle') {
|
|
40
55
|
if (!primary) return
|
|
41
|
-
|
|
56
|
+
showHint(text, state)
|
|
42
57
|
clearTimeout(hintTimer)
|
|
43
|
-
if (ms) hintTimer = window.setTimeout(() => (
|
|
58
|
+
if (ms) hintTimer = window.setTimeout(() => showHint(IDLE_HINT, 'idle'), ms)
|
|
44
59
|
}
|
|
45
60
|
// ---- 纯享:PURE_AFTER_MS 没人动就藏起提示、状态栏,告诉主题也藏起它的播报 ----
|
|
46
61
|
const PURE_AFTER_MS = 30_000
|
|
@@ -49,7 +64,7 @@ let pureTimer = 0
|
|
|
49
64
|
function setPure(on) {
|
|
50
65
|
pure = on
|
|
51
66
|
document.body.classList.toggle('pure', on)
|
|
52
|
-
|
|
67
|
+
toTheme({ type: 'desk:pure', on })
|
|
53
68
|
}
|
|
54
69
|
/** 有人动了(或刚进屏保):都露出来,重新数 30 秒 */
|
|
55
70
|
function reveal() {
|
|
@@ -65,16 +80,19 @@ function wake() {
|
|
|
65
80
|
clearTimeout(hideTimer)
|
|
66
81
|
hideTimer = window.setTimeout(() => !busy && document.body.classList.remove('awake'), 4000)
|
|
67
82
|
}
|
|
68
|
-
// 摸了 Touch ID
|
|
69
|
-
desk.on('saver:touch', () =>
|
|
83
|
+
// 摸了 Touch ID(主进程转过来的):同样露出来;result 是 match(认出来了)/ miss(没认出来)/ ''(老版本分不出来)
|
|
84
|
+
desk.on('saver:touch', (result) => {
|
|
85
|
+
reveal()
|
|
86
|
+
if (hud) toTheme({ type: 'desk:touch', result: result === 'match' || result === 'miss' ? result : '' })
|
|
87
|
+
})
|
|
70
88
|
async function unlock() {
|
|
71
89
|
if (busy) return
|
|
72
90
|
busy = true
|
|
73
91
|
wake()
|
|
74
|
-
say(t.verifying)
|
|
92
|
+
say(t.verifying, 0, 'verifying')
|
|
75
93
|
try {
|
|
76
94
|
const r = await desk.invoke('saver:unlock')
|
|
77
|
-
if (!r.ok) say(r.msg ? t.failed(r.msg) : IDLE_HINT, r.msg ? 4000 : 0)
|
|
95
|
+
if (!r.ok) say(r.msg ? t.failed(r.msg) : IDLE_HINT, r.msg ? 4000 : 0, r.msg ? 'failed' : 'idle')
|
|
78
96
|
} finally {
|
|
79
97
|
busy = false
|
|
80
98
|
}
|
|
@@ -101,17 +119,28 @@ addEventListener('mousemove', (e) => {
|
|
|
101
119
|
// 主题是沙盒 iframe(没有同源),只能 postMessage;主题开好后会发 desk:ready 来要一份。
|
|
102
120
|
// 一起带上:是不是主屏(副屏主题只放画面)、是不是在用电池(主题降帧率、降分辨率)。
|
|
103
121
|
let latest = null
|
|
122
|
+
let status = null
|
|
104
123
|
function forward() {
|
|
105
|
-
if (latest
|
|
124
|
+
if (latest) toTheme({ type: 'desk:sessions', primary, ...latest })
|
|
125
|
+
}
|
|
126
|
+
/** hud 主题开好了(或开得晚):补一份提示和电池、Wi-Fi */
|
|
127
|
+
function forwardHud() {
|
|
128
|
+
if (!hud) return
|
|
129
|
+
toTheme({ type: 'desk:hint', ...hintNow })
|
|
130
|
+
if (status) toTheme({ type: 'desk:status', ...status })
|
|
106
131
|
}
|
|
107
132
|
desk.on('saver:sessions', (p) => {
|
|
108
133
|
latest = p
|
|
109
134
|
forward()
|
|
110
135
|
})
|
|
111
|
-
frame.addEventListener('load',
|
|
136
|
+
frame.addEventListener('load', () => {
|
|
137
|
+
forward()
|
|
138
|
+
forwardHud()
|
|
139
|
+
})
|
|
112
140
|
addEventListener('message', (e) => {
|
|
113
141
|
if (e.source !== frame.contentWindow || e.data?.type !== 'desk:ready') return
|
|
114
142
|
forward()
|
|
143
|
+
forwardHud()
|
|
115
144
|
if (pure) setPure(true) // 主题开得晚:补一句
|
|
116
145
|
})
|
|
117
146
|
void desk.invoke('saver:info').then((info) => {
|
|
@@ -121,6 +150,8 @@ void desk.invoke('saver:info').then((info) => {
|
|
|
121
150
|
})
|
|
122
151
|
const svgEl = (sel) => document.querySelector(sel)
|
|
123
152
|
desk.on('saver:status', (st) => {
|
|
153
|
+
status = { battery: st.battery ?? null, wifi: st.wifi ?? null }
|
|
154
|
+
if (hud) toTheme({ type: 'desk:status', ...status })
|
|
124
155
|
const b = st.battery
|
|
125
156
|
$('batt').hidden = !b
|
|
126
157
|
if (b) {
|
|
@@ -156,7 +187,7 @@ function tick() {
|
|
|
156
187
|
$('clockT').textContent = zh ? `${h < 12 ? '上午' : '下午'}${h12}:${mm}` : `${h12}:${mm} ${h < 12 ? 'AM' : 'PM'}`
|
|
157
188
|
}
|
|
158
189
|
if (primary) {
|
|
159
|
-
$('status').hidden =
|
|
190
|
+
$('status').hidden = hud
|
|
160
191
|
tick()
|
|
161
192
|
// 对准整分钟换
|
|
162
193
|
window.setTimeout(
|
package/app/themes.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// 屏保主题从哪来。主题就是一个目录:index.html(在沙盒 iframe 里跑,只管画)+ saver.json(名字、要不要会话)。
|
|
2
2
|
//
|
|
3
3
|
// 主题可以分开装,想要哪个装哪个:
|
|
4
|
-
// 1. 这个包自带的 themes
|
|
5
|
-
// 2. 装在旁边的主题包:package.json 里写了 "dsh-screensaver": { "theme": "<目录,默认 .>" } 的 npm
|
|
6
|
-
//
|
|
4
|
+
// 1. 这个包自带的 themes/(「时钟」basic、「亚空间跃迁」subspace、「魔法书斋」magic-tower,都随包发布);
|
|
5
|
+
// 2. 装在旁边的主题包:package.json 里写了 "dsh-screensaver": { "theme": "<目录,默认 .>" } 的 npm 包
|
|
6
|
+
// (别人做的第三方主题;id 和自带的重了以自带的为准)。dsh 的 profile 是 hoisted 布局,
|
|
7
7
|
// 主题包和本包都在同一个 node_modules 下,看本包的上一层(带 @scope 的再往下一层);
|
|
8
8
|
// 3. 环境变量 DSH_SCREENSAVER_THEMES 列的目录(: 分隔,每个是一个主题,或者装着好几个主题的目录);
|
|
9
9
|
// 4. 数据目录下的 themes/<id>/,自己做着玩的主题放这里就行。
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
// { "id": "subspace", "name": { "zh": "亚空间跃迁", "en": "Subspace Jump" }, "sessions": true }
|
|
13
13
|
// id 不写就用目录名(主题包用包名去掉 dsh-screensaver-theme- 前缀);name 可以是字符串;
|
|
14
14
|
// "sessions": true 的主题才拿得到本机 Claude Code / Codex / DeepSeek Harness 会话的名字和进展。
|
|
15
|
+
// "hud": true 的主题自己画右上角状态栏和底部提示(外壳把电池、Wi-Fi、提示、摸了指纹转给它,自己的藏起来)。
|
|
15
16
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
16
17
|
import { basename, delimiter, dirname, join, resolve } from 'node:path'
|
|
17
18
|
import { dataDir, PKG_DIR } from './dirs.js'
|
|
@@ -46,6 +47,7 @@ export function readTheme(dir, fallbackId = basename(dir), lang = 'en') {
|
|
|
46
47
|
if (name && typeof name === 'object') name = name[lang] ?? name.en ?? name.zh ?? Object.values(name)[0]
|
|
47
48
|
const theme = { id, name: typeof name === 'string' && name.trim() ? name.trim() : id, dir: resolve(dir) }
|
|
48
49
|
if (meta.sessions === true) theme.sessions = true
|
|
50
|
+
if (meta.hud === true) theme.hud = true
|
|
49
51
|
return theme
|
|
50
52
|
}
|
|
51
53
|
|
package/bin/dsh-screensaver.js
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
// npx github:realRoc/dsh-screensaver 常驻,按 ⌃⌥⌘L 开屏保(Ctrl+C 退出)
|
|
4
4
|
// npx github:realRoc/dsh-screensaver --now 马上开屏保,解开后退出(适合让 AI agent 在你走开前跑一下)
|
|
5
5
|
// npx github:realRoc/dsh-screensaver --now subspace
|
|
6
|
-
//
|
|
6
|
+
// npx dsh-screensaver setup 改配置(合盖不睡、主题、空闲自动开),别的子命令见 lib/cli.js
|
|
7
|
+
// 配置存在数据目录的 config.json(lib/settings.js);环境变量 DSH_SCREENSAVER_CONFIG(JSON)临时盖过它。
|
|
8
|
+
import { CLI_USAGE, runCli } from '../lib/cli.js'
|
|
7
9
|
import { launch } from '../lib/launcher.js'
|
|
10
|
+
import { explicitConfig } from '../lib/settings.js'
|
|
8
11
|
|
|
9
12
|
const args = process.argv.slice(2)
|
|
10
13
|
if (args.includes('--help') || args.includes('-h')) {
|
|
@@ -15,14 +18,19 @@ Usage:
|
|
|
15
18
|
dsh-screensaver --now [theme] start right away and exit after you unlock
|
|
16
19
|
|
|
17
20
|
Unlock with Touch ID (just touch the sensor) or any key / click for the password dialog.
|
|
18
|
-
|
|
21
|
+
Lid-closed awake is on by default once you allow it: dsh-screensaver lid authorize
|
|
22
|
+
|
|
23
|
+
${CLI_USAGE}
|
|
24
|
+
|
|
25
|
+
One-off overrides: DSH_SCREENSAVER_CONFIG='{"theme":"subspace","idleMinutes":10,"lidAwake":false}'`)
|
|
19
26
|
process.exit(0)
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
const code = await runCli(args)
|
|
30
|
+
if (code !== null) process.exit(code)
|
|
31
|
+
|
|
32
|
+
// 只传写了的项:默认值交给屏保进程(saver.js),不然交给常驻实例时会把默认的 lidAwake 当成这次的要求
|
|
33
|
+
const config = explicitConfig()
|
|
26
34
|
|
|
27
35
|
try {
|
|
28
36
|
const child = await launch({ args, config })
|
package/cordis.patch.yml
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
# - id: dsh-screensaver
|
|
9
9
|
# config:
|
|
10
10
|
# theme: subspace
|
|
11
|
+
# screens: [magic-tower, subspace] # 每块屏幕不同:主屏魔法书斋,其余屏幕亚空间(不写 = 都用 theme)
|
|
11
12
|
# idleMinutes: 10
|
|
12
|
-
# lidAwake:
|
|
13
|
+
# lidAwake: false # 合盖不睡默认开(授权过才生效),不要就写 false
|
|
13
14
|
- insert:
|
|
14
15
|
- id: dsh-screensaver
|
|
15
16
|
name: dsh-screensaver
|
|
16
17
|
config:
|
|
17
18
|
theme: basic
|
|
18
19
|
idleMinutes: 0
|
|
19
|
-
lidAwake:
|
|
20
|
+
lidAwake: true
|
|
20
21
|
- id: dsh-screensaver-command
|
|
21
22
|
name: dsh-screensaver/command
|
|
22
23
|
- id: dsh-screensaver-tool
|
package/docs/themes.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Theme API
|
|
2
2
|
|
|
3
|
+
Building a theme with a coding agent? Give it [skills/dsh-screensaver-theme](../skills/dsh-screensaver-theme/SKILL.md):
|
|
4
|
+
the layout, timing and behaviour rules every theme follows, on top of the API below.
|
|
5
|
+
|
|
3
6
|
The theme API (this document, the shell and the message formats) is MIT: build your own theme on it and license it
|
|
4
7
|
however you like. The themes shipped in this repo are CC BY-NC-SA 4.0 (see [LICENSE-ASSETS.md](../LICENSE-ASSETS.md)).
|
|
5
8
|
|
|
@@ -8,17 +11,23 @@ A theme is a folder:
|
|
|
8
11
|
```
|
|
9
12
|
my-theme/
|
|
10
13
|
index.html # the whole theme; runs in a sandboxed iframe (allow-scripts only, no network)
|
|
11
|
-
saver.json # { "id": "my-theme", "name": { "en": "My Theme", "zh": "我的主题" }, "sessions": true }
|
|
14
|
+
saver.json # { "id": "my-theme", "name": { "en": "My Theme", "zh": "我的主题" }, "sessions": true, "hud": true }
|
|
12
15
|
```
|
|
13
16
|
|
|
14
17
|
- `id`: lowercase letters, digits and `-`. Defaults to the folder name (or the package name without
|
|
15
18
|
`dsh-screensaver-theme-`).
|
|
16
19
|
- `name`: a string, or `{ "en": ..., "zh": ... }` picked by the system language.
|
|
17
20
|
- `sessions`: `true` to receive local agent sessions. Only themes that ask get session names and progress.
|
|
21
|
+
- `hud`: `true` to draw the top-right status bar and the bottom hint yourself, in your theme's style. The shell hides its
|
|
22
|
+
own and sends you what they would show (`desk:status`, `desk:hint`, `desk:touch` below). Keep them where the shell
|
|
23
|
+
puts them: status bar at the top right like the menu bar (`top: 6px; right: 14px; height: 24px`), hint centred
|
|
24
|
+
`7vh` above the bottom edge. The system Touch ID icon still appears above the hint when the sensor is touched
|
|
25
|
+
(centre about `7vh + 52px` from the bottom); draw around it, not over it. The time and date you compute yourself.
|
|
18
26
|
|
|
19
27
|
The theme only draws. The shell around it owns the keyboard, mouse, Touch ID, the bottom hint and the top-right status
|
|
20
|
-
bar (battery, Wi-Fi, date and time)
|
|
21
|
-
scripts, styles and images (data: URLs). `themes/subspace/scripts/build.mjs` shows one way to bundle with esbuild
|
|
28
|
+
bar (battery, Wi-Fi, date and time), unless the theme sets `"hud": true`. Keep `index.html` self-contained: the sandbox has an opaque origin, so inline your
|
|
29
|
+
scripts, styles and images (data: URLs). `themes/subspace/scripts/build.mjs` shows one way to bundle with esbuild;
|
|
30
|
+
`themes/magic-tower` uses `"hud": true`.
|
|
22
31
|
|
|
23
32
|
## Query string
|
|
24
33
|
|
|
@@ -49,6 +58,16 @@ Listen with `addEventListener('message', ...)` and check `event.source === paren
|
|
|
49
58
|
|
|
50
59
|
// Pure mode: 30 s without input. Hide your overlays (text, lists) and keep only the animation.
|
|
51
60
|
{ type: 'desk:pure', on: true | false }
|
|
61
|
+
|
|
62
|
+
// Only on the primary display, and only to themes with "hud": true. A desk:hint means the shell has handed you the
|
|
63
|
+
// status bar and the hint, so show yours once it arrives (an older shell never sends it and draws its own).
|
|
64
|
+
// The hint line, already localized: 'Touch ID or Enter Password', 'Verifying…', 'Still locked: …'.
|
|
65
|
+
{ type: 'desk:hint', text: 'Touch ID or Enter Password', state: 'idle' | 'verifying' | 'failed' }
|
|
66
|
+
// Battery and Wi-Fi, every 20 s. null when the Mac has none or it could not be read.
|
|
67
|
+
{ type: 'desk:status', battery: { percent: 82, plugged: false } | null, wifi: { on: true, connected: true, rssi: -52 } | null }
|
|
68
|
+
// The Touch ID sensor was touched. 'match': recognized (the screen saver closes about half a second later);
|
|
69
|
+
// 'miss': not recognized, the user can try again; '': an older Touch ID helper that can't tell.
|
|
70
|
+
{ type: 'desk:touch', result: 'match' | 'miss' | '' }
|
|
52
71
|
```
|
|
53
72
|
|
|
54
73
|
Post `{ type: 'desk:ready' }` to `parent` once your script is running to get the current session list.
|