Unread badge and suggestions
Applied reviewer suggestions. Unread Badge displays a `0`
This commit is contained in:
parent
dd703eb969
commit
dda7c7c958
2 changed files with 20 additions and 7 deletions
|
@ -7,7 +7,7 @@
|
||||||
import { app, NativeImage, nativeImage } from "electron";
|
import { app, NativeImage, nativeImage } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { BADGE_DIR } from "shared/paths";
|
import { BADGE_DIR } from "shared/paths";
|
||||||
import { exec } from "child_process";
|
import { execFile } from "child_process";
|
||||||
|
|
||||||
const imgCache = new Map<number, NativeImage>();
|
const imgCache = new Map<number, NativeImage>();
|
||||||
function loadBadge(index: number) {
|
function loadBadge(index: number) {
|
||||||
|
@ -25,18 +25,31 @@ let lastIndex: null | number = -1;
|
||||||
export function setBadgeCount(count: number) {
|
export function setBadgeCount(count: number) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "linux":
|
case "linux":
|
||||||
if (count === -1) count = 0;
|
if (typeof count !== "number") { //sanitize
|
||||||
// app.setBadgeCount(count);
|
console.log("what the hel- *kaboom*")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
function emitDBusBadge(count: number, visible: boolean) {
|
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}>}"`;
|
execFile ("gdbus", [
|
||||||
exec(badgeCountCommand)
|
"emit",
|
||||||
|
"--session",
|
||||||
|
"--object-path",
|
||||||
|
"/",
|
||||||
|
"--signal",
|
||||||
|
"com.canonical.Unity.LauncherEntry.Update",
|
||||||
|
"application://vesktop.desktop",
|
||||||
|
`{\'count\': <int64 ${count}>, \'count-visible\': <${visible}>}`
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
emitDBusBadge(count, false);
|
emitDBusBadge(count, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (count === -1) {
|
||||||
|
emitDBusBadge(0, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
emitDBusBadge(count, true);
|
emitDBusBadge(count, true);
|
||||||
break;
|
break;
|
||||||
case "darwin":
|
case "darwin":
|
||||||
|
|
|
@ -446,7 +446,7 @@ function createMainWindow() {
|
||||||
|
|
||||||
if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
|
if (Settings.store.staticTitle) win.on("page-title-updated", e => e.preventDefault());
|
||||||
else if (Settings.store.appBadge) mainWin.webContents.on('page-title-updated', (_, title) => {
|
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);
|
mainWin.setTitle(cleanedTitle);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue