From 116c3e3e0ea6793cf35dd0c2cf95def1c30e72ab Mon Sep 17 00:00:00 2001 From: Oj Date: Wed, 6 Apr 2022 22:45:43 +0100 Subject: [PATCH] [Splash > Backend] Minor source cleanup --- src/bootstrap.js | 4 ++-- src/splash/index.js | 37 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/bootstrap.js b/src/bootstrap.js index c236262..588e5e9 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -74,8 +74,6 @@ const startUpdate = async () => { moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo); } - splash.initSplash(startMin); - splash.events.once('APP_SHOULD_LAUNCH', () => { if (!process.env.OPENASAR_NOSTART) startCore(); }); @@ -100,6 +98,8 @@ const startUpdate = async () => { } }, 3000); }); + + splash.initSplash(startMin); }; diff --git a/src/splash/index.js b/src/splash/index.js index f32307f..54df5e3 100644 --- a/src/splash/index.js +++ b/src/splash/index.js @@ -8,14 +8,12 @@ const updater = require("../updater/updater"); let splashState = {}; let modulesListeners = {}; -let launchedMainWindow = false; let updateAttempt = 0; -let splashWindow, newUpdater; +let win, newUpdater, done; exports.initSplash = (startMin = false) => { newUpdater = updater.getUpdater(); - if (newUpdater == null) initModuleUpdater(); launchSplash(startMin); @@ -30,48 +28,48 @@ exports.initSplash = (startMin = false) => { destroySplash(); launchMain(); - + setTimeout(() => { events.emit('APP_SHOULD_SHOW'); }, 100); }, 300); }; -exports.focusWindow = () => splashWindow?.focus?.(); -exports.pageReady = () => destroySplash() || process.nextTick(() => events.emit('APP_SHOULD_SHOW')); +exports.focusWindow = () => win?.focus?.(); const destroySplash = () => { - splashWindow?.setSkipTaskbar?.(true); + win?.setSkipTaskbar?.(true); setTimeout(() => { - if (!splashWindow) return; + if (!win) return; - splashWindow.hide(); - splashWindow.close(); - splashWindow = null; + win.hide(); + win.close(); + win = null; }, 100); }; +exports.pageReady = () => destroySplash() || process.nextTick(() => events.emit('APP_SHOULD_SHOW')); + + const launchMain = () => { for (const e in modulesListeners) moduleUpdater.events.removeListener(e, modulesListeners[e]); // Remove updater v1 listeners - if (!launchedMainWindow && splashWindow != null) { - sendState('starting'); + done = true; - launchedMainWindow = true; - events.emit('APP_SHOULD_LAUNCH'); - } + sendState('starting'); + events.emit('APP_SHOULD_LAUNCH'); }; const sendState = (status) => { try { - splashWindow.webContents.send('state', { status, ...splashState }); + win.webContents.send('state', { status, ...splashState }); } catch (_e) {} }; const launchSplash = (startMin) => { - splashWindow = new BrowserWindow({ + win = new BrowserWindow({ width: 300, height: process.platform === 'darwin' ? 300 : 350, frame: false, @@ -84,10 +82,9 @@ const launchSplash = (startMin) => { } }); - const win = splashWindow; const wc = win.webContents; - if (process.platform !== 'darwin') win.on('closed', () => !launchedMainWindow && app.quit()); + if (process.platform !== 'darwin') win.on('closed', () => !done && app.quit()); wc.once('dom-ready', () => { if (oaConfig.themeSync !== false) wc.insertCSS(JSON.parse(fs.readFileSync(join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS);