在Windows 10电子托盘图标问题

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

我已经建立了电子程序,现在想用托盘功能提到here

我给它位于在基座位置build文件夹,如下所示图标路径

tray = new Tray(`file://${__dirname}/build/icon.ico`);

但是,这是抛出以下错误enter image description here

我想知道如何使用图标作为其文件中没有提到。

javascript windows-10 electron system-tray
3个回答
4
投票

这个工作对我来说。虽然图标的尺寸必须小到可以显示

const { Tray, nativeImage } = require('electron');

const iconPath = path.join(__dirname, 'build/icon-st.png');
mainWindow.tray = new Tray(nativeImage.createFromPath(iconPath));

0
投票

看起来与Windows的路径问题。我会建议使用节点的path模块正确地解析绝对路径,像这样使用绝对路径:

const iconPath = path.join(__dirname, 'build/icon.ico');
tray = new Tray(iconPath);

有迹象表明,给你不同的选项上this electron issue几个很好的意见。


0
投票

虽然产生的身材,但是图标是不可见的。

我有同样的问题,一个图标是不是10托盘上的窗口可见。

它的发生是因为图标是不是不能在Windows图像查看器可见(损坏/损坏的图标)。

我下载了一个彩色图标和重试和它的工作。

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