32 lines
887 B
TypeScript
32 lines
887 B
TypeScript
import { globalShortcut } from 'electron'
|
||
import { sendPlayerControl } from './playerControl'
|
||
|
||
/**
|
||
* 媒体快捷键:
|
||
* - 播放/暂停:全局 CommandOrControl+P(macOS ⌘P / Windows Ctrl+P),与原项目一致
|
||
* - 快退/快进:由渲染进程监听 ← / →(与原项目一致,见 playerStore)
|
||
*/
|
||
|
||
const GLOBAL_PLAY_PAUSE = 'CommandOrControl+P'
|
||
|
||
export function registerMediaShortcuts(): void {
|
||
try {
|
||
const ok = globalShortcut.register(GLOBAL_PLAY_PAUSE, () =>
|
||
sendPlayerControl('playpause')
|
||
)
|
||
if (!ok) {
|
||
console.warn(`[shortcuts] 注册失败(可能被系统占用): ${GLOBAL_PLAY_PAUSE}`)
|
||
}
|
||
} catch (e) {
|
||
console.warn(`[shortcuts] 注册异常: ${GLOBAL_PLAY_PAUSE}`, e)
|
||
}
|
||
}
|
||
|
||
export function unregisterMediaShortcuts(): void {
|
||
try {
|
||
globalShortcut.unregister(GLOBAL_PLAY_PAUSE)
|
||
} catch {
|
||
/* ignore */
|
||
}
|
||
}
|