From 133cf280e4f619ab8447515385227f9e29ce0fd0 Mon Sep 17 00:00:00 2001 From: Oj Date: Tue, 5 Apr 2022 13:13:55 +0100 Subject: [PATCH] [Various] Deep integrate u2QuickLoad (now forced always on win32) and appUpdater, other minor source cleanup --- src/bootstrap.js | 42 +++++++++++++++++++++++++----------- src/index.js | 19 ++++++++++++---- src/splash/index.js | 2 -- src/updater/appUpdater.js | 29 ------------------------- src/updater/moduleUpdater.js | 2 +- src/utils/u2QuickLoad.js | 8 ------- 6 files changed, 45 insertions(+), 57 deletions(-) delete mode 100644 src/updater/appUpdater.js delete mode 100644 src/utils/u2QuickLoad.js diff --git a/src/bootstrap.js b/src/bootstrap.js index 8eb2a02..7e260a8 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -14,23 +14,24 @@ global.releaseChannel = buildInfo.releaseChannel; log('BuildInfo', buildInfo); -const errorHandler = require('./errorHandler'); -errorHandler.init(); +const { fatal, handled, init: EHInit } = require('./errorHandler'); +EHInit(); -const splashScreen = require('./splash'); +const splash = require('./splash'); const updater = require('./updater/updater'); const moduleUpdater = require('./updater/moduleUpdater'); -const appUpdater = require('./updater/appUpdater'); if (!settings.get('enableHardwareAcceleration', true)) app.disableHardwareAcceleration(); +const autoStart = require('./autoStart'); + let desktopCore; const startCore = () => { desktopCore = require('./utils/requireNative')('discord_desktop_core'); desktopCore.startup({ - splashScreen, + splashScreen: splash, moduleUpdater, buildInfo, Constants, @@ -38,7 +39,7 @@ const startCore = () => { appSettings: require('./appSettings'), paths: require('./paths'), GPUSettings: require('./GPUSettings'), - autoStart: require('./autoStart'), + autoStart, crashReporterSetup: require('./crashReporterSetup'), }); @@ -50,7 +51,7 @@ const startCore = () => { let done = false; bw.webContents.on('dom-ready', () => { if (!done) { // Only run once - splashScreen.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier + splash.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier done = true; } @@ -67,14 +68,29 @@ const startCore = () => { }; const startUpdate = async () => { - const startMinimized = process.argv.includes('--start-minimized'); + const startMin = process.argv.includes('--start-minimized'); - appUpdater.update(startMinimized, () => { - if (process.env.OPENASAR_NOSTART) return; + if (updater.tryInitUpdater(buildInfo, Constants.NEW_UPDATE_ENDPOINT)) { + const inst = updater.getUpdater(); - startCore(); - }, () => { - desktopCore.setMainWindowVisible(!startMinimized); + inst.on('host-updated', () => autoStart.update(() => {})); + inst.on('unhandled-exception', fatal); + inst.on('InconsistentInstallerState', fatal); + inst.on('update-error', handled); + + require('./firstRun').do(inst); + } else { + moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo); + } + + splash.initSplash(startMin); + + splash.events.once('APP_SHOULD_LAUNCH', () => { + if (!process.env.OPENASAR_NOSTART) startCore(); + }); + + splash.events.once('APP_SHOULD_SHOW', () => { + desktopCore.setMainWindowVisible(!startMin); setTimeout(() => { // Try to update our asar const config = require('./config'); diff --git a/src/index.js b/src/index.js index 948bd49..01e8ca0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,31 @@ -const log = global.log = (area, ...args) => console.log(`[\x1B[38;2;88;101;242mOpenAsar\x1B[0m > ${area}]`, ...args); // Make log global for easy usage everywhere +const { join } = require('path'); + +global.log = (area, ...args) => console.log(`[\x1B[38;2;88;101;242mOpenAsar\x1B[0m > ${area}]`, ...args); // Make log global for easy usage everywhere global.oaVersion = 'nightly'; log('Init', 'OpenAsar', oaVersion); if (process.resourcesPath.startsWith('/usr/lib/electron')) global.systemElectron = true; // Using system electron, flag for other places -process.resourcesPath = require('path').join(__dirname, '..'); // Force resourcesPath for system electron +process.resourcesPath = join(__dirname, '..'); // Force resourcesPath for system electron -require('./paths').init(); +const paths = require('./paths'); +paths.init(); global.settings = require('./appSettings').getSettings(); global.oaConfig = settings.get('openasar', {}); + require('./cmdSwitches')(); + +// Force u2QuickLoad (pre-"minified" ish) +const M = require('module'); // Module + +const b = join(paths.getExeDir(), 'modules'); // Base dir +if (process.platform === 'win32') for (const m of require('fs').readdirSync(b)) M.globalPaths.push(join(b, m)); // For each module dir, add to globalPaths + + if (process.argv.includes('--overlay-host')) { // If overlay - require('./utils/u2QuickLoad'); // Manually load Updater v2 module paths (all modules) require('./utils/requireNative')('discord_overlay2', 'standalone_host.js'); // Start overlay } else { require('./bootstrap')(); // Start bootstrap diff --git a/src/splash/index.js b/src/splash/index.js index 2e69e55..31e9347 100644 --- a/src/splash/index.js +++ b/src/splash/index.js @@ -29,8 +29,6 @@ exports.initSplash = (startMin = false) => { if (process.env.OPENASAR_QUICKSTART || oaConfig.quickstart) setTimeout(() => { destroySplash(); - if (newUpdater != null) require('../utils/u2QuickLoad'); // Manually load module paths for faster requiring - launchMain(); setTimeout(() => { diff --git a/src/updater/appUpdater.js b/src/updater/appUpdater.js deleted file mode 100644 index e6de963..0000000 --- a/src/updater/appUpdater.js +++ /dev/null @@ -1,29 +0,0 @@ -const updater = require('./updater'); - -const buildInfo = require('../utils/buildInfo'); -const Constants = require('../Constants'); - -const { fatal, handled } = require('../errorHandler'); -const splash = require('../splash'); - - -exports.update = (startMin, done, show) => { - if (updater.tryInitUpdater(buildInfo, Constants.NEW_UPDATE_ENDPOINT)) { - const inst = updater.getUpdater(); - - inst.on('host-updated', () => require('../autoStart').update(() => {})); - inst.on('unhandled-exception', fatal); - inst.on('InconsistentInstallerState', fatal); - inst.on('update-error', handled); - - require('../firstRun').do(inst); - } else { - require('./moduleUpdater').init(Constants.UPDATE_ENDPOINT, settings, buildInfo); - } - - splash.initSplash(startMin); - splash.events.once('APP_SHOULD_LAUNCH', done); - splash.events.once('APP_SHOULD_SHOW', show); -}; - -exports.focusSplash = () => splash.focusWindow(); \ No newline at end of file diff --git a/src/updater/moduleUpdater.js b/src/updater/moduleUpdater.js index ba2ba07..354a6f3 100644 --- a/src/updater/moduleUpdater.js +++ b/src/updater/moduleUpdater.js @@ -31,7 +31,7 @@ const resetTracking = () => { installing = Object.assign({}, base); }; -exports.init = (endpoint, settings, { releaseChannel, version }) => { +exports.init = (endpoint, { releaseChannel, version }) => { skipHost = settings.get('SKIP_HOST_UPDATE'); skipModule = settings.get('SKIP_MODULE_UPDATE'); diff --git a/src/utils/u2QuickLoad.js b/src/utils/u2QuickLoad.js deleted file mode 100644 index ae08ab9..0000000 --- a/src/utils/u2QuickLoad.js +++ /dev/null @@ -1,8 +0,0 @@ -const { join } = require('path'); -const Module = require('module'); - - -const base = join(require('../paths').getExeDir(), 'modules'); -for (const dir of require('fs').readdirSync(base)) { - Module.globalPaths.push(join(base, dir)); -} \ No newline at end of file