Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Uncaught Exception: TypeError: Error processing argument at index 0, conversion failure from file:///root/doc_electron/chef.ico #9795

Closed
zombieleet opened this issue Jun 19, 2017 · 5 comments

Comments

@zombieleet
Copy link
Contributor

zombieleet commented Jun 19, 2017

Electron Version: 1.7.2
Operating System: Linux 4.4.0-kali1-amd64 #1 SMP Debian 4.4.6-1kali1 (2016-03-18)

Am currently following the electron documentation, but the Tray api is not working, it spits out this error

Uncaught Exception:
TypeError: Error processing argument at index 0, conversion failure from file:///root/doc_electron/chef.ico
at App.app.on (/root/doc_electron/tray.js:6:10)
at emitTwo (events.js:111:20)
at App.emit (events.js:194:7)

This is the code

const { app, Menu, Tray } = require("electron");

let tray ;

app.on("ready", () => {
  tray = new Tray(`${__dirname}/chef.ico`);
  const contextMenu = Menu.buildFromTemplate([
    {label: "Item1", type: "radio"},
    {lable: "Item2", type:"radio"},
    {label: "Item4", type: "radio"}
  ]);
  tray.setToolTip("This is my application.");
  tray.setContextMenu(contextMenu);
});
@enlight
Copy link
Contributor

enlight commented Jun 19, 2017

You need to use a file path to specify the icon, not a URL.

@enlight enlight closed this as completed Jun 19, 2017
@zombieleet
Copy link
Contributor Author

@enlight using a file path does not make it work either

@enlight
Copy link
Contributor

enlight commented Jun 19, 2017

Can you update the snippet you posted to show how you've specified the file path?

@enlight enlight reopened this Jun 19, 2017
@MarshallOfSound
Copy link
Member

Woo hoo, my turn to close this 😆

https://github.com/electron/electron/blob/b09086c1b8a498c8d5184c6cb466dd3b1a668094/docs/api/native-image.md#supported-formats

On Windows, you can also load ICO icons from file paths.

.ico files are not supported as native images on linux. See #2277 for more information

@eveningkid
Copy link

eveningkid commented Feb 24, 2018

In case someone ends up here without finding a solution that works, here are the steps I'd recommend:

  • are you passing a NativeImage value to Tray constructor? If not:
// If not already imported
// const path = require('path');
const iconPath = path.join(__dirname, 'tray-icon.png');
const trayIcon = nativeImage.createFromPath(iconPath);
const tray = new Tray(trayIcon);
  • does your icon follow any of the NativeImage supported formats? PNG and JPEG are the only two formats supported on all platforms.
  • remember that your icon should be sized 16*16px or respects NativeImage file sizes. Otherwise, resize it before:
let trayIcon = nativeImage.createFromPath(iconPath);
trayIcon = trayIcon.resize({ width: 16, height: 16 });

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants