[Bootstrap] Minor source cleanup, fix MainWindow not injecting after window crash
This commit is contained in:
parent
a1133cd597
commit
a74141f34f
2 changed files with 19 additions and 29 deletions
39
src/bootstrap.js
vendored
39
src/bootstrap.js
vendored
|
@ -1,4 +1,4 @@
|
||||||
const { app, BrowserWindow } = require('electron');
|
const { app } = require('electron');
|
||||||
const { readFileSync } = require('fs');
|
const { readFileSync } = require('fs');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
|
||||||
|
@ -28,6 +28,20 @@ const autoStart = require('./autoStart');
|
||||||
|
|
||||||
let desktopCore;
|
let desktopCore;
|
||||||
const startCore = () => {
|
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 = require('./utils/requireNative')('discord_desktop_core');
|
||||||
|
|
||||||
desktopCore.startup({
|
desktopCore.startup({
|
||||||
|
@ -42,29 +56,6 @@ const startCore = () => {
|
||||||
autoStart,
|
autoStart,
|
||||||
crashReporterSetup: require('./crashReporterSetup'),
|
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 () => {
|
const startUpdate = async () => {
|
||||||
|
|
|
@ -38,20 +38,19 @@ exports.initSplash = (startMin = false) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.focusWindow = () => splashWindow?.focus?.();
|
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 = () => {
|
const destroySplash = () => {
|
||||||
log('Splash', 'Destroy');
|
splashWindow?.setSkipTaskbar?.(true);
|
||||||
|
|
||||||
if (!splashWindow) return;
|
|
||||||
|
|
||||||
splashWindow.setSkipTaskbar(true);
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!splashWindow) return;
|
if (!splashWindow) return;
|
||||||
|
|
||||||
splashWindow.hide();
|
splashWindow.hide();
|
||||||
splashWindow.close();
|
splashWindow.close();
|
||||||
splashWindow = null;
|
splashWindow = null;
|
||||||
|
|
||||||
|
return true;
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue