[Splash > Backend] Minor source cleanup

This commit is contained in:
Ducko 2022-04-06 22:45:43 +01:00
parent 001ca8b49f
commit 116c3e3e0e
2 changed files with 19 additions and 22 deletions

4
src/bootstrap.js vendored
View File

@ -74,8 +74,6 @@ const startUpdate = async () => {
moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo); moduleUpdater.init(Constants.UPDATE_ENDPOINT, buildInfo);
} }
splash.initSplash(startMin);
splash.events.once('APP_SHOULD_LAUNCH', () => { splash.events.once('APP_SHOULD_LAUNCH', () => {
if (!process.env.OPENASAR_NOSTART) startCore(); if (!process.env.OPENASAR_NOSTART) startCore();
}); });
@ -100,6 +98,8 @@ const startUpdate = async () => {
} }
}, 3000); }, 3000);
}); });
splash.initSplash(startMin);
}; };

View File

@ -8,14 +8,12 @@ const updater = require("../updater/updater");
let splashState = {}; let splashState = {};
let modulesListeners = {}; let modulesListeners = {};
let launchedMainWindow = false;
let updateAttempt = 0; let updateAttempt = 0;
let splashWindow, newUpdater; let win, newUpdater, done;
exports.initSplash = (startMin = false) => { exports.initSplash = (startMin = false) => {
newUpdater = updater.getUpdater(); newUpdater = updater.getUpdater();
if (newUpdater == null) initModuleUpdater(); if (newUpdater == null) initModuleUpdater();
launchSplash(startMin); launchSplash(startMin);
@ -30,48 +28,48 @@ exports.initSplash = (startMin = false) => {
destroySplash(); destroySplash();
launchMain(); launchMain();
setTimeout(() => { setTimeout(() => {
events.emit('APP_SHOULD_SHOW'); events.emit('APP_SHOULD_SHOW');
}, 100); }, 100);
}, 300); }, 300);
}; };
exports.focusWindow = () => splashWindow?.focus?.(); exports.focusWindow = () => win?.focus?.();
exports.pageReady = () => destroySplash() || process.nextTick(() => events.emit('APP_SHOULD_SHOW'));
const destroySplash = () => { const destroySplash = () => {
splashWindow?.setSkipTaskbar?.(true); win?.setSkipTaskbar?.(true);
setTimeout(() => { setTimeout(() => {
if (!splashWindow) return; if (!win) return;
splashWindow.hide(); win.hide();
splashWindow.close(); win.close();
splashWindow = null; win = null;
}, 100); }, 100);
}; };
exports.pageReady = () => destroySplash() || process.nextTick(() => events.emit('APP_SHOULD_SHOW'));
const launchMain = () => { const launchMain = () => {
for (const e in modulesListeners) moduleUpdater.events.removeListener(e, modulesListeners[e]); // Remove updater v1 listeners for (const e in modulesListeners) moduleUpdater.events.removeListener(e, modulesListeners[e]); // Remove updater v1 listeners
if (!launchedMainWindow && splashWindow != null) { done = true;
sendState('starting');
launchedMainWindow = true; sendState('starting');
events.emit('APP_SHOULD_LAUNCH'); events.emit('APP_SHOULD_LAUNCH');
}
}; };
const sendState = (status) => { const sendState = (status) => {
try { try {
splashWindow.webContents.send('state', { status, ...splashState }); win.webContents.send('state', { status, ...splashState });
} catch (_e) {} } catch (_e) {}
}; };
const launchSplash = (startMin) => { const launchSplash = (startMin) => {
splashWindow = new BrowserWindow({ win = new BrowserWindow({
width: 300, width: 300,
height: process.platform === 'darwin' ? 300 : 350, height: process.platform === 'darwin' ? 300 : 350,
frame: false, frame: false,
@ -84,10 +82,9 @@ const launchSplash = (startMin) => {
} }
}); });
const win = splashWindow;
const wc = win.webContents; 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', () => { wc.once('dom-ready', () => {
if (oaConfig.themeSync !== false) wc.insertCSS(JSON.parse(fs.readFileSync(join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); if (oaConfig.themeSync !== false) wc.insertCSS(JSON.parse(fs.readFileSync(join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS);