node.js - Electron App 打包后没有运行

标签 node.js electron electron-builder electron-packager

我尝试打包我使用 创建的简单 ElectronJS 应用程序 electron-builder Electron 封装工这导致文件无法运行。当我点击应用程序的图标时,没有任何 react ,没有错误,也没有运行。

应用程序在本地运行良好,并在启动时显示通知以及托盘图标。

如果有人想看看,这里是完整的代码:

https://github.com/ali-h2010/Electron-Huawei-Router-Unoffical-Utility

请注意,我能够打包其他示例应用程序,因此问题很可能仅出现在我的项目中。

最佳答案

请查看我的评论,了解为什么即使应用程序已正确打包,您的应用程序也无法运行。

  // This is wrong
  // win.loadFile('Views/index.html')
  // This will be aboluste path after packaging the app.
  // So the app will look from the root directory.
  // Not inside the app.

  win.loadFile(path.join(__dirname, 'Views/index.html'))

  win.on('close', function (event) {
    // event.preventDefault();
    // win.hide();
  })

  win.on('minimize', function (event) {
    event.preventDefault()
    win.hide()
  })


  let AppTray = null;

  // Same error
  // const iconPath = 'Assets/Images/BatteryIcons/UnknownBattery.png')
  // AppTray = new Tray(iconPath);
  // After packaging the app there won't be assets on root directory
  const iconPath = path.join(__dirname, 'Assets/Images/BatteryIcons')
  AppTray = new Tray(path.join(iconPath, 'UnknownBattery.png'));
  ...

我已经在你的 repo 上制作了完整的代码并制作了 PR。

关于node.js - Electron App 打包后没有运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62227299/

相关文章:

javascript - NodeJS `setTimeout` 还能等多久?

node.js - 如何在 NodeJS 中检查计算机何时空闲?

python - 在 Electron 应用程序中运行 python 脚本

javascript - 未捕获( promise )TypeError : Cannot read property 'NON_INDEXED_FIELDS' of undefined

reactjs - 语法错误: missing ) after argument list when using electron-builder

javascript - 如何使用自定义日期格式的 find() 方法从集合中检索数据

javascript - 如何在 Node.js 和浏览器之间共享代码?

即使成功触发了所有退出事件,Electron 应用程序仍挂起退出

node.js - bash 脚本作为 AWS 运行实例的用户数据的正确语法

javascript - 为 Electron 的每个平台打包不同的二进制文件