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(
translatedShortcut,
cls.wrap(() => {
if (!mainWindow) {
const targetWindow = getLastFocusedWindow() || mainWindow;
if (!targetWindow || targetWindow.isDestroyed()) {
return;
}
// 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() {
return mainWindow;
}