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 15 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
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a new library that adds more than 200kb of javascript just for one single dbus call is pretty bad

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#517 also uses it for accent calls.

we were shelling out before but #686 (comment)

},
"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.

26 changes: 24 additions & 2 deletions src/main/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { app, NativeImage, nativeImage } from "electron";
import { join } from "path";
import { BADGE_DIR } from "shared/paths";

import { dbus, getSessionBus } from "./utils/dbus";

const imgCache = new Map<number, NativeImage>();
function loadBadge(index: number) {
const cached = imgCache.get(index);
Expand All @@ -24,8 +26,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 = getSessionBus();
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", ["x", 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