Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

image cannot be resolved when application is packed #3621

Open
3 tasks done
yosle opened this issue Jun 7, 2024 · 4 comments
Open
3 tasks done

image cannot be resolved when application is packed #3621

yosle opened this issue Jun 7, 2024 · 4 comments

Comments

@yosle
Copy link

yosle commented Jun 7, 2024

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.1.1

Electron version

24.0.0

Operating system

Ubuntu 22.04

Last known working Electron Forge version

No response

Expected behavior

When using electron forge webpack typescript template. The image should be packed and resolved when npm run package or npm run make

Actual behavior

I got this code for tray icon:

// some code
    const icon = nativeImage.createFromPath(
      path.resolve("./src/assets/xnauta.png")
    );
        const tray = new Tray(icon);
        // some more code
            console.log("testing the path ", path.resolve("./src/assets/xnauta.png"));

if I run npm start , the tray icon is rendered correctly. icon path path is resolved to :
/home/yosle/projects/xnauta-electron/src/assets/xnauta.png

When executing after npm run package or pn run make, tray icon is not rendered , and icon path is resolved to :
/home/yosle/projects/xnauta-electron/out/xnauta-linux-x64/resources/app/.webpack/main/assets/xnauta.png
If I navigate to this folder , the file doesn't exist.

Also tried this on Windows with similar result, tray icon is not shown, but tray menu options are displayed

Captura desde 2024-06-07 12-48-21

Steps to reproduce

run app with npm start, Tray icon is rendered correctly:
Captura desde 2024-06-07 12-45-06

run npm run package and execute the binary or run npm run make , install the deb package and execute the app:
Captura desde 2024-06-07 12-44-03

Additional information

if I run npm start , the tray icon is rendered correctly. icon path path is resolved to :
/home/yosle/projects/xnauta-electron/src/assets/xnauta.png

When executing after npm run package, tray icon is not rendered , and icon path is resolved to :
/home/yosle/projects/xnauta-electron/out/xnauta-linux-x64/resources/app/.webpack/main/assets/xnauta.png
If I navigate to this folder , the file doesn't exist.

@justgo97
Copy link

justgo97 commented Jun 7, 2024

I had similar issue with an app I been working on, Had to change the path a bit for when the app is packaged

const createTray = () => {
  const iconPath = app.isPackaged
    ? path.join(__dirname, "..", "..", "..", "pomodoro.ico")
    : path.join(__dirname, "..", "..", "src", "pomodoro.ico");

  const icon = nativeImage.createFromPath(iconPath);
@yosletpp
Copy link

yosletpp commented Jun 7, 2024

I had similar issue with an app I been working on, Had to change the path a bit for when the app is packaged

const createTray = () => {
  const iconPath = app.isPackaged
    ? path.join(__dirname, "..", "..", "..", "pomodoro.ico")
    : path.join(__dirname, "..", "..", "src", "pomodoro.ico");

  const icon = nativeImage.createFromPath(iconPath);

Thanks for answering but it's doesn't seem to work for me . There's no PNG or icons in the entire out/xnauta-linux-x64 folder at all. I tried to put the images in the src directory instead of src/assets directory. But packager seems to completely ignore them.

@justgo97
Copy link

justgo97 commented Jun 7, 2024

I had similar issue with an app I been working on, Had to change the path a bit for when the app is packaged

const createTray = () => {
  const iconPath = app.isPackaged
    ? path.join(__dirname, "..", "..", "..", "pomodoro.ico")
    : path.join(__dirname, "..", "..", "src", "pomodoro.ico");

  const icon = nativeImage.createFromPath(iconPath);

Thanks for answering but it's doesn't seem to work for me . There's no PNG or icons in the entire out/xnauta-linux-x64 folder at all. I tried to put the images in the src directory instead of src/assets directory. But packager seems to completely ignore them.

Oh I see, I had that kind of issue too, If I remember correctly I solved it by adding the file to extraResource field in packagerConfig in forge.config.ts file

const config: ForgeConfig = {
  packagerConfig: {
    executableName: "pomodoro",
    icon: "./src/pomodoro.ico",
    asar: false,
    extraResource: ["./src/pomodoro.ico"],
  },
@yosletpp
Copy link

yosletpp commented Jun 8, 2024

Thanks, like you said, add to extraResources. Worked like a charm. Funny thing is I couldn't find any of this in the official docs. I would guess it should be some kind of tip in the tray notification section. Left a star in your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants