gpt4 book ai didi

electron - .png格式的带有托盘图标的Electron JS Mac OS X构建失败

转载 作者:行者123 更新时间:2023-12-03 12:42:42 31 4
gpt4 key购买 nike

对于初学者,我为“正常”(非托盘)应用程序构建的程序可以与 Electron 打包程序一起正常工作,并且此命令

npx electron-packager . --overwrite --plaorm=darwin --arch=x64 --icon=aicons/1024.icns --prune=true --out=release-builds

我最近重构了我的代码,所以现在是一个托盘应用程序

所以我有
  tray = new Tray('icons/elektro.png')
tray.setToolTip('elektro')

使用npm start可以正常工作,但是当我使用 Electron 打包程序构建.app时,出现以下错误:
Uncaught Exception:
TypeError: Error processing argument at index 0, conversion failure from icons/elektro.png
at App.<anonymous> (/Users/gurugeek/elektro/release-builds/elektro-darwin-x64/elektro.app/Contents/Resources/app/main.js:48:10)
at App.emit (events.js:205:15)

我认为问题与用于托盘图标的.png有关。如果我将其更改为.icns格式,则无法在npm start下运行。知道如何解决这个问题吗?

我正在使用 Electron 6

最佳答案

好的,问题与路径有关。看起来微不足道,但.app文件在大多数情况下只是死掉而没有任何错误。到处都没有很好地记录此问题,因此我将其留给所有发现同一问题的人员:

  const path = require('path');
var iconPath = path.join(__dirname, '/icons/elektro.png') // your png tray icon
let trayIcon = nativeImage.createFromPath(iconPath);
// if needed resize to 16x16 but mac also accepted the 24 icon
// trayIcon = trayIcon.resize({
// width: 16,
// height: 16
// });

tray = new Tray(trayIcon)

关于electron - .png格式的带有托盘图标的Electron JS Mac OS X构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58495184/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com