question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System tray icon shows in development mode, but not after packaging the app. Any workaround to this?

This is how I add the icon

let tray = new Tray(
      nativeImage.createFromPath(
        path.join(__dirname, 'resources', 'icons', '24x24.png')
      )
    );

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
masonleecommented, Jul 12, 2020

I figured it out with help from the electron-builder docs and https://stackoverflow.com/a/46033483/530309

I moved my tray icon into a new folder called [my_project]/extraResources.

Then I added a electron-builder definition for “extraResources” in [my_project]/package.json. For me, that looks like:

  "build": {
    "extraResources": [
      "./extraResources/**"
    ],
   ...

Then, when referencing the tray icon by name, I use a new getAssetPath() function so that it can be found in dev mode and when packaged. Here’s that:

import path from 'path';
import { app, Tray } from 'electron';

const EXTRA_RESOURCES_PATH = app.isPackaged
  ? path.join(process.resourcesPath, 'extraResources')
  : path.join(__dirname, '../../extraResources');  // Your relative path may be different!

const getAssetPath = (resourceFilename: string): string => {
  return path.join(EXTRA_RESOURCES_PATH, resourceFilename);
};

const tray = new Tray(getAssetPath("myTrayIcon.png");

Hope this helps others who are new to Electron. Anyone know a better way? Should this be something that’s added to this boilerplate project, or did I miss how the boilerplate recommends to do this?

0reactions
patrickkreuzenortcommented, Nov 22, 2020

My problem with packaging of an embedded sqlite db with prepared data is now solved, thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is system tray in Windows? - TechTarget
An icon can be placed in the system tray when a program is installed by making an entry in the system registry or...
Read more >
How to Customize and Tweak Your System Tray Icons in ...
To further customize your notification area icons, click the “Customize” link behind the up arrow. You can also right-click your taskbar, select ...
Read more >
Customize the taskbar notification area - Microsoft Support
To change how icons and notifications appear · Press and hold or right-click any empty space on the taskbar and select Taskbar settings....
Read more >
Windows 10 - System Tray - Tutorialspoint
The System Tray is another name given to the Notification Area, which we can find in the right-side of the Windows Taskbar. The...
Read more >
The Windows 10 system tray - How to show or hide icons!
Another method for displaying the hidden icons in the system tray involves accessing the Taskbar settings. To do that, right-click or press-and- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found