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

ADD: Support badge on tray/dock in Linux + notification setting #95

Merged
Merged
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
105 changes: 62 additions & 43 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,15 @@ const windowState = new Store({
},
});

// Get icon image
let iconImage = nativeImage.createFromPath(
path.join(
__dirname,
"/windows/otherAssets/icon" +
(process.platform === "linux" ? ".png" : ".ico")
)
);

// Get tray icon image
let trayIconImage = nativeImage.createFromPath(
path.join(
Expand All @@ -606,6 +615,11 @@ let trayIconImage = nativeImage.createFromPath(
)
);

// Get tray notification image
let trayIconNotificationImage = nativeImage.createFromPath(
path.join(__dirname, "/windows/otherAssets/tray-notification.png")
);

// Sets the default settings
let settings = new Store({
name: "settings",
Expand Down Expand Up @@ -653,13 +667,7 @@ if (!singleInstanceLock) {
// Set main window background color
backgroundColor: "#282C34",
// Set main window icon
icon: nativeImage.createFromPath(
path.join(
__dirname,
"/windows/otherAssets/icon" +
(process.platform === "linux" ? ".png" : ".ico")
)
),
icon: iconImage,
webPreferences: {
// Enable <webview> tag for embedding WhatsApp
webviewTag: true,
Expand Down Expand Up @@ -891,45 +899,56 @@ if (!singleInstanceLock) {

ipcMain.on("message-indicator", (e, messageCount) => {
if (
messageCount > 0 &&
messageCount !== null &&
messageCount !== undefined
settings
.get("settings")
.find((setting) => setting.id === "notificationBadge").value
) {
switch (process.platform) {
case "darwin":
app.dock.setBadge("·");
break;
case "win32":
if (
settings
.get("settings")
.find((setting) => setting.id === "notificationCountInTray")
.value
) {
trayBadge.generate(messageCount).then((imgDataUrl) => {
const generatedImage = nativeImage.createFromDataURL(
imgDataUrl
);
if (trayIcon) trayIcon.setImage(generatedImage);
});
}
break;
default:
break;
}
} else {
switch (process.platform) {
case "darwin":
app.dock.setBadge("");
break;
default:
if (trayIcon) trayIcon.setImage(trayIconImage);
break;
if (
messageCount > 0 &&
messageCount !== null &&
messageCount !== undefined
) {
switch (process.platform) {
case "darwin":
app.dock.setBadge("·");
break;
case "win32":
if (
settings
.get("settings")
.find((setting) => setting.id === "notificationCountInTray")
.value
) {
trayBadge.generate(messageCount).then((imgDataUrl) => {
const generatedImage = nativeImage.createFromDataURL(
imgDataUrl
);
if (trayIcon) trayIcon.setImage(generatedImage);
});
}
break;
default:
if (trayIcon) trayIcon.setImage(trayIconNotificationImage);

mainWindow.setIcon(trayIconNotificationImage);
break;
}
} else {
switch (process.platform) {
case "darwin":
app.dock.setBadge("");
break;
default:
if (trayIcon) trayIcon.setImage(trayIconImage);

mainWindow.setIcon(iconImage);
break;
}
}
}

if (process.platform === "win32") {
mainWindow.webContents.send("message-indicator", messageCount);
if (process.platform === "win32") {
mainWindow.webContents.send("message-indicator", messageCount);
}
}
});
});
Expand Down
9 changes: 8 additions & 1 deletion src/js/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const defaultSettings = [
value: true,
name: "Custom Titlebar",
description:
"If you are having any issues with the custom titlebar, you can disable it using this setting. <b>NOTE: This setting requires you to restart the whole app for changes to apply.</b>",
"If you are having any issues with the custom titlebar, you can disable it using this setting. <b>NOTE: Requires restart of the application to apply.</b>",
id: "customTitlebar",
},
{
Expand All @@ -46,6 +46,13 @@ const defaultSettings = [
"When enabled, Altus will remember what tab was last active so when you re-open the app it will focus the tab which was last active.",
id: "rememberActiveTab",
},
{
value: true,
name: "Show Notification Badge",
description:
"When enabled, Altus will show the notification badge on the dock and tray. <b>NOTE: Requires restart of the application to apply.</b>",
id: "notificationBadge",
},
{
value: true,
name: "Show Notification Count In Tray Icon (Windows)",
Expand Down
Binary file added src/windows/otherAssets/tray-notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.