feat(linix): Emit D-Bus signal directly for dock notification badges

Closes #298, #424, #189

remove (#) title prefix when `Notification Badge` option is toggled

explode scuffed option libunity dependency (kabloomed)
This commit is contained in:
Kylie C 2024-06-20 22:20:22 -04:00
parent 456d5a61cd
commit dd703eb969
2 changed files with 17 additions and 1 deletions

View file

@ -7,6 +7,7 @@
import { app, NativeImage, nativeImage } from "electron"; import { app, NativeImage, nativeImage } from "electron";
import { join } from "path"; import { join } from "path";
import { BADGE_DIR } from "shared/paths"; import { BADGE_DIR } from "shared/paths";
import { exec } from "child_process";
const imgCache = new Map<number, NativeImage>(); const imgCache = new Map<number, NativeImage>();
function loadBadge(index: number) { function loadBadge(index: number) {
@ -25,7 +26,18 @@ export function setBadgeCount(count: number) {
switch (process.platform) { switch (process.platform) {
case "linux": case "linux":
if (count === -1) count = 0; if (count === -1) count = 0;
app.setBadgeCount(count); // app.setBadgeCount(count);
function emitDBusBadge(count: number, visible: boolean) {
const badgeCountCommand = `gdbus emit --session --object-path / --signal com.canonical.Unity.LauncherEntry.Update "application://vesktop.desktop" "{'count': <int64 ${count}>, 'count-visible': <${visible}>}"`;
exec(badgeCountCommand)
}
if (count === 0) {
emitDBusBadge(count, false);
break;
}
emitDBusBadge(count, true);
break; break;
case "darwin": case "darwin":
if (count === 0) { if (count === 0) {

View file

@ -445,6 +445,10 @@ function createMainWindow() {
}); });
if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault()); if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
else if (Settings.store.appBadge) mainWin.webContents.on('page-title-updated', (_, title) => {
let cleanedTitle = title.replace(/^\(\d+\)\s*/, '');
mainWin.setTitle(cleanedTitle);
});
initWindowBoundsListeners(win); initWindowBoundsListeners(win);
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win); if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win);