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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"electron-updater": "^6.3.4"
},
"optionalDependencies": {
"@vencord/venmic": "^6.1.0"
"@vencord/venmic": "^6.1.0",
"@homebridge/dbus-native": "0.6.0"
},
"devDependencies": {
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
Expand Down
133 changes: 126 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions src/main/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import dbus from "@homebridge/dbus-native";
import { app, NativeImage, nativeImage } from "electron";
import { join } from "path";
import { BADGE_DIR } from "shared/paths";
Expand All @@ -24,8 +25,28 @@ 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") {
throw new Error("count must be a number"); // sanitize
}

const sessionBus = dbus.sessionBus();
sessionBus.connection.message({
type: dbus.messageType.signal,
serial: 1,
path: "/",
interface: "com.canonical.Unity.LauncherEntry",
member: "Update",
signature: "sa{sv}",
body: [
process.env.container === "1"
? "application://dev.vencord.Vesktop.desktop" // flatpak handling
: "application://vesktop.desktop",
[
["count", ["i", count === -1 ? 0 : count]],
["count-visible", ["b", 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
Loading