[Bootstrap] Minor source cleanup, fix MainWindow not injecting after window crash

This commit is contained in:
Ducko 2022-04-06 20:49:42 +01:00
parent a1133cd597
commit a74141f34f
2 changed files with 19 additions and 29 deletions

39
src/bootstrap.js vendored
View file

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron');
const { app } = require('electron');
const { readFileSync } = require('fs');
const { join } = require('path');
@ -28,6 +28,20 @@ const autoStart = require('./autoStart');
let desktopCore;
const startCore = () => {
app.on('browser-window-created', (e, bw) => { // Main window injection
bw.webContents.on('dom-ready', () => {
splash.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier
const [ channel, hash ] = oaVersion.split('-'); // Split via -
bw.webContents.executeJavaScript(
readFileSync(join(__dirname, 'mainWindow.js'), 'utf8')
.replaceAll('<channel>', channel)
.replaceAll('<hash>', hash || 'custom')
);
});
});
desktopCore = require('./utils/requireNative')('discord_desktop_core');
desktopCore.startup({
@ -42,29 +56,6 @@ const startCore = () => {
autoStart,
crashReporterSetup: require('./crashReporterSetup'),
});
setImmediate(() => {
if (!global.mainWindowId) return;
const bw = BrowserWindow.fromId(global.mainWindowId);
let done = false;
bw.webContents.on('dom-ready', () => {
if (!done) { // Only run once
splash.pageReady(); // Override Core's pageReady with our own on dom-ready to show main window earlier
done = true;
}
const [ channel, hash ] = oaVersion.split('-'); // Split via -
bw.webContents.executeJavaScript(
readFileSync(join(__dirname, 'mainWindow.js'), 'utf8')
.replaceAll('<channel>', channel)
.replaceAll('<hash>', hash || 'custom')
);
});
});
};
const startUpdate = async () => {

View file

@ -38,20 +38,19 @@ exports.initSplash = (startMin = false) => {
};
exports.focusWindow = () => splashWindow?.focus?.();
exports.pageReady = () => destroySplash() || process.nextTick(() => events.emit('APP_SHOULD_SHOW'));
exports.pageReady = () => destroySplash() && process.nextTick(() => events.emit('APP_SHOULD_SHOW'));
const destroySplash = () => {
log('Splash', 'Destroy');
splashWindow?.setSkipTaskbar?.(true);
if (!splashWindow) return;
splashWindow.setSkipTaskbar(true);
setTimeout(() => {
if (!splashWindow) return;
splashWindow.hide();
splashWindow.close();
splashWindow = null;
return true;
}, 100);
};