[Registry] Rename WindowsUtils to Registry, more specialised rewrite

This commit is contained in:
Ducko 2022-03-10 08:46:09 +00:00
parent ee98fe11ae
commit 1540dfcbbb
3 changed files with 15 additions and 11 deletions

View File

@ -1,6 +1,6 @@
const path = require('path'); const path = require('path');
const windowsUtils = require('../utils/windowsUtils'); const registry = require('../utils/registry');
const retainAsar = require('./retainAsar'); const retainAsar = require('./retainAsar');
const appSettings = require('../appSettings'); const appSettings = require('../appSettings');
@ -16,7 +16,7 @@ exports.install = (callback) => {
log('AutoStart', 'Install'); 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 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) => { exports.update = (callback) => {
@ -30,7 +30,7 @@ exports.update = (callback) => {
exports.uninstall = (callback) => { exports.uninstall = (callback) => {
log('AutoStart', 'Uninstall'); 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

View File

@ -1,7 +1,8 @@
const fs = require('fs'); const fs = require('fs');
const { join, resolve, basename } = require('path'); const { join, resolve, basename } = require('path');
const paths = require('../paths'); const paths = require('../paths');
const windowsUtils = require('../utils/windowsUtils'); const registry = require('../utils/registry');
const Constants = require('../Constants'); const Constants = require('../Constants');
const appPath = resolve(process.execPath, '..'); const appPath = resolve(process.execPath, '..');
@ -48,7 +49,7 @@ const updateShortcuts = (updater) => {
const installProtocol = (protocol, callback) => { const installProtocol = (protocol, callback) => {
const base = 'HKCU\\Software\\Classes\\' + protocol; 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) => { exports.performFirstRunTasks = (updater) => {

View File

@ -4,7 +4,7 @@ const { join } = require('path');
const sr = process.env.SystemRoot; 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 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 = ''; let process, stdout = '';
try { 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)); 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(); const args = queue.shift();
if (!args) return callback(); if (!args) return callback();
args.unshift('add'); args.unshift('add');
args.push('/f'); args.push('/f');
return spawnReg(args, () => addToRegistry(queue, callback)); return spawnReg(args, () => add(queue, callback));
}; };
module.exports = { spawn, spawnReg, addToRegistry }; module.exports = {
spawn,
add
};