diff --git a/js/methods.js b/js/methods.js
index 81d133f..1550729 100644
--- a/js/methods.js
+++ b/js/methods.js
@@ -117,6 +117,7 @@ function preFillSettings() {
}
const settings = require('electron-settings');
document.getElementById('apply_last_settings_on_launch').checked = settings.get('settings.apply_last_settings_on_launch');
+ document.getElementById('minimize_to_tray').checked = settings.get('settings.minimize_to_tray');
}
/**
@@ -204,6 +205,13 @@ function registerEventListenerForSettingsInput() {
apply_last_settings_on_launch: !!apply_last_settings_on_launch.checked
});
});
+ var minimize_to_tray = document.getElementById('minimize_to_tray');
+ minimize_to_tray.addEventListener('change', function() {
+ settings.set('settings', {
+ ...settings.get('settings'),
+ minimize_to_tray: !!minimize_to_tray.checked
+ });
+ });
}
function displayVersion() {
diff --git a/main.js b/main.js
index d65d0e0..86ededd 100644
--- a/main.js
+++ b/main.js
@@ -6,7 +6,7 @@ if (setupEvents.handleSquirrelEvent()) {
}
// Modules to control application life and create native browser window
-const {app, BrowserWindow} = require('electron')
+const {app, BrowserWindow, Menu, Tray} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@@ -21,15 +21,15 @@ function createWindow () {
nodeIntegration: true
}
})
-
+
mainWindow.setOpacity(0.95);
-
+
// and load the index.html of the app.
mainWindow.loadFile('index.html')
-
+
// Open the DevTools.
// mainWindow.webContents.openDevTools()
-
+
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
@@ -37,6 +37,33 @@ function createWindow () {
// when you should delete the corresponding element.
mainWindow = null
})
+
+ const settings = require('electron-settings');
+ mainWindow.on('minimize',function(event){
+ if (settings.get('settings.minimize_to_tray')) {
+ event.preventDefault();
+ mainWindow.hide();
+ }
+ });
+
+ var contextMenu = Menu.buildFromTemplate([
+ {
+ label: 'Show App',
+ click: function () {
+ mainWindow.show();
+ }
+ },
+ {
+ label: 'Quit',
+ click: function () {
+ application.isQuiting = true;
+ application.quit();
+ }
+ }
+ ]);
+
+ var appIcon = new Tray(__dirname + '/assets/icon.ico');
+ appIcon.setContextMenu(contextMenu);
}
// This method will be called when Electron has finished