Electron 解决打包后系统托盘报错问题

今天在打包electron时碰到系统托盘无法显示问题Electron 解决打包后系统托盘报错问题_第1张图片

但在使用electron .命令测试时是没有问题的,考虑可能是图片路径问题于是把图片路径改为绝对路径,问题解决。

// 创建系统托盘
function createTray(){
    // 图片使用绝对路径,解决打包后报错问题
    tray = new Tray(path.join(__dirname,'/template/img/logo.ico'))
    const contextMenu = Menu.buildFromTemplate([
        { label: '关于msunui' ,click:()=>{

        }},
        { label: '退出', click:()=>{
            app.exit();
        }}
    ])
    tray.setToolTip('msunui使用文档');
    tray.setContextMenu(contextMenu);
}

你可能感兴趣的:(【Electron】,Electron,系统托盘,报错,打包)