Behave like a single-window Mac app on Mac
This commit is contained in:
parent
31607f0776
commit
3c55629208
1 changed files with 19 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
const {app, BrowserWindow} = require('electron');
|
||||
|
||||
let mainWindow = null;
|
||||
let appQuitting = false;
|
||||
|
||||
app.on('ready', () => {
|
||||
mainWindow = new BrowserWindow({
|
||||
|
@ -12,8 +13,26 @@ app.on('ready', () => {
|
|||
mainWindow.on('closed', () => {
|
||||
mainWindow = null;
|
||||
});
|
||||
mainWindow.on('close', (e) => {
|
||||
if (process.platform == 'darwin' && !appQuitting) {
|
||||
// On Mac, closing the window just hides it
|
||||
// (this is generally how single-window Mac apps
|
||||
// behave, eg. Mail.app)
|
||||
e.preventDefault();
|
||||
mainWindow.hide();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
app.on('before-quit', () => {
|
||||
appQuitting = true;
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue