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

macOS: Show alternate tray icon for unread messages #1352

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
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/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.