OpenAsar/src/autoStart/win32.js

15 lines
929 B
JavaScript
Raw Normal View History

const { join, basename } = require('path');
2021-12-13 08:40:18 +00:00
const reg = (a, c) => require('child_process').execFile('reg.exe', a, c);
2021-12-13 08:40:18 +00:00
const appName = basename(process.execPath, '.exe');
const queuePrefix = [ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName ];
2021-12-13 08:40:18 +00:00
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
2021-12-13 08:40:18 +00:00
exports.uninstall = (cb) => reg([ 'delete', ...queuePrefix, '/f' ], () => cb()); // Delete reg
2021-12-13 08:40:18 +00:00
exports.isInstalled = (cb) => reg([ 'query', ...queuePrefix ], (e, out) => cb(out.includes(appName))); // Check reg