[Registry] Move installProtocol to util, minor source cleanup
This commit is contained in:
		
							parent
							
								
									f1ab5b0d91
								
							
						
					
					
						commit
						82c23cf845
					
				
					 2 changed files with 10 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -47,11 +47,6 @@ const updateShortcuts = (updater) => {
 | 
			
		|||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const installProtocol = (protocol, callback) => {
 | 
			
		||||
  const base = 'HKCU\\Software\\Classes\\' + protocol;
 | 
			
		||||
  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) => {
 | 
			
		||||
  log('FirstRun', 'Perform');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +61,7 @@ exports.performFirstRunTasks = (updater) => {
 | 
			
		|||
    log('FirstRun', 'Error updating shortcuts', e);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  installProtocol(Constants.APP_PROTOCOL, () => {
 | 
			
		||||
  registry.installProtocol(Constants.APP_PROTOCOL, () => {
 | 
			
		||||
    if (!shortcutSuccess) return;
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ const sr = process.env.SystemRoot;
 | 
			
		|||
const regExe = join(sr || '', sr ? 'System32' : '', 'reg.exe'); // %SystemRoot%\System32\reg.exe OR reg.exe if SR is undefined
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const spawn = (args, callback = (() => {})) => {
 | 
			
		||||
const spawn = (args, callback) => {
 | 
			
		||||
  let process, stdout = '';
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
| 
						 | 
				
			
			@ -21,17 +21,21 @@ const spawn = (args, callback = (() => {})) => {
 | 
			
		|||
  process.on('exit', (code, signal) => callback(code !== 0 ? new Error('Spawn: ' + signal ?? code) : null, stdout));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const add = (queue, callback = (() => {})) => {
 | 
			
		||||
const add = (queue, callback) => {
 | 
			
		||||
  const args = queue.shift();
 | 
			
		||||
  if (!args) return callback();
 | 
			
		||||
 | 
			
		||||
  args.unshift('add');
 | 
			
		||||
  args.push('/f');
 | 
			
		||||
  args = [ 'add', ...args, '/f' ];
 | 
			
		||||
 | 
			
		||||
  return spawn(args, () => add(queue, callback));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  spawn,
 | 
			
		||||
  add
 | 
			
		||||
  add,
 | 
			
		||||
 | 
			
		||||
  installProtocol: (protocol, callback) => {
 | 
			
		||||
    const base = 'HKCU\\Software\\Classes\\' + protocol;
 | 
			
		||||
    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);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue