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

问题描述 投票:1回答:1

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

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

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

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

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

node.js electron electron-builder electron-packager
1个回答
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'));
  ...

我已经在您的存储库中编写了完整的代码并进行了PR。

© www.soinside.com 2019 - 2024. All rights reserved.