Electron-将托盘图标添加到Windows PC时发生JavaScript错误
我在尝试学习Electron并在windows计算机的托盘中显示图标时遇到此错误。有人知道是什么导致了这个错误吗 主进程中发生JavaScript错误 未捕获异常:类型错误:参数数量不足 在App.App.on (C:\Users\davidb\Desktop\ElectronCode\boilerplates\tasky\index.js:18:3)Electron-将托盘图标添加到Windows PC时发生JavaScript错误,javascript,electron,Javascript,Electron,我在尝试学习Electron并在windows计算机的托盘中显示图标时遇到此错误。有人知道是什么导致了这个错误吗 主进程中发生JavaScript错误 未捕获异常:类型错误:参数数量不足 在App.App.on (C:\Users\davidb\Desktop\ElectronCode\boilerplates\tasky\index.js:18:3) 至少两次(events.js:111:20) 在App.emit(events.js:191:7) 当您没有将任何内容传递到new Tray()
至少两次(events.js:111:20)
在App.emit(events.js:191:7)
当您没有将任何内容传递到
new Tray()
时,似乎会发生此错误,因此iconPath
可能未定义。当我单击错误上的x时,它仍然可以加载并正常工作。我不明白,哈哈
const path = require('path');
const electron = require('electron');
const { app, BrowserWindow, Tray } = electron;
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
height: 500,
width: 300,
frame: false,
resizable: false
});
mainWindow.loadURL(`file://${__dirname}/src/index.html`);
const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
const iconPath = path.join(__dirname, `./src/assets/${iconName}`);
new Tray(iconPath);
});