启动应用程序上的电子闪屏

Arn*_*ibu 9 node.js electron

我一直在使用Django,现在我正在玩Electron,因为我想创建一个桌面应用程序.

我想知道是否有一种简单的方法来创建一个启动画面(无框窗口)只显示一个徽标几秒钟然后打开一个"正常"窗口,主窗口将在其中呈现?

谢谢,

阿尔诺

Jul*_*ien 22

一个简单的电子启动画面可能是这样的

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();
  });
});
Run Code Online (Sandbox Code Playgroud)

  • 如果确实是 amlang 的评论来自[链接的atom.io讨论](https://discuss.atom.io/t/help-creating-a-splash-screen -电子/19089/8)? (4认同)

Lee*_*Gee 11

要获得无框窗口,只需将frameless选项设置为true创建新窗口时的选项BrowserWindow- 称为无框架API:

const {BrowserWindow} = require('electron');
let win = new BrowserWindow({
    width: 800, 
    height: 600, 
    frame: false
});
win.show();
Run Code Online (Sandbox Code Playgroud)

只需在应用程序触发ready事件时显示"主"应用程序窗口之前显示该窗口.