Skip to content

Instantly share code, notes, and snippets.

@t4t5
Created May 19, 2020 18:44
Show Gist options
  • Save t4t5/8b238b146feef32e15fd8ff42269f4ec to your computer and use it in GitHub Desktop.
Save t4t5/8b238b146feef32e15fd8ff42269f4ec to your computer and use it in GitHub Desktop.
Electron: Quit macOS app with command + Q
// 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