Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron splashscreen on startup application

Tags:

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

like image 451
Arnaud Geotribu Avatar asked Aug 24 '16 14:08

Arnaud Geotribu


People also ask

What is splash screen on startup?

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.

Is splash screen the same as loading screen?

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.

Can I use Vue with electron?

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.


Video Answer


2 Answers

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();
  });
});
like image 171
Julien Avatar answered Sep 21 '22 07:09

Julien


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.

like image 20
Lee Goddard Avatar answered Sep 25 '22 07:09

Lee Goddard