mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-11 15:51:06 +00:00
Fix Window closing behavior
This commit is contained in:
parent
0c9d6312a4
commit
a910914aa4
@ -12,7 +12,7 @@ const {isOSX} = helpers;
|
||||
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
|
||||
const appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
||||
|
||||
const DEFAULT_ICON_PATH = path.join(__dirname, '/icon.png');
|
||||
const DEFAULT_ICON_PATH = path.join(__dirname, '..', '/icon.png');
|
||||
const Tray = electron.Tray;
|
||||
const Menu = electron.Menu;
|
||||
|
||||
@ -22,7 +22,7 @@ if (appArgs.insecure) {
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors');
|
||||
}
|
||||
|
||||
if(!appArgs.icon){
|
||||
if (!appArgs.icon) {
|
||||
appArgs.icon = DEFAULT_ICON_PATH;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ if (isOSX()) {
|
||||
app.on('window-all-closed', () => {
|
||||
// Need a better place to store user options, unless you intend to dump everything into cli
|
||||
// determined opts
|
||||
if(appArgs.minimizeToTray){
|
||||
if (appArgs.minimizeToTray) {
|
||||
mainWindow.hide();
|
||||
return;
|
||||
}
|
||||
@ -69,15 +69,31 @@ app.on('before-quit', () => {
|
||||
let appIcon = null;
|
||||
app.on('ready', () => {
|
||||
mainWindow = createMainWindow(appArgs, app.quit, setDockBadge);
|
||||
mainWindow.on('close', (e)=> {
|
||||
if (!mainWindow.forceClose && appArgs.minimizeToTray) {
|
||||
e.preventDefault();
|
||||
mainWindow.hide();
|
||||
}
|
||||
});
|
||||
|
||||
appIcon = new Tray(appArgs.icon);
|
||||
let menu = Menu.buildFromTemplate([
|
||||
// See https://github.com/atom/electron/blob/master/docs/api/tray.md for why
|
||||
// there is a shitty option to show
|
||||
{
|
||||
label: 'Show',
|
||||
type: 'normal',
|
||||
click: function (menuItem) {
|
||||
console.log(mainWindow);
|
||||
mainWindow.show();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Minimize to Tray',
|
||||
type: 'checkbox',
|
||||
checked: appArgs.minimizeToTray || true,
|
||||
click: function (menuItem) {
|
||||
appArgs.minimizeToTray = menuItem.checked = !menuItem.checked;
|
||||
appArgs.minimizeToTray = menuItem.checked;
|
||||
fs.writeFileSync(APP_ARGS_FILE_PATH, JSON.stringify(appArgs));
|
||||
}
|
||||
},
|
||||
@ -85,6 +101,7 @@ app.on('ready', () => {
|
||||
label: 'Close',
|
||||
type: 'normal',
|
||||
click: function (menuItem) {
|
||||
mainWindow.forceClose = true;
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user