See #1 Added minimize to tray capability.

This commit is contained in:
Quentin Decaunes 2019-03-01 16:24:43 +01:00
parent 50a935fd45
commit 45dfaacffe
3 changed files with 42 additions and 5 deletions

View File

@ -72,6 +72,8 @@
<li class="uk-container uk-animation-fade">
<h3>Auto apply on launch:</h3>
<label><input class="uk-checkbox" type="checkbox" id="apply_last_settings_on_launch"> When checked, Ryzen Controller will try to apply latest used settings on launch.</label>
<h3>Minimize to tray:</h3>
<label><input class="uk-checkbox" type="checkbox" id="minimize_to_tray"> When checked, Ryzen Controller will minimize to tray instead of taskbar.</label>
<h3>Ryzenadj path:</h3>
<div class="uk-grid-small" uk-grid>
<div class="uk-width-2-3@s">

View File

@ -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() {

29
main.js
View File

@ -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.
@ -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