Send global shortcut to current window (#7645)

This commit is contained in:
Elian Doran
2025-11-08 08:31:17 +02:00
committed by GitHub

View File

@@ -337,14 +337,15 @@ async function registerGlobalShortcuts() {
const result = globalShortcut.register( const result = globalShortcut.register(
translatedShortcut, translatedShortcut,
cls.wrap(() => { cls.wrap(() => {
if (!mainWindow) { const targetWindow = getLastFocusedWindow() || mainWindow;
if (!targetWindow || targetWindow.isDestroyed()) {
return; return;
} }
// window may be hidden / not in focus // window may be hidden / not in focus
mainWindow.focus(); showAndFocusWindow(targetWindow);
mainWindow.webContents.send("globalShortcut", action.actionName); targetWindow.webContents.send("globalShortcut", action.actionName);
}) })
); );
@@ -358,6 +359,17 @@ async function registerGlobalShortcuts() {
} }
} }
function showAndFocusWindow(window: BrowserWindow) {
if (!window) return;
if (window.isMinimized()) {
window.restore();
}
window.show();
window.focus();
}
function getMainWindow() { function getMainWindow() {
return mainWindow; return mainWindow;
} }