Electron App 打包后不是运行

Electron App is not running after being packaged

我尝试打包我使用 electron-builderelectron-packager 创建的一个简单的 ElectronJS 应用程序,结果生成的文件不是可运行。当我点击应用程序的图标时,没有任何反应,没有错误,也没有 运行.

应用程序在本地 运行 正常,启动时会显示通知和托盘图标。

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

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。