From 45dfaacffe57f1f38e9f1dd2f9659c3891125a9e Mon Sep 17 00:00:00 2001 From: Quentin Decaunes Date: Fri, 1 Mar 2019 16:24:43 +0100 Subject: [PATCH] See #1 Added minimize to tray capability. --- index.html | 2 ++ js/methods.js | 8 ++++++++ main.js | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index b7b213a..84d7a60 100644 --- a/index.html +++ b/index.html @@ -72,6 +72,8 @@
  • Auto apply on launch:

    +

    Minimize to tray:

    +

    Ryzenadj path:

    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