Add native param in setBadgeCount() and fix settings menu
This commit is contained in:
parent
3ad9d6e4a2
commit
a63a3e710f
5 changed files with 50 additions and 27 deletions
|
@ -31,13 +31,15 @@ function loadTrayIcon(index: number) {
|
||||||
|
|
||||||
let lastIndex: null | number = -1;
|
let lastIndex: null | number = -1;
|
||||||
|
|
||||||
export function setBadgeCount(count: number, tray: boolean = false) {
|
export function setBadgeCount(count: number, native: boolean = true, tray: boolean = false) {
|
||||||
const [index, description] = getBadgeIndexAndDescription(count);
|
const [index, description] = getBadgeIndexAndDescription(count);
|
||||||
|
|
||||||
if (tray) {
|
if (tray) {
|
||||||
globals.tray?.setImage(loadTrayIcon(index ?? 0));
|
globals.tray?.setImage(loadTrayIcon(index ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!native) return;
|
||||||
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "linux":
|
case "linux":
|
||||||
if (count === -1) count = 0;
|
if (count === -1) count = 0;
|
||||||
|
|
|
@ -117,7 +117,9 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
|
||||||
return dir;
|
return dir;
|
||||||
});
|
});
|
||||||
|
|
||||||
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number, tray: boolean) => setBadgeCount(count, tray));
|
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number, native: boolean, tray: boolean) =>
|
||||||
|
setBadgeCount(count, native, tray)
|
||||||
|
);
|
||||||
|
|
||||||
function readCss() {
|
function readCss() {
|
||||||
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
|
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
|
||||||
|
|
|
@ -23,7 +23,8 @@ export const VesktopNative = {
|
||||||
app: {
|
app: {
|
||||||
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
||||||
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
||||||
setBadgeCount: (count: number, tray: boolean = false) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count, tray),
|
setBadgeCount: (count: number, native: boolean = true, tray: boolean = false) =>
|
||||||
|
invoke<void>(IpcEvents.SET_BADGE_COUNT, count, native, tray),
|
||||||
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
||||||
},
|
},
|
||||||
autostart: {
|
autostart: {
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function setBadge() {
|
||||||
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;
|
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;
|
||||||
|
|
||||||
if (Settings.store.appBadge || Settings.store.trayBadge)
|
if (Settings.store.appBadge || Settings.store.trayBadge)
|
||||||
VesktopNative.app.setBadgeCount(totalCount, Settings.store.trayBadge);
|
VesktopNative.app.setBadgeCount(totalCount, Settings.store.appBadge, Settings.store.trayBadge);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,26 +28,6 @@ export default function SettingsUi() {
|
||||||
"Discord Titlebar",
|
"Discord Titlebar",
|
||||||
"Use Discord's custom title bar instead of the Windows one. Requires a full restart."
|
"Use Discord's custom title bar instead of the Windows one. Requires a full restart."
|
||||||
],
|
],
|
||||||
!isMac && ["tray", "Tray Icon", "Add a tray icon for Vesktop", true],
|
|
||||||
!isMac && [
|
|
||||||
"minimizeToTray",
|
|
||||||
"Minimize to tray",
|
|
||||||
"Hitting X will make Vesktop minimize to the tray instead of closing",
|
|
||||||
true,
|
|
||||||
() => Settings.tray ?? true
|
|
||||||
],
|
|
||||||
!isMac && [
|
|
||||||
"trayBadge",
|
|
||||||
"Tray Notification Badge",
|
|
||||||
"Show mention badge on the tray icon",
|
|
||||||
false,
|
|
||||||
() => Settings.tray ?? true,
|
|
||||||
v => {
|
|
||||||
Settings.trayBadge = v;
|
|
||||||
if (v) setBadge();
|
|
||||||
else VesktopNative.app.setBadgeCount(0, true);
|
|
||||||
}
|
|
||||||
],
|
|
||||||
["arRPC", "Rich Presence", "Enables Rich Presence via arRPC", false],
|
["arRPC", "Rich Presence", "Enables Rich Presence via arRPC", false],
|
||||||
[
|
[
|
||||||
"disableMinSize",
|
"disableMinSize",
|
||||||
|
@ -107,18 +87,56 @@ export default function SettingsUi() {
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
Settings.appBadge = v;
|
Settings.appBadge = v;
|
||||||
if (v) setBadge();
|
if (v) setBadge();
|
||||||
else VesktopNative.app.setBadgeCount(0, Settings.trayBadge);
|
else VesktopNative.app.setBadgeCount(0, true, false);
|
||||||
}}
|
}}
|
||||||
note="Show mention badge on the app (taskbar/panel) icon"
|
note="Show mention badge on the app (taskbar/panel) icon"
|
||||||
>
|
>
|
||||||
Notification Badge
|
Notification Badge
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|
||||||
{switches.map(([key, text, note, def, predicate, onChange]) => (
|
{!isMac && (
|
||||||
|
<>
|
||||||
|
<Switch
|
||||||
|
value={Settings.tray ?? true}
|
||||||
|
onChange={v => {
|
||||||
|
Settings.tray = v;
|
||||||
|
if (v && Settings.trayBadge) setBadge();
|
||||||
|
}}
|
||||||
|
note="Add a tray icon for Vesktop"
|
||||||
|
key="tray"
|
||||||
|
>
|
||||||
|
Tray Icon
|
||||||
|
</Switch>
|
||||||
|
<Switch
|
||||||
|
value={Settings.minimizeToTray ?? true}
|
||||||
|
onChange={v => (Settings.minimizeToTray = v)}
|
||||||
|
disabled={!(Settings.tray ?? true)}
|
||||||
|
note="Hitting X will make Vesktop minimize to the tray instead of closing"
|
||||||
|
key="minimizeToTray"
|
||||||
|
>
|
||||||
|
Minimize to Tray
|
||||||
|
</Switch>
|
||||||
|
<Switch
|
||||||
|
value={Settings.trayBadge ?? true}
|
||||||
|
onChange={v => {
|
||||||
|
Settings.trayBadge = v;
|
||||||
|
if (v) setBadge();
|
||||||
|
else VesktopNative.app.setBadgeCount(0, false, true);
|
||||||
|
}}
|
||||||
|
disabled={!(Settings.tray ?? true)}
|
||||||
|
note="Show mention badge on the tray icon"
|
||||||
|
key="trayBadge"
|
||||||
|
>
|
||||||
|
Tray Notification Badge
|
||||||
|
</Switch>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{switches.map(([key, text, note, def, predicate]) => (
|
||||||
<Switch
|
<Switch
|
||||||
value={(Settings[key as any] ?? def ?? false) && predicate?.() !== false}
|
value={(Settings[key as any] ?? def ?? false) && predicate?.() !== false}
|
||||||
disabled={predicate && !predicate()}
|
disabled={predicate && !predicate()}
|
||||||
onChange={onChange ?? (v => (Settings[key as any] = v))}
|
onChange={v => (Settings[key as any] = v)}
|
||||||
note={note}
|
note={note}
|
||||||
key={key}
|
key={key}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue