mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-10 14:22:46 +02:00
fix: strip playback menu accelerators while command palette is open (#2055)
On macOS, menu item accelerators (e.g. Space for Play/Pause) fire even when an input has focus, bypassing the renderer-side useHotkeys guard added in #1925. Typing a space character in the command palette search toggled play/pause instead of inserting a space. Track command palette open state in the main process via IPC. When the palette is open, rebuild the application menu with empty playback accelerators so single-key shortcuts no longer intercept keystrokes intended for the search input. Restore accelerators when the palette closes. Co-authored-by: Jack McCrea <jack@MacBookPro.lan>
This commit is contained in:
+11
-1
@@ -280,6 +280,16 @@ let currentRepeatMode: PlayerRepeat = PlayerRepeat.NONE;
|
||||
let currentSidebarCollapsed = false;
|
||||
let currentShuffleEnabled = false;
|
||||
let playbackMenuAccelerators: MenuPlaybackState['accelerators'] = {};
|
||||
let commandPaletteOpen = false;
|
||||
|
||||
ipcMain.on('command-palette-state', (_event, opened: boolean) => {
|
||||
const next = !!opened;
|
||||
if (commandPaletteOpen === next) return;
|
||||
commandPaletteOpen = next;
|
||||
if (isMacOS()) {
|
||||
rebuildMainMenu();
|
||||
}
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
import('source-map-support').then((sourceMapSupport) => {
|
||||
@@ -340,7 +350,7 @@ const rebuildMainMenu = () => {
|
||||
if (!menuBuilder || !mainWindow) return;
|
||||
|
||||
menuBuilder.buildMenu({
|
||||
accelerators: playbackMenuAccelerators,
|
||||
accelerators: commandPaletteOpen ? {} : playbackMenuAccelerators,
|
||||
playbackStatus: currentPlaybackStatus,
|
||||
privateMode: currentPrivateMode,
|
||||
repeatMode: currentRepeatMode,
|
||||
|
||||
@@ -54,6 +54,10 @@ const forceGarbageCollection = (): boolean => {
|
||||
}
|
||||
};
|
||||
|
||||
const setCommandPaletteOpen = (opened: boolean) => {
|
||||
ipcRenderer.send('command-palette-state', opened);
|
||||
};
|
||||
|
||||
const rendererOpenSettings = (cb: () => void) => {
|
||||
ipcRenderer.on('renderer-open-settings', () => cb());
|
||||
};
|
||||
@@ -101,6 +105,7 @@ export const utils = {
|
||||
rendererTogglePrivateMode,
|
||||
rendererToggleSidebar,
|
||||
rendererUpdateAvailable,
|
||||
setCommandPaletteOpen,
|
||||
startPowerSaveBlocker,
|
||||
stopPowerSaveBlocker,
|
||||
};
|
||||
|
||||
@@ -201,17 +201,22 @@ export const useAppStore = createWithEqualityFn<AppSlice>()(
|
||||
set((state) => {
|
||||
state.commandPalette.opened = false;
|
||||
});
|
||||
window.api?.utils?.setCommandPaletteOpen?.(false);
|
||||
},
|
||||
open: () => {
|
||||
set((state) => {
|
||||
state.commandPalette.opened = true;
|
||||
});
|
||||
window.api?.utils?.setCommandPaletteOpen?.(true);
|
||||
},
|
||||
opened: false,
|
||||
toggle: () => {
|
||||
let nextOpened = false;
|
||||
set((state) => {
|
||||
state.commandPalette.opened = !state.commandPalette.opened;
|
||||
nextOpened = state.commandPalette.opened;
|
||||
});
|
||||
window.api?.utils?.setCommandPaletteOpen?.(nextOpened);
|
||||
},
|
||||
},
|
||||
commandPaletteSearchSectionsExpanded: {},
|
||||
|
||||
Reference in New Issue
Block a user