Re-implement minimize on close.

This commit is contained in:
Keith Maika 2022-01-16 17:15:06 -05:00
parent 1d19fba89f
commit 948f56fdea
No known key found for this signature in database
GPG Key ID: F71740E8722C75F1
2 changed files with 21 additions and 15 deletions

22
main.js
View File

@ -8,7 +8,7 @@ let mainWindow
// Require other app modules
const trayService = require(__dirname+'/modules/tray-service')
const menuService = require(__dirname+'/modules/menu-service')
// const settingsService = require(__dirname+'/modules/settings-service')
const settingsService = require(__dirname+'/modules/settings-service')
const isMac = process.platform === 'darwin'
const isWin = process.platform === 'win32'
@ -50,21 +50,17 @@ function createWindow () {
// mainWindow.webContents.openDevTools()
// Before close
// const minimizeOnClose = settingsService.get('minimizeOnClose');
const minimizeOnClose = false; // XXX: this doesn't seem to work
if (minimizeOnClose) {
mainWindow.on('close', (e) => {
if (!app.isQuitting) {
e.preventDefault()
mainWindow.hide()
}
return false;
})
}
mainWindow.on('close', (e) => {
if (!app.isQuitting && settingsService.get('minimizeOnClose')) {
e.preventDefault()
mainWindow.hide()
}
return false;
})
// Handle shutdown event on Mac with minimizeOnClose
// to prevent shutdown interrupt
if (isMac && minimizeOnClose) {
if (isMac) {
const { powerMonitor } = require('electron')
powerMonitor.on('shutdown', () => {
app.isQuitting = true

View File

@ -2,6 +2,7 @@
* Module for Menu functions.
*/
const {app, Menu, BrowserWindow} = require('electron')
const settingsService = require(__dirname + '/../modules/settings-service')
const menuService = {}
@ -19,6 +20,15 @@ menuService.createMenu = () => {
activeWindow.reload()
}
},
{
label: 'Minimize on close',
type: 'checkbox',
checked: settingsService.get('minimizeOnClose'),
click: () => {
this.checked = !this.checked;
settingsService.set('minimizeOnClose', this.checked);
}
},
{
type: 'separator',
},
@ -30,7 +40,7 @@ menuService.createMenu = () => {
app.quit()
},
},
],
],
}
const edit = {
@ -67,7 +77,7 @@ menuService.createMenu = () => {
accelerator: 'CmdOrCtrl+A',
role: 'selectAll',
},
],
],
}
const help = {