Created
May 19, 2020 18:44
-
-
Save t4t5/8b238b146feef32e15fd8ff42269f4ec to your computer and use it in GitHub Desktop.
Electron: Quit macOS app with command + Q
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Quit app on macOS ONLY if using command + Q or some other force quit option: | |
win = new BrowserWindow({ width: 500, height: 500 }) | |
let forceQuit = false | |
// Triggered before close event, i.e. when pressing command + Q | |
app.on('before-quit', () => { | |
forceQuit = true | |
}) | |
win.on('close', e => { | |
if (!forceQuit && process.platform === 'darwin') { // "darwin" is macOS | |
e.preventDefault() // Prevents quit | |
win.hide() | |
} | |
// Let the app quit normally… | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment