diff --git a/src/autoStart/win32.js b/src/autoStart/win32.js index 54af769..511a892 100644 --- a/src/autoStart/win32.js +++ b/src/autoStart/win32.js @@ -1,15 +1,15 @@ const { join, basename } = require('path'); -const registry = require('../utils/registry'); +const reg = require('../utils/registry'); const appName = basename(process.execPath, '.exe'); const queuePrefix = [ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName ]; -exports.install = (cb) => registry.add([[ ...queuePrefix, '/d', join(process.execPath, '..', '..', 'Update.exe') + ` --processStart ${basename(process.execPath)}` + (settings.get('START_MINIMIZED') ? ' --process-start-args --start-minimized' : '') ]], cb); // Make reg (with Electron args if start min) +exports.install = (cb) => reg([ 'add', ...queuePrefix, '/d', join(process.execPath, '..', '..', 'Update.exe') + ' --processStart ' + basename(process.execPath) + (settings.get('START_MINIMIZED') ? ' --process-start-args --start-minimized' : ''), '/f' ], cb); // Make reg (with Electron args if start min) exports.update = (cb) => exports.isInstalled(installed => installed ? exports.install(cb) : cb()); // Reinstall if installed, else just cb -exports.uninstall = (cb) => registry.spawn([ 'delete', ...queuePrefix, '/f' ], () => cb()); // Delete reg +exports.uninstall = (cb) => reg([ 'delete', ...queuePrefix, '/f' ], () => cb()); // Delete reg -exports.isInstalled = (cb) => registry.spawn([ 'query', ...queuePrefix ], (e, out) => cb(out.includes(appName))); // Check reg \ No newline at end of file +exports.isInstalled = (cb) => reg([ 'query', ...queuePrefix ], (e, out) => cb(out.includes(appName))); // Check reg \ No newline at end of file diff --git a/src/utils/registry.js b/src/utils/registry.js index 6479305..7088a9d 100644 --- a/src/utils/registry.js +++ b/src/utils/registry.js @@ -1,11 +1,3 @@ const CP = require('child_process'); - -exports.spawn = (args, cb) => CP.execFile('reg.exe', args, cb); - -exports.add = (todo, cb) => { - const x = todo.shift(); - if (!x) return cb(); - - exports.spawn([ 'add', ...x, '/f' ], () => exports.add(todo, cb)); -}; \ No newline at end of file +module.exports = (args, cb) => CP.execFile('reg.exe', args, cb); \ No newline at end of file diff --git a/src/winFirst.js b/src/winFirst.js index cf5c0e0..e8c4852 100644 --- a/src/winFirst.js +++ b/src/winFirst.js @@ -2,6 +2,7 @@ const fs = require('fs'); const { join, resolve, basename } = require('path'); const Constants = require('./Constants'); +const reg = require('./utils/registry'); const exec = process.execPath; const app = resolve(exec, '..'); @@ -15,34 +16,38 @@ exports.do = (updater) => { const proto = Constants.APP_PROTOCOL; const base = 'HKCU\\Software\\Classes\\' + proto; - require('./utils/registry').add([[base, '/ve', '/d', `URL:${proto} Protocol`], [base, '/v', 'URL Protocol'], [base + '\\DefaultIcon', '/ve', '/d', `"${process.execPath}",-1`], [base + '\\shell\\open\\command', '/ve', '/d', `"${process.execPath}" --url -- "%1"`]], () => { // Make protocol - try { // Make shortcuts - const file = Constants.APP_NAME_FOR_HUMANS + '.lnk'; - const icon_path = join(root, 'app.ico'); - - fs.copyFileSync(join(app, 'app.ico'), icon_path); // app-1.0.0/app.ico -> app.ico - - for (const shortcut_path of [ - join(updater.getKnownFolder('desktop'), file), - join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file) - ]) { - if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths - - updater.createShortcut({ - target_path: join(root, 'Update.exe'), - shortcut_path, - arguments: '--processStart ' + basename(process.execPath), - icon_path, - icon_index: 0, - description: Constants.APP_DESCRIPTION, - app_user_model_id: Constants.APP_ID, - working_directory: app - }); - } + for (const x of [ + [base, '/ve', '/d', `URL:${proto} Protocol`], [base, '/v', 'URL Protocol'], + [base + '\\DefaultIcon', '/ve', '/d', `"${exec}",-1`], + [base + '\\shell\\open\\command', '/ve', '/d', `"${exec}" --url -- "%1"`] + ]) reg([ 'add', ...x, '/f' ], e => {}); - fs.writeFileSync(flag, 'true'); - } catch (e) { - log('FirstRun', e); + try { // Make shortcuts + const file = Constants.APP_NAME_FOR_HUMANS + '.lnk'; + const icon_path = join(root, 'app.ico'); + + fs.copyFileSync(join(app, 'app.ico'), icon_path); // app-1.0.0/app.ico -> app.ico + + for (const shortcut_path of [ + join(updater.getKnownFolder('desktop'), file), + join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file) + ]) { + if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths + + updater.createShortcut({ + target_path: join(root, 'Update.exe'), + shortcut_path, + arguments: '--processStart ' + basename(exec), + icon_path, + icon_index: 0, + description: Constants.APP_DESCRIPTION, + app_user_model_id: Constants.APP_ID, + working_directory: app + }); } - }); + + fs.writeFileSync(flag, 'true'); + } catch (e) { + log('FirstRun', e); + } }; \ No newline at end of file