打包后电子应用程序未运行

时间:2020-06-06 04:27:33

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

我尝试打包使用 electron-builder electron-packager 创建的简单ElectronJS应用程序,结果导致文件无法运行。当我单击该应用程序的图标时,什么也没有发生,没有错误,也没有运行。

应用在本地运行良好,并在启动时显示通知以及任务栏图标。

下面是完整的代码,如果有人想看看:

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

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

1 个答案:

答案 0 :(得分:1)

请检查我的评论,以确保即使应用程序已正确打包,您的应用程序仍无法正常工作。

  // 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'));
  ...

我已经在您的仓库中制作了完整的代码并进行了公关。