Skip to content

Commit

Permalink
macOS: Show alternate tray icon for unread messages
Browse files Browse the repository at this point in the history
  • Loading branch information
darrinsmart committed Jul 15, 2024
1 parent 92260b0 commit 23d1f2c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions app/renderer/js/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,37 @@ let tray: ElectronTray | null = null;
const appIcon = path.join(publicPath, "resources/tray/tray");

const iconPath = (): string => {
if (process.platform === "linux") {
return appIcon + "linux.png";
}
switch (process.platform) {
case "darwin": {
return appIcon + "macOSTemplate.png";
}

case "win32": {
return appIcon + "win.ico";
}

return (
appIcon + (process.platform === "win32" ? "win.ico" : "macOSTemplate.png")
);
default: {
return appIcon + "linux.png";
}
}
};

const winUnreadTrayIconPath = (): string => appIcon + "unread.ico";
const unreadTrayIconPath = (): string => {
switch (process.platform) {
case "darwin": {
return appIcon + "macOSUnreadTemplate.png";
}

case "win32": {
return appIcon + "unread.ico";
}

default: {
// Note this isn't used - see renderNativeImage()
return appIcon + "linux.png";
}
}
};

let unread = 0;

Expand Down Expand Up @@ -118,8 +139,8 @@ const renderCanvas = function (argument: number): HTMLCanvasElement {
* @return the native image
*/
const renderNativeImage = function (argument: number): NativeImage {
if (process.platform === "win32") {
return nativeImage.createFromPath(winUnreadTrayIconPath());
if (process.platform === "win32" || process.platform === "darwin") {
return nativeImage.createFromPath(unreadTrayIconPath());
}

const canvas = renderCanvas(argument);
Expand Down Expand Up @@ -197,18 +218,15 @@ export function initializeTray(serverManagerView: ServerManagerView) {
return;
}

// We don't want to create tray from unread messages on macOS since it already has dock badges.
if (process.platform === "linux" || process.platform === "win32") {
if (argument === 0) {
unread = argument;
tray.setImage(iconPath());
tray.setToolTip("No unread messages");
} else {
unread = argument;
const image = renderNativeImage(argument);
tray.setImage(image);
tray.setToolTip(`${argument} unread messages`);
}
// Update tray icon based on unread count
unread = argument;
if (unread === 0) {
tray.setImage(iconPath());
tray.setToolTip("No unread messages");
} else {
const image = renderNativeImage(argument);
tray.setImage(image);
tray.setToolTip(`${argument} unread messages`);
}
});

Expand Down
Binary file modified public/resources/tray/traymacOSTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/resources/tray/traymacOSTemplate@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/resources/tray/traymacOSTemplate@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/resources/tray/traymacOSTemplate@4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/resources/tray/traymacOSUnreadTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/resources/tray/traymacOSUnreadTemplate@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/resources/tray/traymacOSUnreadTemplate@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 23d1f2c

Please sign in to comment.