dsh-power-menu-mac 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/CHANGELOG.md +11 -0
- package/docs/screenshot.png +0 -0
- package/lib/client.js +16 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
本项目遵循 [Semantic Versioning](https://semver.org/spec/v2.0.0.html),格式参考 [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)。
|
|
4
4
|
|
|
5
|
+
## [0.1.1] - 2026-10-29
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- 打开菜单不再把焦点放进第一项。第一项是「关闭DSH」,焦点落上去之后误按一个回车/空格就会把应用关掉。焦点现在留在触发按钮上;ArrowDown / ArrowUp / Home / End 仍然能进菜单(由触发按钮转发给菜单的键盘处理),Esc 照旧关闭。
|
|
10
|
+
- 打开菜单时显式把焦点收回触发按钮。有些 WebKit 表面里点按钮不会自动聚焦,否则会出现「菜单开了但方向键没反应」。
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- 菜单按钮上的契约属性:`data-dsh-power-action="shutdown"` / `data-dsh-power-action="restart"`。`MenuItem` 现在把多余 props 透传给底层 `button`,选择器和自动化检查可以直接按动作定位,不用匹配标签文字。
|
|
15
|
+
|
|
5
16
|
## [0.1.0] - 2026-10-26
|
|
6
17
|
|
|
7
18
|
首个 macOS 版本。基于 [xichen-62/dsh-power-menu](https://github.com/xichen-62/dsh-power-menu) 0.1.18(MIT)移植。
|
package/docs/screenshot.png
CHANGED
|
Binary file
|
package/lib/client.js
CHANGED
|
@@ -98,8 +98,11 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
h('path', { d: 'M3 3v5h5' }))
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
// 多余的 props 原样透传给 button:契约属性(如 data-dsh-power-action)挂在真正的
|
|
102
|
+
// 那个按钮上,选择器才抓得到。
|
|
103
|
+
function MenuItem({ icon, label, onSelect, itemRef, ...rest }) {
|
|
102
104
|
return h('button', {
|
|
105
|
+
...rest,
|
|
103
106
|
type: 'button',
|
|
104
107
|
role: 'menuitem',
|
|
105
108
|
tabIndex: -1,
|
|
@@ -175,11 +178,8 @@ window.__ModuleLoader__.load({
|
|
|
175
178
|
}
|
|
176
179
|
}, [open])
|
|
177
180
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const first = itemRefs.current[0]
|
|
181
|
-
if (first !== null && first !== undefined) first.focus()
|
|
182
|
-
}, [open])
|
|
181
|
+
// 打开时不把焦点丢进菜单:第一项是「关闭DSH」,焦点落上去之后一个回车就把
|
|
182
|
+
// 应用关了。焦点留在触发按钮上,方向键进菜单(见触发按钮的 onKeyDown)。
|
|
183
183
|
|
|
184
184
|
const onMenuKeyDown = (event) => {
|
|
185
185
|
const items = itemRefs.current.filter(Boolean)
|
|
@@ -245,12 +245,14 @@ window.__ModuleLoader__.load({
|
|
|
245
245
|
h(MenuItem, {
|
|
246
246
|
icon: h(PowerIcon, { size: 21 }),
|
|
247
247
|
label: '关闭DSH',
|
|
248
|
+
'data-dsh-power-action': 'shutdown',
|
|
248
249
|
itemRef: (el) => { itemRefs.current[0] = el },
|
|
249
250
|
onSelect: () => run('shutdown'),
|
|
250
251
|
}),
|
|
251
252
|
h(MenuItem, {
|
|
252
253
|
icon: h(RestartIcon, { size: 21 }),
|
|
253
254
|
label: '重启DSH',
|
|
255
|
+
'data-dsh-power-action': 'restart',
|
|
254
256
|
itemRef: (el) => { itemRefs.current[1] = el },
|
|
255
257
|
onSelect: () => run('restart'),
|
|
256
258
|
}))
|
|
@@ -274,9 +276,16 @@ window.__ModuleLoader__.load({
|
|
|
274
276
|
'aria-haspopup': 'menu',
|
|
275
277
|
'aria-expanded': open ? 'true' : 'false',
|
|
276
278
|
'data-dshpm-slot': placement,
|
|
279
|
+
// 焦点留在按钮上,所以方向键要在这里接住:ArrowDown 进第一项、ArrowUp 进
|
|
280
|
+
// 最后一项(`onMenuKeyDown` 用 activeElement 定位,按钮不在菜单里时下标是 -1)。
|
|
281
|
+
onKeyDown: open ? onMenuKeyDown : undefined,
|
|
277
282
|
onClick: () => {
|
|
278
283
|
setError(null)
|
|
279
|
-
|
|
284
|
+
const next = !open
|
|
285
|
+
setOpen(next)
|
|
286
|
+
// 明确把焦点留在按钮上:有的 WebKit 里点按钮不会自动聚焦,靠默认行为
|
|
287
|
+
// 会出现"打开了菜单但方向键没反应"。
|
|
288
|
+
if (next) triggerRef.current?.focus()
|
|
280
289
|
},
|
|
281
290
|
}, h(PowerIcon, { size: 16 })))
|
|
282
291
|
|
package/package.json
CHANGED