Files
LoveLiveMusicPlayer-Next/src/main/services/mediaShortcuts.ts
2026-08-08 23:41:19 +08:00

32 lines
887 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { globalShortcut } from 'electron'
import { sendPlayerControl } from './playerControl'
/**
* 媒体快捷键:
* - 播放/暂停:全局 CommandOrControl+PmacOS ⌘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 */
}
}