adapt windows

This commit is contained in:
2026-08-08 23:41:19 +08:00
parent 1fa69aa055
commit 9455c1d57e
20 changed files with 433 additions and 80 deletions

View File

@@ -1,16 +1,13 @@
import { globalShortcut, type BrowserWindow } from 'electron'
import { globalShortcut } from 'electron'
import { sendPlayerControl } from './playerControl'
/**
* 媒体快捷键:
* - 播放/暂停:全局 Super+PmacOS ⌘P / Windows Win+P托盘后台也可用
* - 快退/快进:仅窗口聚焦时 Super+← / Super+→,避免全局抢占方向键
*
* Electron 的 Super = Windows 徽标键 / macOS Command。
* 注意Windows 系统常占用 Win+P投影注册失败时会打日志。
* - 播放/暂停:全局 CommandOrControl+PmacOS ⌘P / Windows Ctrl+P与原项目一致
* - 快退/快进:由渲染进程监听 ← / →(与原项目一致,见 playerStore
*/
const GLOBAL_PLAY_PAUSE = 'Super+P'
const GLOBAL_PLAY_PAUSE = 'CommandOrControl+P'
export function registerMediaShortcuts(): void {
try {
@@ -32,22 +29,3 @@ export function unregisterMediaShortcuts(): void {
/* ignore */
}
}
/** 窗口聚焦时的快退 / 快进(不注册全局,避免影响其它应用) */
export function bindSeekShortcuts(window: BrowserWindow): void {
window.webContents.on('before-input-event', (event, input) => {
if (input.type !== 'keyDown') return
// meta = macOS Command / Windows 徽标键
if (!input.meta || input.control || input.alt) return
if (input.code === 'ArrowLeft') {
event.preventDefault()
sendPlayerControl('seek-backward')
return
}
if (input.code === 'ArrowRight') {
event.preventDefault()
sendPlayerControl('seek-forward')
}
})
}