Added tray icon voice detection

This commit is contained in:
Oleh Polisan 2024-04-18 15:12:13 +03:00 committed by Oleh Polisan
parent 9c6b5f9194
commit 05def05cc2
7 changed files with 96 additions and 4 deletions

View file

@ -18,7 +18,7 @@ import { IpcEvents } from "../shared/IpcEvents";
import { setBadgeCount } from "./appBadge"; import { setBadgeCount } from "./appBadge";
import { autoStart } from "./autoStart"; import { autoStart } from "./autoStart";
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
import { mainWin } from "./mainWindow"; import { mainWin, setTrayIcon } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { handle, handleSync } from "./utils/ipcWrappers"; import { handle, handleSync } from "./utils/ipcWrappers";
import { PopoutWindows } from "./utils/popout"; import { PopoutWindows } from "./utils/popout";
@ -153,3 +153,5 @@ watch(
mainWin?.webContents.postMessage("VencordThemeUpdate", void 0); mainWin?.webContents.postMessage("VencordThemeUpdate", void 0);
}) })
); );
handle(IpcEvents.SET_TRAY_ICON, (_, iconName: string) => setTrayIcon(iconName));

View file

@ -21,7 +21,7 @@ import { isTruthy } from "shared/utils/guards";
import { once } from "shared/utils/once"; import { once } from "shared/utils/once";
import type { SettingsStore } from "shared/utils/SettingsStore"; import type { SettingsStore } from "shared/utils/SettingsStore";
import { ICON_PATH } from "../shared/paths"; import { ICON_PATH, SPEAKING_ICON_PATH, MUTED_ICON_PATH, DEAFENED_ICON_PATH, IDLE_ICON_PATH } from "../shared/paths";
import { createAboutWindow } from "./about"; import { createAboutWindow } from "./about";
import { initArRPC } from "./arrpc"; import { initArRPC } from "./arrpc";
import { import {
@ -40,6 +40,9 @@ import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS"; import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
import { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader"; import { downloadVencordFiles, ensureVencordFiles } from "./utils/vencordLoader";
import { fluxDispatcher } from "@vencord/types/webpack/common";
import { onceReady } from "@vencord/types/webpack";
let isQuitting = false; let isQuitting = false;
let tray: Tray; let tray: Tray;
@ -478,3 +481,23 @@ export async function createWindows() {
initArRPC(); initArRPC();
} }
export async function setTrayIcon(iconName) {
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);
}
}

View file

@ -24,7 +24,8 @@ export const VesktopNative = {
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) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count), setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY) supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY),
setTrayIcon: (iconName: string) => invoke<void>(IpcEvents.SET_TRAY_ICON, iconName)
}, },
autostart: { autostart: {
isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED), isEnabled: () => sendSync<boolean>(IpcEvents.AUTOSTART_ENABLED),

View file

@ -11,3 +11,4 @@ import "./hideSwitchDevice";
import "./screenShareFixes"; import "./screenShareFixes";
import "./spellCheck"; import "./spellCheck";
import "./windowsTitleBar"; import "./windowsTitleBar";
import "./tray";

View file

@ -0,0 +1,59 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2024 Vendicated and Vencord contributors
*/
import { findByPropsLazy, findStoreLazy, onceReady } from "@vencord/types/webpack";
import { FluxDispatcher, UserStore } from "@vencord/types/webpack/common";
const logger = new Vencord.Util.Logger("VesktopTray");
const muteActions = findByPropsLazy("isSelfMute");
const deafActions = findByPropsLazy("isSelfDeaf");
onceReady.then(() => {
const userID = UserStore.getCurrentUser().id;
FluxDispatcher.subscribe("SPEAKING", params => {
if (params.userId === userID) {
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");
}
}
}
});
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");
}
});
FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_MUTE", () => {
if (muteActions.isSelfMute()) {
VesktopNative.app.setTrayIcon("muted");
} else {
VesktopNative.app.setTrayIcon("idle");
}
});
FluxDispatcher.subscribe("RTC_CONNECTION_STATE", params => {
if (params.state == "RTC_CONNECTED") {
VesktopNative.app.setTrayIcon("idle");
} else if (params.state == "RTC_DISCONNECTED") {
VesktopNative.app.setTrayIcon("main");
}
});
});

View file

@ -49,5 +49,7 @@ export const enum IpcEvents {
ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY",
CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE" CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE",
SET_TRAY_ICON = "VCD_SET_TRAY_ICON"
} }

View file

@ -10,3 +10,7 @@ export const STATIC_DIR = /* @__PURE__ */ join(__dirname, "..", "..", "static");
export const VIEW_DIR = /* @__PURE__ */ join(STATIC_DIR, "views"); export const VIEW_DIR = /* @__PURE__ */ join(STATIC_DIR, "views");
export const BADGE_DIR = /* @__PURE__ */ join(STATIC_DIR, "badges"); export const BADGE_DIR = /* @__PURE__ */ join(STATIC_DIR, "badges");
export const ICON_PATH = /* @__PURE__ */ join(STATIC_DIR, "icon.png"); 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");