如何在电子中为启动屏幕添加延迟



我希望启动屏幕在屏幕上停留3秒,但电子加载应用程序的速度要快得多,所以它只停留了一瞬间。

我正在使用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等待3秒。下面这样的东西应该可以工作-

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

最新更新