Electron — 无法显示自定义图标 [英] Electron — Can't get custom icon to appear

查看:44
本文介绍了Electron — 无法显示自定义图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以两种不同方式设置我的 Electron 应用程序图标时遇到问题:

I'm having an issue setting the icon for my Electron app in two different ways:

非打包(通过终端运行应用)

我的 main.js 确实指定了一个 'icon' 值,指向图标文件,但它不适用.

My main.js does specify an 'icon' value, pointing to the icon file, but it does not apply.

打包(使用电子打包器)

我的 package.json 文件指定了 'icon' 键,指向图标文件,并且我在 build 目录中有 .icns (Mac) 文件.我使用electron-packager构建app,但是没有应用图标,而是使用了默认的electron图标.

My package.json file specifies the 'icon' key, pointing to the icon file, and I have the .icns (Mac) file in the build directory. I used electron-packager to build the app, but the icon is not applied, the default electron icon is used instead.

不知道我在这里做错了什么,一切似乎都是正确的.

Not sure what I'm doing wrong here, everything appears correct.

推荐答案

如果你的意思是dock上的图标,在MAC上应该可以使用:

If you mean the icon on the dock, on MAC can should use:

const app = electron.app;
const image = electron.nativeImage.createFromPath(
  app.getAppPath() + "/public/YOUR_APP_IMAGE_NAME"
);
app.dock.setIcon(image);

这篇关于Electron — 无法显示自定义图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆