[Splash > Backend] Rewrite showing and injection to use events instead of IPC

main
Oj 2 years ago
parent 80f9c6fc68
commit 875d8aa103

@ -106,8 +106,6 @@
const barContainer = document.querySelector('#bar-container'); const barContainer = document.querySelector('#bar-container');
const barFill = document.querySelector('#bar-fill'); const barFill = document.querySelector('#bar-fill');
DiscordSplash.signalReady();
DiscordSplash.onStateUpdate(({ status, current, total, progress, seconds }) => { DiscordSplash.onStateUpdate(({ status, current, total, progress, seconds }) => {
let statusText = status.replaceAll('-', ' '); let statusText = status.replaceAll('-', ' ');
let showProgress = false; let showProgress = false;

@ -377,6 +377,7 @@ function launchSplashWindow(startMinimized) {
resizable: false, resizable: false,
center: true, center: true,
show: false, show: false,
backgroundColor: '#2f3136',
webPreferences: { webPreferences: {
nodeIntegration: false, nodeIntegration: false,
enableRemoteModule: false, enableRemoteModule: false,
@ -399,21 +400,20 @@ function launchSplashWindow(startMinimized) {
}); });
} }
ipcMain.on('DISCORD_SPLASH_SCREEN_READY', () => { const win = splashWindow;
log('Splash', 'Window declared ready, showing and starting update process'); const wc = win.webContents;
wc.once('dom-ready', () => {
if (oaConfig.themeSync !== false) try { // Inject themesync CSS if (oaConfig.themeSync !== false) try { // Inject themesync CSS
splashWindow.webContents.insertCSS(JSON.parse(_fs.default.readFileSync(_path.default.join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS); wc.insertCSS(JSON.parse(_fs.default.readFileSync(_path.default.join(paths.getUserData(), 'userDataCache.json'), 'utf8')).openasarSplashCSS);
} catch (e) { } } catch (e) { }
if (oaConfig.splashText === true) try { if (oaConfig.splashText === true) try {
const buildInfo = require('../utils/buildInfo.js'); const buildInfo = require('../utils/buildInfo.js');
splashWindow.webContents.executeJavaScript(`debug.textContent = '${buildInfo.releaseChannel} ${buildInfo.version}\\nOpenAsar ${oaVersion}'`); wc.executeJavaScript(`debug.textContent = '${buildInfo.releaseChannel} ${buildInfo.version}\\nOpenAsar ${oaVersion}'`);
} catch (e) { } } catch (e) { }
if (splashWindow && !startMinimized) { if (!startMinimized) win.once('ready-to-show', () => win.show());
splashWindow.show();
}
}); });
const splashUrl = _url.default.format({ const splashUrl = _url.default.format({
@ -422,7 +422,7 @@ function launchSplashWindow(startMinimized) {
pathname: _path.default.join(__dirname, 'index.html') pathname: _path.default.join(__dirname, 'index.html')
}); });
splashWindow.loadURL(splashUrl); win.loadURL(splashUrl);
log('Splash', `Loading window (with url ${splashUrl})`); log('Splash', `Loading window (with url ${splashUrl})`);
} }

@ -2,6 +2,5 @@ const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('DiscordSplash', { contextBridge.exposeInMainWorld('DiscordSplash', {
signalReady: () => ipcRenderer.send('DISCORD_SPLASH_SCREEN_READY'),
onStateUpdate: callback => ipcRenderer.on('DISCORD_SPLASH_UPDATE_STATE', (_, state) => callback(state)) onStateUpdate: callback => ipcRenderer.on('DISCORD_SPLASH_UPDATE_STATE', (_, state) => callback(state))
}); });
Loading…
Cancel
Save