【问题标题】:How to add a delay for splash screen in electron如何在电子中为闪屏添加延迟
【发布时间】:2021-03-15 09:00:58
【问题描述】:

我希望启动画面在屏幕上停留 3 秒,但 electron 加载应用程序的速度比这更快,所以它只停留一秒钟。

我正在使用 Angular 来制作 SPA。

这是启动画面和主窗口的电子函数

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: 800,
    height: 450,
    transparent: true,
    frame: false,
    alwaysOnTop: true,
  });
  splash.loadURL(`file://${__dirname}/splash.html`);
  mainWindow.loadURL(`file://${__dirname}/dist/MedalFrontEnd/index.html`);

  // if main window is ready to show, then destroy the splash window and show up the main window
  function showFunc() {
    mainWindow.once("ready-to-show", () => {
      splash.destroy();
      mainWindow.show();
    });
  }

  showFunc();
});

【问题讨论】:

  • 我不是一个真正的电子人,但你不能只做 setTimeout(() => {splash.destroy(); mainWindow.show();}, 3000) 吗?跨度>

标签: javascript node.js angular electron


【解决方案1】:

您可以在函数中使用setTimeout 等待3 秒。像下面这样的东西应该可以工作 -

function showFunc() {
    mainWindow.once("ready-to-show", () => {
        setTimeout(function(){      
            splash.destroy();
            mainWindow.show();
        }, 3000);
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多