I've been using Django a lot and now I'm playing with Electron as I would like to create a desktop app.
I wonder is there an easy way to create a splash screen (frameless window) only to display a logo for a few seconds then open a "normal" window where the main application will be rendered ?
Thanks,
Arnaud
The splash screen is an introduction page that is displayed as a program or computer is loading or booting. For example, when a Microsoft Windows computer is starting up, there is a Windows splash screen that is displayed while Windows is loading.
A splash screen, also known as a launch screen, is the first screen that a user sees when opening your app, and it stays visible while the app is loading. You can control when the splash screen disappears by using the native SplashScreen API.
If you've worked with Vue before, it's fairly simple to get started with Electron. This is possible with a Vue CLI plugin called Electron Builder, and in the coming sections, we'll learn how this plugin works by building a sample application that returns a wholesome list of trending movies from themoviedb API.
A simple splash screen for electron could be something like
let splash
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`);
// 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();
});
});
To get a frameless window, just set the frameless
option to true
when creating a new BrowserWindow
— known as the Frameless API:
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({
width: 800,
height: 600,
frame: false
});
win.show();
Just show that window before you show your 'main' application window, when the app fires the ready
event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With