Skip to content

Commit

Permalink
Unread badge and suggestions
Browse files Browse the repository at this point in the history
Applied reviewer suggestions.

Unread Badge displays a `0`
  • Loading branch information
Covkie committed Jun 22, 2024
1 parent dd703eb commit 4956f9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions src/main/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { app, NativeImage, nativeImage } from "electron";
import { join } from "path";
import { BADGE_DIR } from "shared/paths";
import { exec } from "child_process";
import { execFile } from "child_process";

const imgCache = new Map<number, NativeImage>();
function loadBadge(index: number) {
Expand All @@ -25,18 +25,31 @@ let lastIndex: null | number = -1;
export function setBadgeCount(count: number) {
switch (process.platform) {
case "linux":
if (count === -1) count = 0;
// app.setBadgeCount(count);
if (typeof count !== "number") { //sanitize
console.log("what the hel- *kaboom*")
break;
}

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)
execFile ("gdbus", [
"emit",
"--session",
"--object-path",
"/",
"--signal",
"com.canonical.Unity.LauncherEntry.Update",
"application://vesktop.desktop",
`{\'count\': <int64 ${count}>, \'count-visible\': <${visible}>}`
]);
}

if (count === 0) {
emitDBusBadge(count, false);
break;
}
if (count === -1) {
emitDBusBadge(0, true);
break;
}
emitDBusBadge(count, true);
break;
case "darwin":
Expand Down
2 changes: 1 addition & 1 deletion src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ 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*/, '');
let cleanedTitle = title.replace(/^\(\d+\)\s*|•\s/, '');
mainWin.setTitle(cleanedTitle);
});

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/appBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function setBadge() {

let toFind = 3;

function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {
export function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {
waitFor(filters.byStoreName(name), store => {
cb?.(store);
store.addChangeListener(setBadge);
Expand Down

0 comments on commit 4956f9a

Please sign in to comment.