[FirstRun] Complete rewrite
This commit is contained in:
		
							parent
							
								
									6c77d1225f
								
							
						
					
					
						commit
						9484954247
					
				
					 4 changed files with 85 additions and 2 deletions
				
			
		
							
								
								
									
										2
									
								
								src/firstRun/darwin.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/firstRun/darwin.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
// Stub in normal Discord
 | 
			
		||||
exports.performFirstRunTasks = () => {};
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
// Stub for now at least
 | 
			
		||||
 | 
			
		||||
exports.update = (callback) => { callback(); };
 | 
			
		||||
exports.performFirstRunTasks = (updater) => { };
 | 
			
		||||
module.exports = require('./' + process.platform);
 | 
			
		||||
							
								
								
									
										2
									
								
								src/firstRun/linux.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								src/firstRun/linux.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
// Stub in normal Discord
 | 
			
		||||
exports.performFirstRunTasks = () => {};
 | 
			
		||||
							
								
								
									
										80
									
								
								src/firstRun/win32.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								src/firstRun/win32.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,80 @@
 | 
			
		|||
"use strict";
 | 
			
		||||
 | 
			
		||||
Object.defineProperty(exports, "__esModule", {
 | 
			
		||||
  value: true
 | 
			
		||||
});
 | 
			
		||||
exports.performFirstRunTasks = performFirstRunTasks;
 | 
			
		||||
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const path = require('path');
 | 
			
		||||
const paths = require('../paths');
 | 
			
		||||
const squirrel = require('../updater/squirrelUpdate');
 | 
			
		||||
const Constants = require('../Constants');
 | 
			
		||||
 | 
			
		||||
const appPath = path.resolve(process.execPath, '..');
 | 
			
		||||
const rootPath = path.resolve(appFolder, '..');
 | 
			
		||||
const exeFilename = path.basename(process.execPath);
 | 
			
		||||
const updateExe = path.join(rootFolder, 'Update.exe');
 | 
			
		||||
 | 
			
		||||
const iconFile = 'app.ico';
 | 
			
		||||
const copyIconToRoot = () => {
 | 
			
		||||
  const currentPath = path.join(appPath, iconFile);
 | 
			
		||||
  const newPath = path.join(rootPath, iconFile);
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    fs.copyFileSync(currentPath, newPath);
 | 
			
		||||
    return newPath;
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    log('FirstRun', 'Failed to copy icon to root', e);
 | 
			
		||||
    return currentPath;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const updateShortcuts = (updater) => {
 | 
			
		||||
  const filename = Constants.APP_NAME_FOR_HUMANS + '.lnk';
 | 
			
		||||
  const paths = [
 | 
			
		||||
    path.join(updater.getKnownFolder('desktop'), filename),
 | 
			
		||||
    path.join(updater.getKnownFolder('programs'), Constants.APP_COMPANY, filename)
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  const icon = copyIconToRoot();
 | 
			
		||||
 | 
			
		||||
  for (const path of paths) {
 | 
			
		||||
    if (!fs.existsSync(path)) continue; // Don't update already deleted paths
 | 
			
		||||
 | 
			
		||||
    updater.createShortcut({
 | 
			
		||||
      target_path: updateExe,
 | 
			
		||||
      shortcut_path: shortcutPath,
 | 
			
		||||
      arguments: `--processStart ${exeFilename}`,
 | 
			
		||||
      icon_path: icon,
 | 
			
		||||
      icon_index: 0,
 | 
			
		||||
      description: Constants.APP_DESCRIPTION,
 | 
			
		||||
      app_user_model_id: Constants.APP_ID,
 | 
			
		||||
      working_directory: appPath
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.performFirstRunTasks = (updater) => {
 | 
			
		||||
  const flagPath = path.join(paths.getUserDataVersioned(), '.first-run');
 | 
			
		||||
 | 
			
		||||
  if (fs.existsSync(flagPath)) return; // Already ran first path, skip
 | 
			
		||||
 | 
			
		||||
  let shortcutSuccess = false;
 | 
			
		||||
  try {
 | 
			
		||||
    updateShortcuts(updater);
 | 
			
		||||
    shortcutSuccess = true;
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    log('FirstRun', 'Error updating shortcuts', e);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  squirrel.installProtocol(Constants.APP_PROTOCOL, () => {
 | 
			
		||||
    if (shortcutSuccess) {
 | 
			
		||||
      try {
 | 
			
		||||
        fs.writeFileSync(firstRunCompletePath, 'true');
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
        log('FirstRun', 'Error writing .first-run', e);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue