OpenAsar/src/autoStart/win32.js

19 lines
1 KiB
JavaScript
Raw Normal View History

const { join, basename, dirname } = require('path');
2021-12-13 08:40:18 +00:00
const registry = require('../utils/registry');
2021-12-13 08:40:18 +00:00
const appName = basename(process.execPath, '.exe');
2021-12-13 08:40:18 +00:00
const queuePrefix = [ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName ];
2021-12-13 08:40:18 +00:00
exports.install = (callback) => {
const execPath = join(dirname(process.execPath), '..', 'Update.exe') + ` --processStart ${basename(process.execPath)}` + (settings.get('START_MINIMIZED', false) ? ' --process-start-args --start-minimized' : ''); // Add Electron args if start minimized on
registry.add([[ ...queuePrefix, '/d', execPath ]], callback); // Make reg
2021-12-13 08:40:18 +00:00
};
exports.update = (callback) => exports.isInstalled(installed => installed ? exports.install(callback) : callback()); // Reinstall if installed, else just callback
2021-12-13 08:40:18 +00:00
exports.uninstall = (callback) => registry.spawn([ 'delete', ...queuePrefix, '/f' ], () => callback()); // Delete reg
2021-12-13 08:40:18 +00:00
exports.isInstalled = (callback) => registry.spawn([ 'query', ...queuePrefix ], () => callback(stdout.includes(appName))); // Check reg