Skip to content

Instantly share code, notes, and snippets.

@atmoner
Created April 12, 2020 20:15
Show Gist options
  • Save atmoner/231795ffbf20ba87814aca0bed1e4ef5 to your computer and use it in GitHub Desktop.
Save atmoner/231795ffbf20ba87814aca0bed1e4ef5 to your computer and use it in GitHub Desktop.
ElectronJs splash
const {app, BrowserWindow} = require('electron')
const path = require('path')
let mainWindow
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
app.on('ready', () => {
// create main browser window
mainWindow = new BrowserWindow({
titleBarStyle: 'hidden',
width: 1920,
height: 1080,
show: false // don't show the main window
});
// create a new `splash`-Window
splash = new BrowserWindow({width: 810, height: 610, transparent: true, frame: false, alwaysOnTop: true});
splash.loadURL(`file://${__dirname}/splash.html`);
mainWindow.loadURL(`file://${__dirname}/index.html`);
// Wait 2 seconds and open main win
sleep(2000).then(() => {
// if main window is ready to show, then destroy the splash window and show up the main window
mainWindow.once('ready-to-show', () => {
splash.destroy();
mainWindow.show();
});
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
if (mainWindow === null) createWindow()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment