Skip to content

Commit

Permalink
fix: Unhijack globalShortcut & convert to local (#466)
Browse files Browse the repository at this point in the history
* convert to local keybinds

* fix lowercase check

* linting

* linting?

* final lint

* final final lint (trust)

* final final FINAL lint (this time for real)

* changelog entry
  • Loading branch information
alepouna authored Apr 14, 2024
1 parent 2911779 commit 85a2823
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .github/CHANGELOG.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@


releases:
- name: 3.4.1
changes:
- title: Shortcut keys no longer override other applications shortcuts
categories: [UI]
authors: [alepouna]
- name: 3.4.0
changes:
- title: Add a button to the error dialog to copy error messages to clipboard
Expand Down
31 changes: 18 additions & 13 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, Menu, globalShortcut, shell, ipcMain } from 'electron';
import { app, BrowserWindow, Menu, shell, ipcMain } from 'electron';
import { NsisUpdater } from 'electron-updater';
import * as path from 'path';
import installExtension, { REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';
Expand Down Expand Up @@ -134,18 +134,6 @@ function initializeApp() {
});
}

globalShortcut.register('CmdOrCtrl+R', () => {
mainWindow.isFocused() && mainWindow.reload();
});

globalShortcut.register('CmdOrCtrl+F5', () => {
mainWindow.isFocused() && mainWindow.reload();
});

globalShortcut.register('CmdOrCtrl+F12', () => {
mainWindow.isFocused() && mainWindow.webContents.toggleDevTools();
});

// Auto updater
if (process.env.NODE_ENV !== 'development') {
let updateOptions;
Expand Down Expand Up @@ -225,6 +213,23 @@ function initializeApp() {
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
}

//Register keybinds
mainWindow.webContents.on('before-input-event', (event, input) => {
// Check if the input event is for window reloading
if (
input.type === 'keyUp' &&
(input.key.toLowerCase() === 'r' || input.key === 'F5') &&
(input.control || input.meta)
) {
mainWindow.isFocused() && mainWindow.reload();
}

// Check if the input even is for dev tools
if (input.type === 'keyUp' && input.key === 'F12' && (input.control || input.meta)) {
mainWindow.isFocused() && mainWindow.webContents.toggleDevTools();
}
});
});

// Quit when all windows are closed, except on macOS. There, it's common
Expand Down

0 comments on commit 85a2823

Please sign in to comment.