From b9e5ad3277b0e1c97392f3be7b764e2698084d59 Mon Sep 17 00:00:00 2001 From: Oleh Polisan Date: Sun, 21 Apr 2024 02:15:15 +0300 Subject: [PATCH] changes according to reviews --- src/main/mainWindow.ts | 26 ++++++++--------------- src/renderer/patches/tray.ts | 40 +++++++++++++----------------------- src/shared/paths.ts | 4 ---- 3 files changed, 23 insertions(+), 47 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 167e682..d1c8931 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -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")); } diff --git a/src/renderer/patches/tray.ts b/src/renderer/patches/tray.ts index 3288d6a..2bb8396 100644 --- a/src/renderer/patches/tray.ts +++ b/src/renderer/patches/tray.ts @@ -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"); } diff --git a/src/shared/paths.ts b/src/shared/paths.ts index 8ef1390..483250a 100644 --- a/src/shared/paths.ts +++ b/src/shared/paths.ts @@ -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");