Skip to content

Commit

Permalink
feat: change tray icon if a tunnel is active
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzi committed May 20, 2021
1 parent ed2b7bb commit 5088294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Binary file added src/assets/icons/icon_tray_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion src/main/TrayMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Menu,
MenuItem,
MenuItemConstructorOptions,
nativeImage,
Tray,
} from "electron";
import { getIconsPath } from "../utils";
Expand All @@ -23,19 +24,33 @@ export class TrayMenu {

private contextMenu: Menu;

private readonly icon: nativeImage;

private readonly iconActive: nativeImage;

constructor(private readonly window: BrowserWindow, isDevelopement: boolean) {
this.tunnels = [];
this.isQuitting = false;
this.icon = nativeImage.createFromPath(getIconsPath("icon_tray.png", isDevelopement));
this.iconActive = nativeImage.createFromPath(getIconsPath("icon_tray_active.png", isDevelopement));

this.tray = new Tray(getIconsPath("icon_tray.png", isDevelopement));
this.tray = new Tray(this.icon);
this.tray.setToolTip("Wire GUI");
this.contextMenu = Menu.buildFromTemplate(this.mountTrayMenuItems());
this.tray.setContextMenu(this.contextMenu);

ipcMain.on("WgConfigStateChange", (event, args: TunnelInfo[]) => {
this.tunnels = args;

this.contextMenu = Menu.buildFromTemplate(this.mountTrayMenuItems());
this.tray.setContextMenu(this.contextMenu);

// When calling setContextMenu alongside setImage
// For some reason electron reloads the tray image
// With this hack this doesn't happen
setTimeout(() => {
this.tray.setImage(this.tunnels.some(tunnel => tunnel.active) ? this.iconActive : this.icon);
}, 100);
});

window.on("close", (event) => {
Expand Down

0 comments on commit 5088294

Please sign in to comment.