dsh-screensaver 0.2.0 → 0.3.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/README.md CHANGED
@@ -13,7 +13,7 @@ with `npx`.
13
13
 
14
14
  ![Subspace Jump theme: Claude Code, Codex and DeepSeek Harness sessions listed during a warp jump](docs/images/subspace.jpg)
15
15
 
16
- | Clock (built in) | Subspace Jump (separate theme package) |
16
+ | Clock (built in) | Subspace Jump (built in) |
17
17
  | --- | --- |
18
18
  | ![Clock theme: a macOS-style lock screen with date, time, battery, Wi-Fi and "Touch ID or Enter Password"](docs/images/basic-zh.jpg) | A three.js warp tunnel (above): when agents are running it jumps into subspace and lists each session with its own product icon. Inside, it drifts between a nebula storm, a vortex of ocean waves and a tunnel of Gaussian splats. |
19
19
 
@@ -29,7 +29,7 @@ keep working and you only want the screen covered.
29
29
  | Computer-use agents and extension-driven browsers keep running | No, they stop ([openai/codex#58545](https://github.com/openai/codex/issues/58545), [openai/codex#43869](https://github.com/openai/codex/issues/43869)) | Not tested | Yes | Yes | **Browser-extension agents keep running**; anything that must click the screen is covered |
30
30
  | Covered browser windows keep full speed | No, the system treats them as hidden | Not tested | n/a | n/a | **Yes**: the cover is a tiny bit translucent, so the system still treats windows as visible |
31
31
  | Prevents display sleep and system idle sleep | No: the display soon goes dark, and whether the Mac then sleeps depends on other apps ([anthropics/claude-code#81832](https://github.com/anthropics/claude-code/issues/81832)) | No | No | Yes | **Yes, while it is up** |
32
- | Stays awake with the **lid closed** | No | No | No | No (sleep assertions cannot stop lid sleep) | **Optional** (`pmset disablesleep` with a one-time admin authorization, auto-restored) |
32
+ | Stays awake with the **lid closed** | No | No | No | No (sleep assertions cannot stop lid sleep) | **Yes, on by default** once you allow it (`pmset disablesleep` with a one-time admin authorization, auto-restored) |
33
33
  | Unlock | Touch ID or password | Key press (+ password) | n/a | n/a | **Just touch Touch ID**, or press any key / click for Touch ID or the login password |
34
34
  | Shows what your agents are doing | No | No | No | No | **Yes** (themes that opt in: names, current step, running / waiting / done / stopped) |
35
35
 
@@ -45,31 +45,27 @@ use dsh-screensaver.
45
45
  ### As a DeepSeek Harness plugin
46
46
 
47
47
  ```bash
48
- dsh plugin --profile web add github:realRoc/dsh-screensaver
48
+ dsh plugin --profile web add dsh-screensaver
49
49
  ```
50
50
 
51
51
  Use `desktop` instead of `web` for the desktop app profile, then restart dsh. The first start downloads the Electron
52
52
  runtime (about 100 MB, once) and compiles the Touch ID helper if the Xcode Command Line Tools are installed.
53
53
 
54
- Themes are separate packages. Install only the ones you want:
55
-
56
- ```bash
57
- dsh plugin --profile web add "github:realRoc/dsh-screensaver#path:/themes/subspace"
58
- ```
54
+ Both themes, Clock and Subspace Jump, ship inside this package; there is nothing else to install.
59
55
 
60
- No git on the machine, or you prefer a fixed release? Install the packaged release instead:
56
+ Want the latest unreleased code from GitHub instead of the npm release:
61
57
 
62
58
  ```bash
63
- dsh plugin --profile web add https://github.com/realRoc/dsh-screensaver/releases/latest/download/dsh-screensaver.tgz
64
- dsh plugin --profile web add https://github.com/realRoc/dsh-screensaver/releases/latest/download/dsh-screensaver-theme-subspace.tgz
59
+ dsh plugin --profile web add github:realRoc/dsh-screensaver
65
60
  ```
66
61
 
67
62
  ### Without dsh
68
63
 
69
64
  ```bash
70
- npx github:realRoc/dsh-screensaver --now # cover the screen now, exit after you unlock
71
- npx github:realRoc/dsh-screensaver # stay in the background, press ⌃⌥⌘L to start
72
- npx github:realRoc/dsh-screensaver --now subspace # with a theme (when it is installed or in DSH_SCREENSAVER_THEMES)
65
+ npx dsh-screensaver --now # cover the screen now, exit after you unlock
66
+ npx dsh-screensaver # stay in the background, press ⌃⌥⌘L to start
67
+ npx dsh-screensaver --now subspace # with a theme
68
+ npx dsh-screensaver setup # settings: lid-closed awake (and its one-time authorization), theme, idle start
73
69
  ```
74
70
 
75
71
  Requirements: macOS 12 or later, Node.js 22 or later. Touch-to-unlock needs a Mac with Touch ID (or a Magic Keyboard with
@@ -103,18 +99,31 @@ Add an entry to your profile's `~/.dsh/profiles/<profile>/cordis.patch.yml` (it
103
99
  config:
104
100
  theme: subspace # default theme id
105
101
  idleMinutes: 10 # start after 10 idle minutes; 0 = never (default)
106
- lidAwake: true # also keep the Mac awake with the lid closed while the screen saver is up
102
+ lidAwake: true # keep the Mac awake with the lid closed while the screen saver is up (default; false turns it off)
107
103
  shortcut: Control+Alt+Command+L # Electron accelerator; '' disables the shortcut
108
104
  ```
109
105
 
110
- Standalone, pass the same fields as JSON: `DSH_SCREENSAVER_CONFIG='{"theme":"subspace"}' npx github:realRoc/dsh-screensaver`.
106
+ Standalone, the same fields live in `~/.dsh/plugins-data/dsh-screensaver/config.json`:
107
+
108
+ | Command | What it does |
109
+ | --- | --- |
110
+ | `dsh-screensaver setup` | Walk through lid-closed awake (authorizes it on the spot), the theme and idle start |
111
+ | `dsh-screensaver config` | Show the settings and the file they are saved in |
112
+ | `dsh-screensaver config <key> <value>` | Change one, e.g. `config lidAwake off`, `config idleMinutes 10` |
113
+ | `dsh-screensaver config unset <key>` | Back to the default |
114
+ | `dsh-screensaver lid [status\|authorize\|revoke]` | Lid-closed awake authorization, same as `/screensaver lid` |
115
+ | `dsh-screensaver themes` | List installed themes |
116
+
117
+ `DSH_SCREENSAVER_CONFIG='{"theme":"subspace"}'` overrides the file for one run. A `--now` handed to a screen saver that is
118
+ already running (for example the one inside dsh) brings its `lidAwake` along for that start when it sets one (in the file or the variable); otherwise the running one
119
+ uses its own config.
111
120
 
112
121
  ## Themes
113
122
 
114
- | Theme | id | Install | Shows agent sessions |
123
+ | Theme | id | Ships with | Shows agent sessions |
115
124
  | --- | --- | --- | --- |
116
125
  | Clock | `basic` | built in | No |
117
- | Subspace Jump | `subspace` | `github:realRoc/dsh-screensaver#path:/themes/subspace` | Yes |
126
+ | Subspace Jump | `subspace` | built in | Yes |
118
127
 
119
128
  More themes are coming. Themes are visual works licensed CC BY-NC-SA 4.0 (no commercial use). A theme is a folder with an `index.html` (runs in a sandboxed iframe, draws only) and a
120
129
  `saver.json`. Put your own in `~/.dsh/plugins-data/dsh-screensaver/themes/<id>/`, or publish it as an npm package with
@@ -139,9 +148,10 @@ sessions. They are trademarks of their owners and are used only to identify thos
139
148
  - A small always-on-top window covers each display; the primary one runs in kiosk mode (hides the Dock and menu bar,
140
149
  blocks ⌘Tab and Force Quit).
141
150
  - `desk-unlock`, a Swift helper (`native/unlock/main.swift`), embeds the system Touch ID view (`LAAuthenticationView`) in
142
- an invisible window above the screen saver, so touching the sensor unlocks with no dialog. It also reads battery and
151
+ an invisible window above the screen saver, so touching the sensor unlocks with no dialog. With the lid closed the
152
+ built-in sensor is off, so it waits for the lid to open (`AppleClamshellState`) and listens again right away. It also reads battery and
143
153
  Wi-Fi for the status bar (IOKit, CoreWLAN; no location permission, the network name is not read).
144
- - While up: `powerSaveBlocker('prevent-display-sleep')`. With `lidAwake`: `pmset -a disablesleep 1`, restored when the
154
+ - While up: `powerSaveBlocker('prevent-display-sleep')`. With `lidAwake` (default) and the authorization: `pmset -a disablesleep 1`, restored when the
145
155
  screen saver closes, when the process dies (a detached watchdog), at the next start if it was left on, and when the
146
156
  battery drops to 20%.
147
157
 
@@ -151,7 +161,9 @@ sessions. They are trademarks of their owners and are used only to identify thos
151
161
  Yes. Terminal agents are not affected at all, the Mac does not idle-sleep, and the display does not turn off.
152
162
 
153
163
  **Does it work when I close the MacBook lid?**
154
- Only with lid-closed awake: run `/screensaver lid authorize` once, then set `lidAwake: true` or use `/screensaver lid on`.
164
+ Yes, after you allow it once: `/screensaver lid authorize` in dsh, or `dsh-screensaver lid authorize` (or `setup`)
165
+ standalone. `lidAwake` is on by default, so from then on every screen saver keeps the Mac awake with the lid closed;
166
+ set `lidAwake: false` to stop that.
155
167
  Keep the Mac plugged in; it turns itself off at 20% battery.
156
168
 
157
169
  **Is it a replacement for the macOS lock screen?**
@@ -159,7 +171,7 @@ No. It is a cover for when you step away at home or in the office and want your
159
171
  security use ⌃⌘Q.
160
172
 
161
173
  **Do I need DeepSeek Harness?**
162
- No. `npx github:realRoc/dsh-screensaver` runs it standalone. dsh adds the `/screensaver` command, the agent tool and
174
+ No. `npx dsh-screensaver` runs it standalone. dsh adds the `/screensaver` command, the agent tool and
163
175
  config.
164
176
 
165
177
  **Does it work on Windows or Linux?**
@@ -180,6 +192,15 @@ npm run build:themes # rebuild themes/subspace/index.html after editin
180
192
  DSH_SCREENSAVER_DEBUG=1 npm run now # log page console messages
181
193
  ```
182
194
 
195
+ ### Release
196
+
197
+ Pushing a `v*` tag runs [`.github/workflows/publish.yml`](.github/workflows/publish.yml), which tests and publishes
198
+ `dsh-screensaver` (themes included) to npm through Trusted Publishing (no token). A version already on npm is skipped.
199
+
200
+ 1. Bump `version` in `package.json`. Rebuild `themes/subspace/index.html` first if the theme source changed.
201
+ 2. Commit and push to `main`.
202
+ 3. Tag and push: `git tag vX.Y.Z && git push origin vX.Y.Z`. The tag must match the root `package.json` version.
203
+
183
204
  ## License
184
205
 
185
206
  Code is MIT ([LICENSE](LICENSE)). All visual assets, meaning every theme under `themes/` and the screenshots under
package/README.zh-CN.md CHANGED
@@ -25,7 +25,7 @@ dsh-screensaver 就是为这种时候做的:样子跟 Mac 锁屏一样,回
25
25
  | computer use 类 agent、靠浏览器扩展驱动的 agent | 会停([openai/codex#58545](https://github.com/openai/codex/issues/58545)、[openai/codex#43869](https://github.com/openai/codex/issues/43869)) | 未测试 | 照常 | 照常 | **浏览器扩展类照常运行**;需要点击屏幕的操作会被挡住 |
26
26
  | 被盖住的浏览器窗口不降频 | 会降频,系统认为窗口不可见 | 未测试 | — | — | **不降频**:屏保保留了一点点透明度,系统仍认为窗口可见 |
27
27
  | 不熄屏、不进入空闲睡眠 | 不管:锁屏后很快熄屏,之后睡不睡取决于其他程序([anthropics/claude-code#81832](https://github.com/anthropics/claude-code/issues/81832)) | 不管 | 不管 | 管 | **屏保期间一直管** |
28
- | 合盖不睡 | 不行 | 不行 | 不行 | 不行(防睡眠断言管不了合盖) | **可选**(`pmset disablesleep`,授权一次,退出后自动恢复) |
28
+ | 合盖不睡 | 不行 | 不行 | 不行 | 不行(防睡眠断言管不了合盖) | **默认开**,授权一次就生效(`pmset disablesleep`,退出后自动恢复) |
29
29
  | 解锁 | Touch ID 或密码 | 按任意键(可能要输密码) | — | — | **直接摸 Touch ID**,或按键、点击后用 Touch ID / 登录密码 |
30
30
  | 能看到 agent 在做什么 | 不能 | 不能 | 不能 | 不能 | **能**(支持会话的主题会显示名称、当前步骤和状态) |
31
31
 
@@ -39,30 +39,26 @@ dsh-screensaver 就是为这种时候做的:样子跟 Mac 锁屏一样,回
39
39
  在 dsh 里使用:
40
40
 
41
41
  ```bash
42
- dsh plugin --profile web add github:realRoc/dsh-screensaver
42
+ dsh plugin --profile web add dsh-screensaver
43
43
  ```
44
44
 
45
45
  DeepSeek Harness 桌面版把 `web` 换成 `desktop`。装好后重启 dsh。第一次启动会下载 Electron 运行时(约 100 MB,只下载一次);
46
46
  如果装了 Xcode 命令行工具,还会在本机编译 Touch ID 小程序。
47
47
 
48
- 主题单独安装,需要哪个装哪个。只用内置的「时钟」就不用装下面这个:
49
-
50
- ```bash
51
- dsh plugin --profile web add "github:realRoc/dsh-screensaver#path:/themes/subspace"
52
- ```
48
+ 「时钟」和「亚空间跃迁」两个主题都随包自带,不用另装。
53
49
 
54
- 电脑上没装 git,或者想装固定的发布版本,可以直接装 GitHub Release 里打好的包:
50
+ 想用 GitHub 上还没发布的最新代码,而不是 npm 上的发布版:
55
51
 
56
52
  ```bash
57
- dsh plugin --profile web add https://github.com/realRoc/dsh-screensaver/releases/latest/download/dsh-screensaver.tgz
58
- dsh plugin --profile web add https://github.com/realRoc/dsh-screensaver/releases/latest/download/dsh-screensaver-theme-subspace.tgz
53
+ dsh plugin --profile web add github:realRoc/dsh-screensaver
59
54
  ```
60
55
 
61
56
  不装 dsh 也能用:
62
57
 
63
58
  ```bash
64
- npx github:realRoc/dsh-screensaver --now # 立即开启,解锁后退出
65
- npx github:realRoc/dsh-screensaver # 在后台待命,按 ⌃⌥⌘L 开启
59
+ npx dsh-screensaver --now # 立即开启,解锁后退出
60
+ npx dsh-screensaver # 在后台待命,按 ⌃⌥⌘L 开启
61
+ npx dsh-screensaver setup # 改配置:合盖不睡(顺手授权)、主题、空闲自动开启
66
62
  ```
67
63
 
68
64
  系统要求:macOS 12 及以上,Node.js 22 及以上。想「摸一下就解锁」,需要带 Touch ID 的 Mac(或带 Touch ID 的妙控键盘),
@@ -93,18 +89,30 @@ npx github:realRoc/dsh-screensaver # 在后台待命,按 ⌃
93
89
  config:
94
90
  theme: subspace # 默认主题
95
91
  idleMinutes: 10 # 空闲 10 分钟自动开启;0 表示不自动开启(默认)
96
- lidAwake: true # 开启屏保时顺便打开合盖不睡
92
+ lidAwake: true # 开启屏保时顺便打开合盖不睡(默认开,写 false 关掉)
97
93
  shortcut: Control+Alt+Command+L # Electron 快捷键写法;填 '' 不注册快捷键
98
94
  ```
99
95
 
100
- 单独运行时,用环境变量传同样的 JSON:`DSH_SCREENSAVER_CONFIG='{"theme":"subspace"}' npx github:realRoc/dsh-screensaver`。
96
+ 单独运行时,同样几项存在 `~/.dsh/plugins-data/dsh-screensaver/config.json`:
97
+
98
+ | 命令 | 作用 |
99
+ | --- | --- |
100
+ | `dsh-screensaver setup` | 一问一答:合盖不睡(当场授权)、主题、空闲自动开启 |
101
+ | `dsh-screensaver config` | 查看配置和配置文件位置 |
102
+ | `dsh-screensaver config <项> <值>` | 改一项,例如 `config lidAwake off`、`config idleMinutes 10` |
103
+ | `dsh-screensaver config unset <项>` | 改回默认 |
104
+ | `dsh-screensaver lid [status\|authorize\|revoke]` | 合盖不睡授权,同 `/screensaver lid` |
105
+ | `dsh-screensaver themes` | 查看已安装的主题 |
106
+
107
+ `DSH_SCREENSAVER_CONFIG='{"theme":"subspace"}'` 只对这一次生效,盖过配置文件。`--now` 交给已经在跑的屏保(比如 dsh 里那个)时,
108
+ 如果这次写了 `lidAwake`(配置文件或环境变量里),会一起带过去;没写就按那个屏保自己的配置。
101
109
 
102
110
  ## 主题
103
111
 
104
- | 主题 | id | 安装方式 | 显示 agent 会话 |
112
+ | 主题 | id | 来源 | 显示 agent 会话 |
105
113
  | --- | --- | --- | --- |
106
114
  | 时钟 | `basic` | 内置 | 否 |
107
- | 亚空间跃迁 | `subspace` | `github:realRoc/dsh-screensaver#path:/themes/subspace` | 是 |
115
+ | 亚空间跃迁 | `subspace` | 内置 | 是 |
108
116
 
109
117
  更多主题陆续推出。每个主题就是一个文件夹:`index.html` 负责绘制(运行在沙盒 iframe 里),`saver.json` 写名称等信息。
110
118
  自己做的主题放进 `~/.dsh/plugins-data/dsh-screensaver/themes/<id>/` 就能用,也可以发布成 npm 包,在 `package.json` 里写上
@@ -128,14 +136,15 @@ npx github:realRoc/dsh-screensaver # 在后台待命,按 ⌃
128
136
  不会。终端里的 agent 完全不受影响,电脑不会空闲睡眠,屏幕也不会熄灭。
129
137
 
130
138
  **合上 MacBook 盖子还能继续跑吗?**
131
- 可以,但要先开启合盖不睡:执行一次 `/screensaver lid authorize`,再设置 `lidAwake: true` 或执行 `/screensaver lid on`。
139
+ 可以,授权一次就行:dsh 里执行 `/screensaver lid authorize`,单独运行时执行 `dsh-screensaver lid authorize`(或 `setup`)。
140
+ `lidAwake` 默认开,之后每次开屏保都会合盖不睡;不想要就设 `lidAwake: false`。
132
141
  建议插着电源;用电池且电量降到 20% 时会自动恢复睡眠。
133
142
 
134
143
  **能代替 macOS 锁屏吗?**
135
144
  不能。它适合在家或办公室临时走开、又想让 agent 继续工作的场景。需要真正的安全保护时,请用 ⌃⌘Q。
136
145
 
137
146
  **一定要装 DeepSeek Harness 吗?**
138
- 不用。`npx github:realRoc/dsh-screensaver` 可以单独运行。装在 dsh 里会多出 `/screensaver` 命令、agent 可调用的工具和配置项。
147
+ 不用。`npx dsh-screensaver` 可以单独运行。装在 dsh 里会多出 `/screensaver` 命令、agent 可调用的工具和配置项。
139
148
 
140
149
  **支持 Windows 或 Linux 吗?**
141
150
  暂时只支持 macOS。
@@ -154,6 +163,15 @@ npm run build:themes # 修改 themes/subspace/src 后重新打包 inde
154
163
  DSH_SCREENSAVER_DEBUG=1 npm run now # 打印页面里的 console 输出
155
164
  ```
156
165
 
166
+ ### 发版
167
+
168
+ 推送 `v*` 标签会触发 [`.github/workflows/publish.yml`](.github/workflows/publish.yml):跑测试,再通过 Trusted Publishing(不用令牌)
169
+ 把 `dsh-screensaver`(含主题)发到 npm。这个版本 npm 上已有就跳过。
170
+
171
+ 1. 改 `package.json` 的 `version`。主题源码改过的话先重新打包 `themes/subspace/index.html`。
172
+ 2. 提交并推送到 `main`。
173
+ 3. 打标签并推送:`git tag vX.Y.Z && git push origin vX.Y.Z`。标签必须和根目录 `package.json` 的版本一致。
174
+
157
175
  ## 授权
158
176
 
159
177
  代码采用 MIT;所有主题(`themes/`)和截图(`docs/images/`)等视觉素材采用 **CC BY-NC-SA 4.0,禁止商用**。
package/app/main.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // → { "$": "lid", "action": "status|authorize|revoke|on|off", "id": 2 }
9
9
  // ← { "$": "state", "active": true } 屏保开了 / 关了
10
10
  // 2. 单独跑(bin/dsh-screensaver.js):`--now [主题]` 马上开,解开后退出;不带就常驻,等快捷键 / 空闲自动开。
11
- // 配置从 DSH_SCREENSAVER_CONFIG(JSON)读。
11
+ // 配置从 DSH_SCREENSAVER_CONFIG(JSON)读(bin/ 把数据目录的 config.json 和调用方带的合好了放进来)。
12
12
  import { app, dialog } from 'electron'
13
13
  import { registerScheme, serveScheme } from './paths.js'
14
14
  import { saverLang, Screensaver } from './saver.js'
@@ -19,11 +19,6 @@ const now = nowAt >= 0
19
19
  const nowTheme = now && argv[nowAt + 1] && !argv[nowAt + 1].startsWith('-') ? argv[nowAt + 1] : undefined
20
20
  const controlled = process.env.DSH_SCREENSAVER_CONTROL === 'stdin'
21
21
 
22
- // 同一时间只开一个:第二次 `dsh-screensaver --now` 交给已经在跑的那个去开
23
- if (!app.requestSingleInstanceLock({ now, theme: nowTheme })) app.exit(0)
24
- registerScheme()
25
- app.dock?.hide() // 不进程序坞,不抢 Cmd+Tab
26
-
27
22
  function readConfig() {
28
23
  try {
29
24
  return JSON.parse(process.env.DSH_SCREENSAVER_CONFIG || '{}')
@@ -32,6 +27,12 @@ function readConfig() {
32
27
  }
33
28
  }
34
29
 
30
+ // 同一时间只开一个:第二次 `dsh-screensaver --now` 交给已经在跑的那个去开,
31
+ // 连同这次明说了的合盖不睡设置(比如桌宠开的、dsh 里配的是关,这一次也按桌宠的来);没说就按那个实例自己的配置
32
+ if (!app.requestSingleInstanceLock({ now, theme: nowTheme, lidAwake: readConfig().lidAwake })) app.exit(0)
33
+ registerScheme()
34
+ app.dock?.hide() // 不进程序坞,不抢 Cmd+Tab
35
+
35
36
  const send = (msg) => process.stdout.write(`${JSON.stringify(msg)}\n`)
36
37
  let saver = null
37
38
  let quitting = false
@@ -108,7 +109,7 @@ async function main() {
108
109
  },
109
110
  })
110
111
  app.on('second-instance', (_e, _argv, _cwd, data) => {
111
- if (data?.now) void saver.start(data.theme)
112
+ if (data?.now) void saver.start(data.theme, { lidAwake: data.lidAwake })
112
113
  })
113
114
  app.on('window-all-closed', () => {}) // 屏保关了程序不退:等下一次快捷键 / 指令
114
115
  app.on('before-quit', (e) => {
package/app/saver.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // 先进 simpleFullScreen(老式全屏,不新开桌面空间)再开 kiosk,不然 kiosk 会走原生全屏,把屏保放进单独的空间。
5
5
  // - 窗口不是完全不透明(网页背景留一点点透明):完全挡住的话 Chrome 会把被挡的窗口当成隐藏,定时器和动画降频,
6
6
  // 被挡住的浏览器里的 agent(靠扩展驱动的那种)也跟着降频。
7
- // - 屏保开着时不让系统睡、也不关屏;配置了 lidAwake 再把合盖睡眠关掉(lidawake.js)。
7
+ // - 屏保开着时不让系统睡、也不关屏;合盖睡眠也关掉(lidawake.js,lidAwake 默认开,写 false 才不管;没授权只提示一句)。
8
8
  // - 解锁两条路(都是 native/unlock/ 的 desk-unlock,LocalAuthentication):
9
9
  // 1. 直接摸 Touch ID:屏保一开就起 `desk-unlock --listen`。它在主屏上盖一层看不见的窗口(屏保上一层),
10
10
  // 底部放系统的指纹小图标,并且自己当前台程序(Touch ID 只认前台程序,所以这期间屏保不抢焦点,
@@ -47,6 +47,10 @@ const SAY = {
47
47
  en: "This Mac can't verify your identity, so the screen saver only covers the screen: a click opens it",
48
48
  },
49
49
  lidRecovered: { zh: '上次合盖不睡没关掉,已经恢复睡眠了', en: 'Lid-closed sleep was left disabled last time; restored it' },
50
+ lidUnauthorized: {
51
+ zh: '合盖不睡还没授权,合上盖子电脑照样睡:dsh 里输 /screensaver lid authorize,或终端跑 dsh-screensaver lid authorize(输一次管理员密码)',
52
+ 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)',
53
+ },
50
54
  }
51
55
 
52
56
  export class Screensaver {
@@ -161,18 +165,24 @@ export class Screensaver {
161
165
  for (const w of win ? [win] : this.wins.values()) if (!w.isDestroyed()) w.webContents.send('saver:sessions', payload)
162
166
  }
163
167
 
164
- async start(themeId) {
168
+ /**
169
+ * 开屏保。opts.lidAwake:这一次要不要合盖不睡(`--now` 交给已经在跑的这个时带过来的),不给就看配置,配置没写算开
170
+ */
171
+ async start(themeId, opts = {}) {
165
172
  if (this.active) return
166
173
  const theme = this.theme(themeId)
167
174
  if (!theme) return this.say('[dsh-screensaver] no theme found')
168
175
  mountTheme(theme.id, theme.dir)
169
176
  this.current = theme
170
177
  if (!this.canAuthenticate()) this.say(SAY.noAuth[saverLang()])
171
- if (this.config.lidAwake && !this.lid.active) {
178
+ if ((opts.lidAwake ?? this.config.lidAwake) !== false && !this.lid.active && this.lid.supported) {
172
179
  try {
173
180
  if (await this.lid.authorized()) {
174
181
  await this.lid.on()
175
182
  this.lidBySaver = this.lid.active
183
+ } else if (!this.lidHinted) {
184
+ this.lidHinted = true
185
+ this.say(SAY.lidUnauthorized[saverLang()])
176
186
  }
177
187
  } catch (e) {
178
188
  this.say(`[dsh-screensaver] lid-awake failed: ${e?.message ?? e}`)
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
- // 比如 themes/subspace 单独装的 dsh-screensaver-theme-subspace。dsh 的 profile 是 hoisted 布局,
4
+ // 1. 这个包自带的 themes/(「时钟」basic 和「亚空间跃迁」subspace,都随包发布);
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>/,自己做着玩的主题放这里就行。
@@ -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
- // 配置用环境变量 DSH_SCREENSAVER_CONFIG(JSON,字段同 dsh 插件配置)。
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
- Config: DSH_SCREENSAVER_CONFIG='{"theme":"subspace","idleMinutes":10,"lidAwake":true}'`)
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
- let config = {}
23
- try {
24
- config = JSON.parse(process.env.DSH_SCREENSAVER_CONFIG || '{}')
25
- } catch {}
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
@@ -9,14 +9,14 @@
9
9
  # config:
10
10
  # theme: subspace
11
11
  # idleMinutes: 10
12
- # lidAwake: true
12
+ # lidAwake: false # 合盖不睡默认开(授权过才生效),不要就写 false
13
13
  - insert:
14
14
  - id: dsh-screensaver
15
15
  name: dsh-screensaver
16
16
  config:
17
17
  theme: basic
18
18
  idleMinutes: 0
19
- lidAwake: false
19
+ lidAwake: true
20
20
  - id: dsh-screensaver-command
21
21
  name: dsh-screensaver/command
22
22
  - id: dsh-screensaver-tool
package/lib/cli.js ADDED
@@ -0,0 +1,167 @@
1
+ // 不装 dsh 时的配置入口(bin/dsh-screensaver.js 的子命令):
2
+ // dsh-screensaver setup 一问一答:合盖不睡(顺手授权)、默认主题、空闲几分钟自动开
3
+ // dsh-screensaver config 看现在的配置和文件在哪
4
+ // dsh-screensaver config <项> <值> 改一项,比如 config lidAwake off、config idleMinutes 10
5
+ // dsh-screensaver config unset <项> 改回默认
6
+ // dsh-screensaver lid [status|authorize|revoke] 合盖不睡的授权(弹一次管理员密码框)
7
+ // dsh-screensaver themes 装了哪些主题
8
+ // 在 dsh 里同样的事用 /screensaver 命令和 cordis.patch.yml。
9
+ //
10
+ // 不碰 Electron;依赖都能注入,好测。
11
+ import { createInterface } from 'node:readline/promises'
12
+ import { LidAwake } from '../app/lidawake.js'
13
+ import { dataDir } from '../app/dirs.js'
14
+ import { listThemes } from '../app/themes.js'
15
+ import { DEFAULTS, KEYS, configPath, parseValue, readSettings, writeSettings } from './settings.js'
16
+
17
+ export const SUBCOMMANDS = ['setup', 'config', 'lid', 'themes']
18
+
19
+ export const CLI_USAGE = `Settings (used when running without dsh):
20
+ dsh-screensaver setup walk through the settings (lid-closed awake, theme, idle start)
21
+ dsh-screensaver config show the settings and where they are saved
22
+ dsh-screensaver config <key> <value> change one: lidAwake on|off, theme <id>, idleMinutes <n>, shortcut <accelerator>
23
+ dsh-screensaver config unset <key> back to the default
24
+ dsh-screensaver lid [status|authorize|revoke]
25
+ allow lid-closed awake (asks for an admin password once)
26
+ dsh-screensaver themes list installed themes
27
+ A screen saver already running in the background picks up changes after a restart.`
28
+
29
+ function show(v) {
30
+ if (typeof v === 'boolean') return v ? 'on' : 'off'
31
+ if (v === '') return "'' (none)"
32
+ return String(v)
33
+ }
34
+
35
+ function lidLine(st) {
36
+ if (!st.supported) return 'Lid-closed awake: macOS only'
37
+ if (!st.authorized) return 'Lid-closed awake: not authorized yet. Run `dsh-screensaver lid authorize` (asks for an admin password once).'
38
+ return `Lid-closed awake: authorized; sleep is ${st.sleepDisabled ? 'disabled right now' : 'normal right now'}`
39
+ }
40
+
41
+ /** 默认的依赖:真的配置文件、真的 LidAwake、终端问答 */
42
+ function defaults(env) {
43
+ return {
44
+ path: configPath(env),
45
+ lid: new LidAwake(dataDir(env)),
46
+ themes: () => listThemes({ env }),
47
+ out: (line) => console.log(line),
48
+ err: (line) => console.error(line),
49
+ ask: async (q) => {
50
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
51
+ try {
52
+ return await rl.question(q)
53
+ } finally {
54
+ rl.close()
55
+ }
56
+ },
57
+ }
58
+ }
59
+
60
+ const yes = (answer, dflt) => {
61
+ const a = String(answer ?? '').trim().toLowerCase()
62
+ return a ? ['y', 'yes', '是', '好'].includes(a) : dflt
63
+ }
64
+
65
+ /**
66
+ * 跑一个子命令;不是子命令返回 null(交给屏保本体),否则返回退出码。
67
+ * @param {string[]} args
68
+ */
69
+ export async function runCli(args, deps = {}) {
70
+ const [cmd, ...rest] = args
71
+ if (!SUBCOMMANDS.includes(cmd)) return null
72
+ const d = { ...defaults(deps.env ?? process.env), ...deps }
73
+ const { out } = d
74
+ try {
75
+ if (cmd === 'themes') {
76
+ const list = d.themes()
77
+ out(list.map((t) => `${t.id} ${t.name}${t.sessions ? ' (shows live agent sessions)' : ''}`).join('\n') || 'No themes installed')
78
+ return 0
79
+ }
80
+
81
+ if (cmd === 'lid') {
82
+ const action = rest[0] ?? 'status'
83
+ if (action === 'authorize') {
84
+ if (!(await d.lid.authorized())) await d.lid.authorize()
85
+ out('Lid-closed awake is authorized. The screen saver turns it on while it is up (lidAwake is on by default).')
86
+ } else if (action === 'revoke') {
87
+ await d.lid.revoke()
88
+ out('Authorization removed. The Mac sleeps with the lid closed again.')
89
+ } else if (action === 'status') {
90
+ out(lidLine(await d.lid.state()))
91
+ } else {
92
+ throw new Error(CLI_USAGE)
93
+ }
94
+ return 0
95
+ }
96
+
97
+ if (cmd === 'config') {
98
+ const saved = readSettings(d.path)
99
+ if (rest.length === 0) {
100
+ for (const k of KEYS) {
101
+ const from = k in saved ? '' : ' (default)'
102
+ const v = k in saved ? saved[k] : DEFAULTS[k]
103
+ out(`${k.padEnd(12)}${v === undefined ? '(default)' : `${show(v)}${from}`}`)
104
+ }
105
+ out(`Saved in ${d.path}`)
106
+ return 0
107
+ }
108
+ if (rest[0] === 'unset' && rest.length === 2) {
109
+ if (!KEYS.includes(rest[1])) throw new Error(`unknown setting "${rest[1]}"; known: ${KEYS.join(', ')}`)
110
+ delete saved[rest[1]]
111
+ writeSettings(saved, d.path)
112
+ out(`${rest[1]} is back to the default`)
113
+ return 0
114
+ }
115
+ if (rest.length !== 2) throw new Error(CLI_USAGE)
116
+ const [key, raw] = rest
117
+ const value = parseValue(key, raw)
118
+ if (key === 'theme' && !d.themes().some((t) => t.id === value)) {
119
+ throw new Error(`No theme "${value}". Installed: ${d.themes().map((t) => t.id).join(', ') || 'none'}`)
120
+ }
121
+ writeSettings({ ...saved, [key]: value }, d.path)
122
+ out(`${key} = ${show(value)}`)
123
+ if (key === 'lidAwake' && value && !(await d.lid.authorized())) out(lidLine({ supported: d.lid.supported, authorized: false }))
124
+ return 0
125
+ }
126
+
127
+ // setup:一问一答,回车用方括号里的
128
+ const saved = readSettings(d.path)
129
+ const cur = { ...DEFAULTS, ...saved }
130
+ const next = { ...saved }
131
+
132
+ next.lidAwake = yes(await d.ask(`Keep the Mac awake with the lid closed while the screen saver is up? [${cur.lidAwake ? 'Y/n' : 'y/N'}] `), cur.lidAwake)
133
+ if (next.lidAwake && d.lid.supported && !(await d.lid.authorized())) {
134
+ if (yes(await d.ask('That needs a one-time admin password (a sudoers rule that only allows pmset disablesleep). Authorize now? [Y/n] '), true)) {
135
+ await d.lid.authorize()
136
+ out('Authorized.')
137
+ } else {
138
+ out('Skipped. Run `dsh-screensaver lid authorize` later; until then the lid still puts the Mac to sleep.')
139
+ }
140
+ }
141
+
142
+ const themes = d.themes()
143
+ if (themes.length > 1) {
144
+ out(themes.map((t, i) => ` ${i + 1}. ${t.name} (${t.id})`).join('\n'))
145
+ const a = String(await d.ask(`Theme? [${cur.theme}] `)).trim()
146
+ const t = themes[Number(a) - 1] ?? themes.find((x) => x.id === a)
147
+ if (a && !t) out(`No theme "${a}", keeping ${cur.theme}`)
148
+ if (t) next.theme = t.id
149
+ }
150
+
151
+ const idle = String(await d.ask(`Start by itself after how many idle minutes? 0 = never [${cur.idleMinutes}] `)).trim()
152
+ if (idle) {
153
+ try {
154
+ next.idleMinutes = parseValue('idleMinutes', idle)
155
+ } catch (e) {
156
+ out(`${e.message}; keeping ${cur.idleMinutes}`)
157
+ }
158
+ }
159
+
160
+ writeSettings(next, d.path)
161
+ out(`Saved in ${d.path}. Start with \`dsh-screensaver --now\`, or run \`dsh-screensaver\` to wait for ⌃⌥⌘L.`)
162
+ return 0
163
+ } catch (e) {
164
+ d.err(e?.message ?? String(e))
165
+ return 1
166
+ }
167
+ }
package/lib/index.js CHANGED
@@ -2,19 +2,19 @@
2
2
  // 平时什么都不显示;按 ⌃⌥⌘L、在 dsh 里输 /screensaver、让 agent 调 screensaver 工具、或者空闲够久才盖住屏幕。
3
3
  //
4
4
  // 配置(cordis.patch.yml 里 dsh-screensaver 的 config,或者 profile 自己覆盖):
5
- // theme 默认主题 id:basic(时钟)、subspace(亚空间跃迁,要另装主题包)……
5
+ // theme 默认主题 id:basic(时钟)、subspace(亚空间跃迁,随包自带)……
6
6
  // idleMinutes 键鼠空闲多少分钟自动开,0 不自动开(默认 0)
7
- // lidAwake 开屏保时顺便打开「合盖不睡」(要先 /screensaver lid authorize 授权一次;默认 false)
7
+ // lidAwake 开屏保时顺便打开「合盖不睡」(要先 /screensaver lid authorize 授权一次;默认 true,false 关掉)
8
8
  // shortcut 全局快捷键,Electron accelerator 写法;空字符串不注册(默认 Control+Alt+Command+L)
9
9
  // desktop false 就不起屏保进程(比如没图形界面的机器)
10
10
  //
11
11
  // 不 import dsh 的包:从 GitHub 装的插件在 profile 的 node_modules 里,解析不到全局装的 @deepseek-ai/*。
12
12
  import { launch } from './launcher.js'
13
13
  import { saver } from './bridge.js'
14
+ import { KEYS } from './settings.js'
14
15
 
15
16
  export const name = 'dsh-screensaver'
16
17
 
17
- const KEYS = ['theme', 'idleMinutes', 'lidAwake', 'shortcut']
18
18
 
19
19
  /** 插件配置里屏保进程认的那几项 */
20
20
  export function saverConfig(config) {