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

feat(linux): Emit D-Bus signal directly for dock notification badges #686

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
18 changes: 16 additions & 2 deletions src/main/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { app, NativeImage, nativeImage } from "electron";
import { join } from "path";
import { BADGE_DIR } from "shared/paths";
import { execFile } from "child_process";

const imgCache = new Map<number, NativeImage>();
function loadBadge(index: number) {
Expand All @@ -24,8 +25,21 @@ let lastIndex: null | number = -1;
export function setBadgeCount(count: number) {
switch (process.platform) {
case "linux":
if (count === -1) count = 0;
Covkie marked this conversation as resolved.
Show resolved Hide resolved
app.setBadgeCount(count);
if (typeof count !== "number") { //sanitize
throw new Error("count must be a number");
}

execFile ("gdbus", [
"emit",
"--session",
"--object-path",
"/",
"--signal",
"com.canonical.Unity.LauncherEntry.Update",
"application://vesktop.desktop",
Covkie marked this conversation as resolved.
Show resolved Hide resolved
`{\'count\': <int64 ${count === -1 ? 0 : count}>, \'count-visible\': <${count !== 0}>}`
]);

break;
case "darwin":
if (count === 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ function createMainWindow() {
});

if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
else if (Settings.store.appBadge)
mainWin.webContents.on("page-title-updated", (_, title) => {
mainWin.setTitle(title.replace(/^\(\d+\)\s*|•\s/, ""));
});

initWindowBoundsListeners(win);
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win);
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ import { Settings } from "./settings";

let GuildReadStateStore: any;
let NotificationSettingsStore: any;
let MessageRequestStore: any;

export function setBadge() {
if (Settings.store.appBadge === false) return;

try {
const mentionCount = GuildReadStateStore.getTotalMentionCount();
const pendingRequests = RelationshipStore.getPendingCount();
const messageRequests = MessageRequestStore.getMessageRequestsCount();
const hasUnread = GuildReadStateStore.hasAnyUnread();
const disableUnreadBadge = NotificationSettingsStore.getDisableUnreadBadge();

let totalCount = mentionCount + pendingRequests;
let totalCount = mentionCount + pendingRequests + messageRequests;
Covkie marked this conversation as resolved.
Show resolved Hide resolved
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;

VesktopNative.app.setBadgeCount(totalCount);
Expand All @@ -44,4 +46,5 @@ function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {

waitForAndSubscribeToStore("GuildReadStateStore", store => (GuildReadStateStore = store));
waitForAndSubscribeToStore("NotificationSettingsStore", store => (NotificationSettingsStore = store));
waitForAndSubscribeToStore("MessageRequestStore", store => (MessageRequestStore = store));
waitForAndSubscribeToStore("RelationshipStore");