windows 10 上的电子托盘图标问题
electron tray icon issue on windows 10
我已经构建了 Electron 应用程序,现在想使用 Tray 功能,如前所述 here
我给出的图标路径位于基本位置的构建文件夹中,如下所示
tray = new Tray(`file://${__dirname}/build/icon.ico`);
但是这是抛出以下错误
我想知道如何使用文档中未提及的图标。
看起来像是 Windows 的路径问题。我建议使用节点的 path
模块的绝对路径来正确解析绝对路径,如下所示:
const iconPath = path.join(__dirname, 'build/icon.ico');
tray = new Tray(iconPath);
this electron issue 上有几条极好的评论,为您提供了多种选择。
这对我有用。虽然图标的大小必须很小才能显示
const { Tray, nativeImage } = require('electron');
const iconPath = path.join(__dirname, 'build/icon-st.png');
mainWindow.tray = new Tray(nativeImage.createFromPath(iconPath));
虽然生成了构建,但是图标不可见。
我遇到了同样的问题,在 windows 10 托盘上看不到图标。
这是因为图标在 window 的图像查看器中不可见(damaged/corrupted 图标)。
我下载了一个彩色图标并重试,它成功了。
我已经构建了 Electron 应用程序,现在想使用 Tray 功能,如前所述 here
我给出的图标路径位于基本位置的构建文件夹中,如下所示
tray = new Tray(`file://${__dirname}/build/icon.ico`);
但是这是抛出以下错误
我想知道如何使用文档中未提及的图标。
看起来像是 Windows 的路径问题。我建议使用节点的 path
模块的绝对路径来正确解析绝对路径,如下所示:
const iconPath = path.join(__dirname, 'build/icon.ico');
tray = new Tray(iconPath);
this electron issue 上有几条极好的评论,为您提供了多种选择。
这对我有用。虽然图标的大小必须很小才能显示
const { Tray, nativeImage } = require('electron');
const iconPath = path.join(__dirname, 'build/icon-st.png');
mainWindow.tray = new Tray(nativeImage.createFromPath(iconPath));
虽然生成了构建,但是图标不可见。
我遇到了同样的问题,在 windows 10 托盘上看不到图标。
这是因为图标在 window 的图像查看器中不可见(damaged/corrupted 图标)。
我下载了一个彩色图标并重试,它成功了。