Add Notification badge

This commit is contained in:
V
2023-06-23 17:20:54 +02:00
parent dde696627e
commit 31799ccfb0
28 changed files with 125 additions and 9 deletions

43
src/renderer/appBadge.ts Normal file
View File

@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { filters, waitFor } from "@vencord/types/webpack";
import { RelationshipStore } from "@vencord/types/webpack/common";
import { Settings } from "./settings";
let GuildReadStateStore: any;
let NotificationSettingsStore: any;
export function setBadge() {
if (Settings.store.appBadge === false) return;
const mentionCount = GuildReadStateStore.getTotalMentionCount();
const pendingRequests = RelationshipStore.getPendingCount();
const hasUnread = GuildReadStateStore.hasAnyUnread();
const disableUnreadBadge = NotificationSettingsStore.getDisableUnreadBadge();
let totalCount = mentionCount + pendingRequests;
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;
VencordDesktopNative.app.setBadgeCount(totalCount);
}
let toFind = 3;
function waitForAndSubscribeToStore(name: string, cb?: (m: any) => void) {
waitFor(filters.byStoreName(name), store => {
cb?.(store);
store.addChangeListener(setBadge);
toFind--;
if (toFind === 0) setBadge();
});
}
waitForAndSubscribeToStore("GuildReadStateStore", store => (GuildReadStateStore = store));
waitForAndSubscribeToStore("NotificationSettingsStore", store => (NotificationSettingsStore = store));
waitForAndSubscribeToStore("RelationshipStore");

View File

@@ -8,6 +8,7 @@ import "./settings.css";
import { Margins } from "@vencord/types/utils";
import { Button, Forms, Select, Switch, Text, useState } from "@vencord/types/webpack/common";
import { setBadge } from "renderer/appBadge";
import { useSettings } from "renderer/settings";
export default function SettingsUi() {
@@ -72,6 +73,18 @@ export default function SettingsUi() {
Start With System
</Switch>
<Switch
value={Settings.appBadge ?? true}
onChange={v => {
Settings.appBadge = v;
if (v) setBadge();
else VencordDesktopNative.app.setBadgeCount(0);
}}
note="Show mention badge on the app icon"
>
Notification Badge
</Switch>
{switches.map(([key, text, note, def, predicate]) => (
<Switch
value={(Settings[key as any] ?? def ?? false) && predicate?.() !== false}

View File

@@ -5,6 +5,7 @@
*/
import "./fixes";
import "./appBadge";
console.log("read if cute :3");