6
electron 开发经验之谈系列-常见问题 - rxliuli blog
source link: https://blog.rxliuli.com/p/c68829779f5449d0afe0e67806dc7fc1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
突然之间 electron 就不能启动了
删除 node_modules 重新 yarn 看看?
打包之后的程序页面空白
实际上是 electron 无法正常加载页面,原因很多
- 路径问题,解压 asar 查看实际路径(
main.js
中loadUrl
的路径是否正确) - react router 仅支持 hash 模式
- 在从文件系统中读取 html 文件时不能使用
#
指定路由,参考: https://stackoverflow.com/questions/55715384s
asar 文件一般在 _win-unpacked/:/app_,参考: https://github.com/electron/asar
electron 程序命令行输出中文乱码
在运行命令前首先运行 chcp 65001
修改活动代码页编号,参考:Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)
如何不打包成压缩格式 asar
配置 electron-builder "asar": false
。
second-instance
事件监听无效
必须使用 app.requestSingleInstanceLock()
保持应用程序单例,才能正常监听到该事件。
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
console.log("second-instance");
});
}
参考: https://www.electronjs.org/docs/api/app#apprequestsingleinstancelock
安装浏览器扩展报错
提示安装失败
(node:23488) ExtensionLoadWarning: Warnings loading extension at C:\Users\rxliuli\AppData\Roaming\Electron\extensions\fmkadmapgofadopljbjfkapdkoienihi: Unrecognized manifest key 'browser_action'. Unre
cognized manifest key 'minimum_chrome_version'. Unrecognized manifest key 'update_url'. Cannot load extension with file or directory name _metadata. Filenames starting with "_" are reserved for use by
the system.
其实答案是:扩展必须在 app.ready
之后,创建 BrowserWindow 窗口之前安装。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK