feat: #3 Auto start on windows session login.

This commit is contained in:
Quentin Decaunes 2019-08-03 21:59:03 +02:00
parent 1a1990b9ad
commit b5b9b3c839
5 changed files with 541 additions and 374 deletions

View File

@ -42,8 +42,8 @@
</li> </li>
<li class="uk-margin-top uk-margin-bottom uk-container"> <li class="uk-margin-top uk-margin-bottom uk-container">
<!-- <h3>Auto start with system:</h3> --> <h3 class="windows-only">Auto start:</h3>
<!-- <label><input class="uk-checkbox" type="checkbox" id="start_at_boot"> When checked, Ryzen Controller will start on system login.</label> --> <label class="windows-only"><input class="uk-checkbox" type="checkbox" id="start_at_boot"> When checked, Ryzen Controller will start on session start.</label>
<h3>Auto apply on launch:</h3> <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> <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> <h3>Minimize to tray:</h3>

View File

@ -208,7 +208,7 @@ function preFillSettings() {
notification('danger', "Path to ryzenadj.exe is wrong, please fix it in settings tab."); notification('danger', "Path to ryzenadj.exe is wrong, please fix it in settings tab.");
} }
const settings = require('electron-settings'); const settings = require('electron-settings');
// document.getElementById('start_at_boot').checked = !!settings.get('settings.start_at_boot'); document.getElementById('start_at_boot').checked = !!settings.get('settings.start_at_boot');
document.getElementById('apply_last_settings_on_launch').checked = !!settings.get('settings.apply_last_settings_on_launch'); 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'); document.getElementById('minimize_to_tray').checked = !!settings.get('settings.minimize_to_tray');
document.getElementById('start_minimized').checked = !!settings.get('settings.start_minimized'); document.getElementById('start_minimized').checked = !!settings.get('settings.start_minimized');
@ -391,20 +391,20 @@ function registerEventListenerForSettingsInput() {
); );
}); });
// var start_at_boot = document.getElementById('start_at_boot'); var start_at_boot = document.getElementById('start_at_boot');
// start_at_boot.addEventListener('change', function() { start_at_boot.addEventListener('change', function() {
//
// settings.set( settings.set(
// "settings", "settings",
// Object.assign( Object.assign(
// {}, {},
// settings.get('settings'), settings.get('settings'),
// { start_at_boot: !!start_at_boot.checked } { start_at_boot: !!start_at_boot.checked }
// ) )
// ); );
//
// require('electron').remote.app.setLoginItemSettings({ openAtLogin: !!start_at_boot.checked }); updateScheduledStartOnBoot(!!start_at_boot.checked);
// }); });
} }
/** /**
@ -564,3 +564,25 @@ function handlePlatformSpecificDisplay() {
} }
} }
} }
/**
* Will delete scheduled task to start ryzen controller on session start then recreate it if isEnable is true.
*
* @param {bool} toBeEnabled Is auto launch should be enabled?
*/
function updateScheduledStartOnBoot(toBeEnabled) {
const app = require('electron').remote.app;
window.app = app;
const AutoLaunch = require('auto-launch');
let autoLaunch = new AutoLaunch({
name: 'Ryzen Controller'
});
autoLaunch.isEnabled().then((isEnabled) => {
console.log(`toBeEnabled: ${toBeEnabled} isEnabled: ${isEnabled}`);
if (toBeEnabled && !isEnabled) {
autoLaunch.enable();
} else {
autoLaunch.disable();
}
});
}

11
main.js
View File

@ -8,9 +8,6 @@ if (!setupEvents.handleSquirrelEvent()) {
const {app, BrowserWindow, Menu, Tray} = require('electron') const {app, BrowserWindow, Menu, Tray} = require('electron')
const settings = require('electron-settings'); const settings = require('electron-settings');
// Check and apply start_on_boot option.
app.setLoginItemSettings({ openAtLogin: !!settings.get('settings.start_at_boot') });
// Check for latest used version and clear settings if needed. // Check for latest used version and clear settings if needed.
const old_version = settings.get('settings.last_used_version'); const old_version = settings.get('settings.last_used_version');
const new_version = require('./package.json').version; const new_version = require('./package.json').version;
@ -110,6 +107,14 @@ if (!setupEvents.handleSquirrelEvent()) {
settings.set('latest_controller_tabs_settings', update_preset_to_1_12_0(settings.get('latest_controller_tabs_settings'))); settings.set('latest_controller_tabs_settings', update_preset_to_1_12_0(settings.get('latest_controller_tabs_settings')));
} }
/**
* Since 1.14.0, login managed through s=windows scheduler
*/
if (compareVersions(old_version, '1.14.0') <= 0) {
// Ensure login on start false.
app.setLoginItemSettings({ openAtLogin: false });
}
settings.set('settings', settings.set('settings',
Object.assign( Object.assign(
{}, {},

847
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@
"electron-packager": "^13.1.0" "electron-packager": "^13.1.0"
}, },
"dependencies": { "dependencies": {
"auto-launch": "^5.0.5",
"compare-versions": "^3.4.0", "compare-versions": "^3.4.0",
"electron-settings": "^3.2.0", "electron-settings": "^3.2.0",
"fix-path": "^2.1.0", "fix-path": "^2.1.0",