From 1540dfcbbbc40906cfb6bdedf31fb8a2bf593cfd Mon Sep 17 00:00:00 2001 From: Oj Date: Thu, 10 Mar 2022 08:46:09 +0000 Subject: [PATCH] [Registry] Rename WindowsUtils to Registry, more specialised rewrite --- src/autoStart/win32.js | 8 ++++---- src/firstRun/win32.js | 5 +++-- src/utils/{windowsUtils.js => registry.js} | 13 ++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) rename src/utils/{windowsUtils.js => registry.js} (70%) diff --git a/src/autoStart/win32.js b/src/autoStart/win32.js index 0454071..df5f0b7 100644 --- a/src/autoStart/win32.js +++ b/src/autoStart/win32.js @@ -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 \ No newline at end of file +exports.isInstalled = (callback) => registry.spawn(['query', ...queuePrefix], (_error, stdout) => callback(stdout.includes(appName))); // Check reg \ No newline at end of file diff --git a/src/firstRun/win32.js b/src/firstRun/win32.js index 26e198b..96b84a1 100644 --- a/src/firstRun/win32.js +++ b/src/firstRun/win32.js @@ -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) => { diff --git a/src/utils/windowsUtils.js b/src/utils/registry.js similarity index 70% rename from src/utils/windowsUtils.js rename to src/utils/registry.js index e44b50c..1abdfe5 100644 --- a/src/utils/windowsUtils.js +++ b/src/utils/registry.js @@ -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 }; \ No newline at end of file +module.exports = { + spawn, + add +}; \ No newline at end of file