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 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion 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 { exec } from "child_process";

const imgCache = new Map<number, NativeImage>();
function loadBadge(index: number) {
Expand All @@ -25,7 +26,18 @@ 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);
// 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}>}"`;
Covkie marked this conversation as resolved.
Show resolved Hide resolved
exec(badgeCountCommand)
}

if (count === 0) {
emitDBusBadge(count, false);
break;
}
emitDBusBadge(count, true);
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) => {
let cleanedTitle = title.replace(/^\(\d+\)\s*/, '');
mainWin.setTitle(cleanedTitle);
});

initWindowBoundsListeners(win);
if (!isDeckGameMode && (Settings.store.tray ?? true) && process.platform !== "darwin") initTray(win);
Expand Down