mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 07:15:51 +01:00
Send global shortcut to current window (#7645)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user