Skip to content

Commit 4956f9a

Browse files
committed
Unread badge and suggestions
Applied reviewer suggestions. Unread Badge displays a `0`
1 parent dd703eb commit 4956f9a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/main/appBadge.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { app, NativeImage, nativeImage } from "electron";
88
import { join } from "path";
99
import { BADGE_DIR } from "shared/paths";
10-
import { exec } from "child_process";
10+
import { execFile } from "child_process";
1111

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

3133
function emitDBusBadge(count: number, visible: boolean) {
32-
const badgeCountCommand = `gdbus emit --session --object-path / --signal com.canonical.Unity.LauncherEntry.Update "application://vesktop.desktop" "{'count': <int64 ${count}>, 'count-visible': <${visible}>}"`;
33-
exec(badgeCountCommand)
34+
execFile ("gdbus", [
35+
"emit",
36+
"--session",
37+
"--object-path",
38+
"/",
39+
"--signal",
40+
"com.canonical.Unity.LauncherEntry.Update",
41+
"application://vesktop.desktop",
42+
`{\'count\': <int64 ${count}>, \'count-visible\': <${visible}>}`
43+
]);
3444
}
35-
3645
if (count === 0) {
3746
emitDBusBadge(count, false);
3847
break;
3948
}
49+
if (count === -1) {
50+
emitDBusBadge(0, true);
51+
break;
52+
}
4053
emitDBusBadge(count, true);
4154
break;
4255
case "darwin":

src/main/mainWindow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function createMainWindow() {
446446

447447
if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
448448
else if (Settings.store.appBadge) mainWin.webContents.on('page-title-updated', (_, title) => {
449-
let cleanedTitle = title.replace(/^\(\d+\)\s*/, '');
449+
let cleanedTitle = title.replace(/^\(\d+\)\s*|\s/, '');
450450
mainWin.setTitle(cleanedTitle);
451451
});
452452

src/renderer/appBadge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function setBadge() {
3232

3333
let toFind = 3;
3434

35-
function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {
35+
export function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {
3636
waitFor(filters.byStoreName(name), store => {
3737
cb?.(store);
3838
store.addChangeListener(setBadge);

0 commit comments

Comments
 (0)