[Registry] Rewrite to just have spawn export, rewrite various internals to use new

pull/66/head
Oj 2 years ago
parent fe66b3133d
commit 4a4c6e2e3a

@ -1,15 +1,15 @@
const { join, basename } = require('path');
const registry = require('../utils/registry');
const reg = require('../utils/registry');
const appName = basename(process.execPath, '.exe');
const queuePrefix = [ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName ];
exports.install = (cb) => registry.add([[ ...queuePrefix, '/d', join(process.execPath, '..', '..', 'Update.exe') + ` --processStart ${basename(process.execPath)}` + (settings.get('START_MINIMIZED') ? ' --process-start-args --start-minimized' : '') ]], cb); // Make reg (with Electron args if start min)
exports.install = (cb) => reg([ 'add', ...queuePrefix, '/d', join(process.execPath, '..', '..', 'Update.exe') + ' --processStart ' + basename(process.execPath) + (settings.get('START_MINIMIZED') ? ' --process-start-args --start-minimized' : ''), '/f' ], cb); // Make reg (with Electron args if start min)
exports.update = (cb) => exports.isInstalled(installed => installed ? exports.install(cb) : cb()); // Reinstall if installed, else just cb
exports.uninstall = (cb) => registry.spawn([ 'delete', ...queuePrefix, '/f' ], () => cb()); // Delete reg
exports.uninstall = (cb) => reg([ 'delete', ...queuePrefix, '/f' ], () => cb()); // Delete reg
exports.isInstalled = (cb) => registry.spawn([ 'query', ...queuePrefix ], (e, out) => cb(out.includes(appName))); // Check reg
exports.isInstalled = (cb) => reg([ 'query', ...queuePrefix ], (e, out) => cb(out.includes(appName))); // Check reg

@ -1,11 +1,3 @@
const CP = require('child_process');
exports.spawn = (args, cb) => CP.execFile('reg.exe', args, cb);
exports.add = (todo, cb) => {
const x = todo.shift();
if (!x) return cb();
exports.spawn([ 'add', ...x, '/f' ], () => exports.add(todo, cb));
};
module.exports = (args, cb) => CP.execFile('reg.exe', args, cb);

@ -2,6 +2,7 @@ const fs = require('fs');
const { join, resolve, basename } = require('path');
const Constants = require('./Constants');
const reg = require('./utils/registry');
const exec = process.execPath;
const app = resolve(exec, '..');
@ -15,34 +16,38 @@ exports.do = (updater) => {
const proto = Constants.APP_PROTOCOL;
const base = 'HKCU\\Software\\Classes\\' + proto;
require('./utils/registry').add([[base, '/ve', '/d', `URL:${proto} Protocol`], [base, '/v', 'URL Protocol'], [base + '\\DefaultIcon', '/ve', '/d', `"${process.execPath}",-1`], [base + '\\shell\\open\\command', '/ve', '/d', `"${process.execPath}" --url -- "%1"`]], () => { // Make protocol
try { // Make shortcuts
const file = Constants.APP_NAME_FOR_HUMANS + '.lnk';
const icon_path = join(root, 'app.ico');
fs.copyFileSync(join(app, 'app.ico'), icon_path); // app-1.0.0/app.ico -> app.ico
for (const shortcut_path of [
join(updater.getKnownFolder('desktop'), file),
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file)
]) {
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
updater.createShortcut({
target_path: join(root, 'Update.exe'),
shortcut_path,
arguments: '--processStart ' + basename(process.execPath),
icon_path,
icon_index: 0,
description: Constants.APP_DESCRIPTION,
app_user_model_id: Constants.APP_ID,
working_directory: app
});
}
fs.writeFileSync(flag, 'true');
} catch (e) {
log('FirstRun', e);
for (const x of [
[base, '/ve', '/d', `URL:${proto} Protocol`], [base, '/v', 'URL Protocol'],
[base + '\\DefaultIcon', '/ve', '/d', `"${exec}",-1`],
[base + '\\shell\\open\\command', '/ve', '/d', `"${exec}" --url -- "%1"`]
]) reg([ 'add', ...x, '/f' ], e => {});
try { // Make shortcuts
const file = Constants.APP_NAME_FOR_HUMANS + '.lnk';
const icon_path = join(root, 'app.ico');
fs.copyFileSync(join(app, 'app.ico'), icon_path); // app-1.0.0/app.ico -> app.ico
for (const shortcut_path of [
join(updater.getKnownFolder('desktop'), file),
join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, file)
]) {
if (!fs.existsSync(shortcut_path)) continue; // Don't update already deleted paths
updater.createShortcut({
target_path: join(root, 'Update.exe'),
shortcut_path,
arguments: '--processStart ' + basename(exec),
icon_path,
icon_index: 0,
description: Constants.APP_DESCRIPTION,
app_user_model_id: Constants.APP_ID,
working_directory: app
});
}
});
fs.writeFileSync(flag, 'true');
} catch (e) {
log('FirstRun', e);
}
};
Loading…
Cancel
Save