asarfuckery/appasar/stable/app_bootstrap/autoStart/win32.js

67 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-01-17 18:22:05 +00:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.install = install;
exports.update = update;
exports.isInstalled = isInstalled;
exports.uninstall = uninstall;
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _windowsUtils = require('../windowsUtils');
var windowsUtils = _interopRequireWildcard(_windowsUtils);
var _appSettings = require('../appSettings');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2019-03-12 17:01:00 +00:00
const settings = (0, _appSettings.getSettings)();
2019-01-17 18:22:05 +00:00
// TODO: We should use Constant's APP_NAME, but only once
// we set up backwards compat with this.
2019-03-12 17:01:00 +00:00
const appName = _path2.default.basename(process.execPath, '.exe');
2019-01-17 18:22:05 +00:00
function install(callback) {
2019-03-12 17:01:00 +00:00
const startMinimized = settings.get('START_MINIMIZED', false);
let { execPath } = process;
2019-01-17 18:22:05 +00:00
if (startMinimized) {
2019-03-12 17:01:00 +00:00
execPath = `${execPath} --start-minimized`;
2019-01-17 18:22:05 +00:00
}
2019-03-12 17:01:00 +00:00
const queue = [['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/d', execPath]];
2019-01-17 18:22:05 +00:00
windowsUtils.addToRegistry(queue, callback);
}
function update(callback) {
2019-03-12 17:01:00 +00:00
isInstalled(installed => {
2019-01-17 18:22:05 +00:00
if (installed) {
install(callback);
} else {
callback();
}
});
}
function isInstalled(callback) {
2019-03-12 17:01:00 +00:00
const queryValue = ['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName];
2019-01-17 18:22:05 +00:00
queryValue.unshift('query');
2019-03-12 17:01:00 +00:00
windowsUtils.spawnReg(queryValue, (error, stdout) => {
const doesOldKeyExist = stdout.indexOf(appName) >= 0;
2019-01-17 18:22:05 +00:00
callback(doesOldKeyExist);
});
}
function uninstall(callback) {
2019-03-12 17:01:00 +00:00
const queryValue = ['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/f'];
2019-01-17 18:22:05 +00:00
queryValue.unshift('delete');
2019-03-12 17:01:00 +00:00
windowsUtils.spawnReg(queryValue, (error, stdout) => {
2019-01-17 18:22:05 +00:00
callback();
});
}