diff --git a/installers/setupEvents.js b/installers/setupEvents.js index 57ce25e..75b6f30 100644 --- a/installers/setupEvents.js +++ b/installers/setupEvents.js @@ -23,11 +23,7 @@ module.exports = { return spawnedProcess; }; - - const spawnUpdate = function(args) { - return spawn(updateDotExe, args); - }; - + const squirrelEvent = process.argv[1]; switch (squirrelEvent) { case '--squirrel-install': @@ -36,20 +32,21 @@ module.exports = { // - Add your .exe to the PATH // - Write to the registry for things like file associations and // explorer context menus - - // Install desktop and start menu shortcuts - spawnUpdate(['--createShortcut', exeName]); - + setTimeout(app.quit, 1000); return true; case '--squirrel-uninstall': // Undo anything you did in the --squirrel-install and // --squirrel-updated handlers - - // Remove desktop and start menu shortcuts - spawnUpdate(['--removeShortcut', exeName]); - + + // Removing desktop shortcut + let fs = require('fs'); + var shortcut_path = app.getPath('desktop') + "\\Ryzen Controller"; + if (!fs.existsSync(shortcut_path)) { + fs.unlink(shortcut_path, console.log); + } + setTimeout(app.quit, 1000); return true; diff --git a/js/app.js b/js/app.js index a541b52..fc0f45e 100644 --- a/js/app.js +++ b/js/app.js @@ -9,6 +9,7 @@ ready(function(){ displayVersion(); reApplyPeriodically(require('electron-settings').get('settings.reapply_periodically')); displayOptionDescription(); + recreateShortcut(); document.isStarting = false; settings.set('settings', { ...settings.get('settings'), diff --git a/js/methods.js b/js/methods.js index a85f718..e8447db 100644 --- a/js/methods.js +++ b/js/methods.js @@ -282,3 +282,32 @@ function displayOptionDescription() { } } } + +/** + * Will recreate shortcut on launch ... no other solution for now :( + */ +function recreateShortcut() { + const settings = require('electron-settings'); + + if (!!settings.get('settings.first_launch')) { + let app = require('electron').remote.app; + let fs = require('fs'); + try { + var shortcut_path = app.getPath('desktop') + "\\Ryzen Controller"; + if (!fs.existsSync(shortcut_path)) { + fs.unlink(shortcut_path, console.log); + fs.symlink(app.getPath('exe'), shortcut_path, function (err) { + if (err) { + notification("danger", "Shortcut can't be created, please check log tabs for more info."); + appendLog(`recreateShortcut(): ${err}`); + } + else { + notification('primary', "A shortcut has been created on desktop."); + } + }); + } + } catch (error) { + appendLog(`recreateShortcut() ${error}`); + } + } +} diff --git a/package.json b/package.json index 10b28ae..9570632 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "main.js", "scripts": { "start": "electron .", - "package": "electron-packager . --overwrite --platform=win32 --arch=ia32 --prune=true --out=release-builds --ignore=\".*-builds\" --icon=\"assets/icon.ico\"", + "package": "electron-packager . --overwrite --platform=win32 --arch=ia32 --prune=true --out=release-builds --ignore=\".*-builds\" --icon=\"assets/icon.ico\" --win32metadata.requested-execution-level=requireAdministrator", "build": "node installers/windows/createinstaller.js" }, "repository": "https://gitlab.com/le.storm1er/ryzen-controller",