[Registry] Rename WindowsUtils to Registry, more specialised rewrite
This commit is contained in:
parent
ee98fe11ae
commit
1540dfcbbb
3 changed files with 15 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
const path = require('path');
|
||||
|
||||
const windowsUtils = require('../utils/windowsUtils');
|
||||
const registry = require('../utils/registry');
|
||||
const retainAsar = require('./retainAsar');
|
||||
|
||||
const appSettings = require('../appSettings');
|
||||
|
@ -16,7 +16,7 @@ exports.install = (callback) => {
|
|||
log('AutoStart', 'Install');
|
||||
|
||||
const execPath = `${updatePath} --processStart ${fullExeName}` + (settings.get('START_MINIMIZED', false) ? ' --process-start-args --start-minimized' : ''); // Add Electron args if start minimized on
|
||||
windowsUtils.addToRegistry([[...queuePrefix, '/d', execPath]], callback); // Make reg
|
||||
registry.add([[...queuePrefix, '/d', execPath]], callback); // Make reg
|
||||
};
|
||||
|
||||
exports.update = (callback) => {
|
||||
|
@ -30,7 +30,7 @@ exports.update = (callback) => {
|
|||
exports.uninstall = (callback) => {
|
||||
log('AutoStart', 'Uninstall');
|
||||
|
||||
windowsUtils.spawnReg(['delete', ...queuePrefix, '/f'], (_error, _stdout) => callback()); // Delete reg
|
||||
registry.spawn(['delete', ...queuePrefix, '/f'], (_error, _stdout) => callback()); // Delete reg
|
||||
};
|
||||
|
||||
exports.isInstalled = (callback) => windowsUtils.spawnReg(['query', ...queuePrefix], (_error, stdout) => callback(stdout.includes(appName))); // Check reg
|
||||
exports.isInstalled = (callback) => registry.spawn(['query', ...queuePrefix], (_error, stdout) => callback(stdout.includes(appName))); // Check reg
|
|
@ -1,7 +1,8 @@
|
|||
const fs = require('fs');
|
||||
const { join, resolve, basename } = require('path');
|
||||
|
||||
const paths = require('../paths');
|
||||
const windowsUtils = require('../utils/windowsUtils');
|
||||
const registry = require('../utils/registry');
|
||||
const Constants = require('../Constants');
|
||||
|
||||
const appPath = resolve(process.execPath, '..');
|
||||
|
@ -48,7 +49,7 @@ const updateShortcuts = (updater) => {
|
|||
|
||||
const installProtocol = (protocol, callback) => {
|
||||
const base = 'HKCU\\Software\\Classes\\' + protocol;
|
||||
windowsUtils.addToRegistry([[base, '/ve', '/d', `URL:${protocol} Protocol`], [base, '/v', 'URL Protocol'], [base + '\\DefaultIcon', '/ve', '/d', '"' + process.execPath + '",-1'], [base + '\\shell\\open\\command', '/ve', '/d', `"${process.execPath}" --url -- "%1"`]], callback);
|
||||
registry.add([[base, '/ve', '/d', `URL:${protocol} Protocol`], [base, '/v', 'URL Protocol'], [base + '\\DefaultIcon', '/ve', '/d', '"' + process.execPath + '",-1'], [base + '\\shell\\open\\command', '/ve', '/d', `"${process.execPath}" --url -- "%1"`]], callback);
|
||||
};
|
||||
|
||||
exports.performFirstRunTasks = (updater) => {
|
||||
|
|
|
@ -4,7 +4,7 @@ const { join } = require('path');
|
|||
const sr = process.env.SystemRoot;
|
||||
const regExePath = join(sr || '', sr ? 'System32' : '', 'reg.exe'); // %SystemRoot%\System32\reg.exe OR reg.exe if SR is undefined
|
||||
|
||||
const spawn = (cmd, args, callback = (() => {})) => {
|
||||
const _spawn = (cmd, args, callback = (() => {})) => {
|
||||
let process, stdout = '';
|
||||
|
||||
try {
|
||||
|
@ -20,16 +20,19 @@ const spawn = (cmd, args, callback = (() => {})) => {
|
|||
process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn returned: ' + signal ?? code) : null, stdout));
|
||||
};
|
||||
|
||||
const spawnReg = (args, callback) => spawn(regExePath, args, callback);
|
||||
const spawn = (args, callback) => _spawn(regExePath, args, callback);
|
||||
|
||||
const addToRegistry = (queue, callback = (() => {})) => {
|
||||
const add = (queue, callback = (() => {})) => {
|
||||
const args = queue.shift();
|
||||
if (!args) return callback();
|
||||
|
||||
args.unshift('add');
|
||||
args.push('/f');
|
||||
|
||||
return spawnReg(args, () => addToRegistry(queue, callback));
|
||||
return spawnReg(args, () => add(queue, callback));
|
||||
};
|
||||
|
||||
module.exports = { spawn, spawnReg, addToRegistry };
|
||||
module.exports = {
|
||||
spawn,
|
||||
add
|
||||
};
|
Loading…
Reference in a new issue