【发布时间】:2019-09-19 03:33:06
【问题描述】:
当我使用npm start 运行我的代码时,main_window 的标题需要一些时间才能完全加载。这是一个演示它的 GIF:
这是我的代码:
const electron = require('electron')
const url = require('url')
const path = require('path')
const {app, BrowserWindow, Menu} = electron
let main_window
app.on('ready', function() {
main_window = new BrowserWindow({})
main_window.loadURL(url.format({
pathname: path.join(__dirname, 'main_window.html'),
protocol: 'file:',
slashes: true
}))
Menu.setApplicationMenu(null)
})
在我在main_window.html 中指定的标题加载之前,它显示了我在package.json 中指定的项目名称。我不认为这两个文件的内容是相关的,但无论如何它们都在这里:
main_window.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>7Watchlist Data Grabber</title>
</head>
<body>
<h1>Another Collection of Web Crawlers</h1>
</body>
</html>
package.json:
{
"name": "datagrabber",
"version": "1.0.0",
"description": "Another Collection of Web Crawlers",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/amirashabani/DataGrabber.git"
},
"author": "Amir A. Shabani",
"license": "MIT",
"bugs": {
"url": "https://github.com/amirashabani/DataGrabber/issues"
},
"homepage": "https://github.com/amirashabani/DataGrabber#readme",
"dependencies": {
"electron": "^5.0.0"
}
}
这是我必须接受的吗?我不认为这是正常的行为。
Edit1:将sandbox 设置为true 或使用npm start --no-proxy-resolver 运行应用程序(如@Mr. Polywhirl 所建议)似乎没有什么不同:
【问题讨论】:
标签: javascript performance user-interface npm electron