changes according to reviews

This commit is contained in:
Oleh Polisan 2024-04-21 02:15:15 +03:00
parent 8c6d68ed60
commit b9e5ad3277
3 changed files with 23 additions and 47 deletions

View file

@ -21,7 +21,7 @@ import { isTruthy } from "shared/utils/guards";
import { once } from "shared/utils/once";
import type { SettingsStore } from "shared/utils/SettingsStore";
import { DEAFENED_ICON_PATH, ICON_PATH, IDLE_ICON_PATH, MUTED_ICON_PATH, SPEAKING_ICON_PATH } from "../shared/paths";
import { ICON_PATH, STATIC_DIR } from "../shared/paths";
import { createAboutWindow } from "./about";
import { initArRPC } from "./arrpc";
import {
@ -479,22 +479,14 @@ export async function createWindows() {
initArRPC();
}
export async function setTrayIcon(iconName) {
export async function setTrayIcon(iconName: string) {
if (!tray) return;
switch (iconName) {
case "speaking":
tray.setImage(SPEAKING_ICON_PATH);
break;
case "muted":
tray.setImage(MUTED_ICON_PATH);
break;
case "deafened":
tray.setImage(DEAFENED_ICON_PATH);
break;
case "idle":
tray.setImage(IDLE_ICON_PATH);
break;
default:
tray.setImage(ICON_PATH);
const Icons = new Set(["speaking", "muted", "deafened", "idle", "main"]);
if (!Icons.has(iconName)) {
console.warn("setTrayIcon: Invalid icon name", iconName);
iconName = "main";
}
tray.setImage(join(STATIC_DIR, iconName + ".png"));
}

View file

@ -10,6 +10,16 @@ import { FluxDispatcher, UserStore } from "@vencord/types/webpack/common";
const muteActions = findByPropsLazy("isSelfMute");
const deafActions = findByPropsLazy("isSelfDeaf");
function setCurrentState() {
if (deafActions.isSelfDeaf()) {
VesktopNative.app.setTrayIcon("deafened");
} else if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
}
onceReady.then(() => {
const userID = UserStore.getCurrentUser().id;
@ -18,44 +28,22 @@ onceReady.then(() => {
if (params.speakingFlags) {
VesktopNative.app.setTrayIcon("speaking");
} else {
if (deafActions.isSelfDeaf()) {
VesktopNative.app.setTrayIcon("deafened");
} else if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
setCurrentState();
}
}
});
FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_DEAF", () => {
if (deafActions.isSelfDeaf()) {
VesktopNative.app.setTrayIcon("deafened");
} else if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
setCurrentState();
});
FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_MUTE", () => {
if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
setCurrentState();
});
FluxDispatcher.subscribe("RTC_CONNECTION_STATE", params => {
if (params.state === "RTC_CONNECTED") {
if (deafActions.isSelfDeaf()) {
VesktopNative.app.setTrayIcon("deafened");
} else if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
setCurrentState();
} else if (params.state === "RTC_DISCONNECTED") {
VesktopNative.app.setTrayIcon("main");
}

View file

@ -10,7 +10,3 @@ export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static");
export const VIEW_DIR = /* @__PURE__ */ join(STATIC_DIR, "views");
export const BADGE_DIR = /* @__PURE__ */ join(STATIC_DIR, "badges");
export const ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "icon.png");
export const SPEAKING_ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "speaking.png");
export const MUTED_ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "muted.png");
export const DEAFENED_ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "deafened.png");
export const IDLE_ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "idle.png");