Electron 电子:更快;“加载屏幕”;窗口
我有一个电子应用程序,我正在尽可能优化启动。我的主要文件是:Electron 电子:更快;“加载屏幕”;窗口,electron,electron-builder,Electron,Electron Builder,我有一个电子应用程序,我正在尽可能优化启动。我的主要文件是: const { app, BrowserWindow, ipcMain, dialog } = require("electron") const path = require("path") const url = require("url") let mainWindow = null let loadingScreen = null const create
const { app, BrowserWindow, ipcMain, dialog } = require("electron")
const path = require("path")
const url = require("url")
let mainWindow = null
let loadingScreen = null
const createLoadingScreen = () => {
loadingScreen = new BrowserWindow({
useContentSize: true,
width: 600,
height: 350,
frame: false,
transparent: true,
})
loadingScreen.setResizable(false)
const startURL = url.format({
pathname: path.join(__dirname, "loading.html"),
protocol: "file:",
slashes: true,
})
loadingScreen.loadURL(startURL)
loadingScreen.on("closed", () => (loadingScreen = null))
loadingScreen.webContents.on("did-finish-load", () => {
loadingScreen.show()
})
}
createMainWindow = () => {
mainWindow = new BrowserWindow({
useContentSize: true,
width: 1400,
minWidth: 1200,
height: 870,
minHeight: 870,
title: "MyApp",
webPreferences: {
nodeIntegration: true,
enableRemoteModule: false,
enableWebSQL: false,
},
show: false,
})
mainWindow.setMenu(null)
const startUrl =
process.env.ELECTRON_START_URL ||
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true,
})
mainWindow.loadURL(startUrl)
mainWindow.on("ready-to-show", () => {
/// when the content has loaded, hide the loading screen and show the main window
if (loadingScreen) {
loadingScreen.close()
}
mainWindow.show()
})
}
app.once("ready", () => {
createLoadingScreen()
createMainWindow()
})
app.on("window-all-closed", () => app.quit())
app.on("activate", () => {
if (mainWindow === null) createMainWindow()
})
应用程序启动时间如下:
App Ready: 0.057 seconds
Loading Screen Display: 2.437 seconds
Main Screen Display: 3.466 seconds
正如您所看到的,Electron在0.057秒时“准备就绪”,然而,创建我的超级简单(单图像)HTML启动页面需要将近2.5秒,然后再花一秒的时间加载主应用程序
我的愿望是找到一种方法,至少让我的启动屏幕尽快启动,这样用户至少知道应用程序正在加载-它目前只是坐在那里,提示用户再次单击图标
有没有什么技巧可以在2.5秒内创建初始页面
我正在运行以下系统:
Window 10 Pro (Build 18363)
32GB RAM
Intel Xeon W-2145 CPU @ 3.7Ghz (16 CPUs)
NVIDIA Quadro P2200
提前谢谢 你想出解决办法了吗?有点像problem@tommygun不幸的是,不是。这只是“现状”中的一种。VSCode的加载速度非常快,我花了一些时间研究他们是如何实现这一点的,但没有取得多大进展。最后,我们将Electron应用程序转换为内部Web应用程序,以简化部署。您是否提出了解决方案?有点像problem@tommygun不幸的是,不是。这只是“现状”中的一种。VSCode的加载速度非常快,我花了一些时间研究他们是如何实现这一点的,但没有取得多大进展。最后,我们最终将Electron应用程序转换为内部Web应用程序,以简化部署。