Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

vue.js - Electron + Vue tray wrong icon path

I'm trying to create a Windows applications using Electron and Vue. I want to send the application to the Tray and show an icon to maximize it again when clicked. It works fine in DEV but when I build the app, the Tray icon is not working. The app it's executing, but when minimized the tray is not showing and there is not option to open it again (need to kill the process).

This is the code I'm trying to use:

app.on("ready", async () => {
  if (isDevelopment && !process.env.IS_TEST) {
    try {
      await installExtension(VUEJS_DEVTOOLS);
    } catch (e) {
      console.error("Vue Devtools failed to install:", e.toString());
    }
  }
  createWindow();
  createTray()
});

const createTray = () => {
  const tray = new Tray(resolve(process.resourcesPath, '\resources\homeico.ico'))

  const contextMenu = Menu.buildFromTemplate([
    {
        label: 'Show App', click: function () {
            app.show()
        }
    },
    {
        label: 'Quit', click: function () {
            app.isQuiting = true
            app.quit()
        }
    }
  ])
  tray.setToolTip('This is my application.')
  tray.setContextMenu(contextMenu)

  tray.on('click', () => {
      console.log('clicked')
  })
}

And in my vue.config.js:

pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      builderOptions: {     
        "extraResources": [
          {
            "from": "extraResources",
            "to": "resources",
            "filter": [
              "**/*"
            ]
          }
        ]
      }      
    },
  },

The resolve(process.resourcesPath, ' esourceshomeico.ico') line is pointing to a existing file, I'm printing this route in the App and I can open it in my Windows Explorer, but when I want to show the Image in the app, I can see next error in the DevTools:

Not allowed to load local resource: file:///C:/Users/mysUser/AppData/Local/Programs/business-config-tool/resources/resources/homeico.ico

The path is accesible, but not in the App. What's the correct way to configure the path to the icon? there is another path I can configure for assets? I also tried with __dirname and other icon formats (ico, png..)

Thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...