Electron启动有个短暂的白屏时间,原因是渲染进程的代码还未加载完毕
有两个解决方案
第一种方案是配置一个loading.html,设置show为false,然后等窗口ready-to-show的时候关闭loading,然后加载内容
async function createWindow() {
win = new BrowserWindow({
frame: false,
show: false,
webPreferences: {
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
preload: path.join(__dirname, 'preload.js'),
nativeWindowOpen: true,
},
});
if (process.env.WEBPACK_DEV_SERVER_URL) {
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
// if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol('app');
win.loadURL('app://./index.html');
}
win.once('ready-to-show', () => {
win.show();
});
}