[Splash > Backend] Minor source cleanup
This commit is contained in:
		
							parent
							
								
									b20b3a1566
								
							
						
					
					
						commit
						53f2767b28
					
				
					 2 changed files with 12 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -10,7 +10,6 @@ let splashState = {};
 | 
			
		|||
let modulesListeners = {};
 | 
			
		||||
let launchedMainWindow = false;
 | 
			
		||||
let updateAttempt = 0;
 | 
			
		||||
let restartRequired = false;
 | 
			
		||||
let splashWindow, updateTimeout, newUpdater;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -210,6 +209,8 @@ const updateUntilCurrent = async () => {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only)
 | 
			
		||||
  let restartRequired;
 | 
			
		||||
 | 
			
		||||
  const add = (event, listener) => {
 | 
			
		||||
    modulesListeners[event] = listener;
 | 
			
		||||
    moduleUpdater.events.on(event, listener);
 | 
			
		||||
| 
						 | 
				
			
			@ -270,14 +271,11 @@ const initModuleUpdater = () => { // "Old" (not v2 / new, win32 only)
 | 
			
		|||
  add('installing-modules-finished', callbackCheck);
 | 
			
		||||
  add('no-pending-updates', callbackCheck);
 | 
			
		||||
 | 
			
		||||
  const progressCallback = (tracker) => ({ name, cur, total }) => tracker.record(name, '', cur, total);
 | 
			
		||||
 | 
			
		||||
  add('downloading-module-progress', ({ name, recv, total }) => {
 | 
			
		||||
    downloads.record(name, '', recv, total);
 | 
			
		||||
  });
 | 
			
		||||
  add('downloading-module-progress', progressCallback(downloads));
 | 
			
		||||
  add('installing-module-progress', progressCallback(installs));
 | 
			
		||||
 | 
			
		||||
  add('installing-module-progress', ({ name, entries, total }) => {
 | 
			
		||||
    installs.record(name, '', entries, total);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  add('update-manually', (e) => {
 | 
			
		||||
    splashState.newVersion = e.newVersion;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -195,13 +195,13 @@ const downloadModule = async (name, ver) => {
 | 
			
		|||
  const path = join(downloadPath, name + '-' + ver + '.zip');
 | 
			
		||||
  const stream = fs.createWriteStream(path);
 | 
			
		||||
 | 
			
		||||
  stream.on('progress', ([recv, total]) => {
 | 
			
		||||
    const progress = Math.min(100, Math.floor(100 * (recv / total)));
 | 
			
		||||
  stream.on('progress', ([cur, total]) => {
 | 
			
		||||
    const progress = Math.min(100, Math.floor(100 * (cur / total)));
 | 
			
		||||
 | 
			
		||||
    events.emit('downloading-module-progress', {
 | 
			
		||||
      name,
 | 
			
		||||
      progress,
 | 
			
		||||
      recv,
 | 
			
		||||
      cur,
 | 
			
		||||
      total
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
| 
						 | 
				
			
			@ -299,17 +299,17 @@ const installModule = async (name, ver, path) => {
 | 
			
		|||
 | 
			
		||||
  proc.stderr.on('data', handleErr);
 | 
			
		||||
 | 
			
		||||
  let entries = 0;
 | 
			
		||||
  let cur = 0;
 | 
			
		||||
  proc.stdout.on('data', (x) => x.toString().split('\n').forEach((x) => {
 | 
			
		||||
    if (!x.includes('inflating')) return;
 | 
			
		||||
 | 
			
		||||
    entries++;
 | 
			
		||||
    const progress = Math.min(100, Math.floor(entries / total * 100));
 | 
			
		||||
    cur++;
 | 
			
		||||
    const progress = Math.min(100, Math.floor(cur / total * 100));
 | 
			
		||||
 | 
			
		||||
    events.emit('installing-module-progress', {
 | 
			
		||||
      name,
 | 
			
		||||
      progress,
 | 
			
		||||
      entries,
 | 
			
		||||
      cur,
 | 
			
		||||
      total
 | 
			
		||||
    });
 | 
			
		||||
  }));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue