From b314f62f557fc548e46b75529f4bd8da80edf6e9 Mon Sep 17 00:00:00 2001 From: Oleh Polisan Date: Sat, 27 Apr 2024 20:13:12 +0300 Subject: [PATCH] svg rework, add proposal for accent color (windows,linux), some bug fixes --- src/main/firstLaunch.ts | 1 + src/main/ipc.ts | 13 ++++++++++++- src/preload/VesktopNative.ts | 3 ++- .../components/settings/TrayColorPicker.tsx | 12 +++++++++--- src/renderer/patches/tray.ts | 10 +++++----- src/shared/IpcEvents.ts | 3 ++- static/idle.svg | 10 +++++----- static/speaking.svg | 10 +++++----- 8 files changed, 41 insertions(+), 21 deletions(-) mode change 100644 => 100755 static/idle.svg mode change 100644 => 100755 static/speaking.svg diff --git a/src/main/firstLaunch.ts b/src/main/firstLaunch.ts index d1bbceb..596c258 100644 --- a/src/main/firstLaunch.ts +++ b/src/main/firstLaunch.ts @@ -48,6 +48,7 @@ export function createFirstLaunchTour() { Settings.store.minimizeToTray = data.minimizeToTray; Settings.store.discordBranch = data.discordBranch; Settings.store.arRPC = data.richPresence; + Settings.store.tray = true; if (data.autoStart) autoStart.enable(); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index cc9d069..cd562e8 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -7,7 +7,17 @@ if (process.platform === "linux") import("./venmic"); import { execFile } from "child_process"; -import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron"; +import { + app, + BrowserWindow, + clipboard, + dialog, + nativeImage, + RelaunchOptions, + session, + shell, + systemPreferences +} from "electron"; import { mkdirSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; import { release } from "os"; @@ -156,3 +166,4 @@ watch( handle(IpcEvents.SET_TRAY_ICON, (_, iconURI) => setTrayIcon(iconURI)); handle(IpcEvents.GET_TRAY_ICON, (_, iconName) => getTrayIconFile(iconName)); +handle(IpcEvents.GET_SYSTEM_ACCENT_COLOR, () => `#${systemPreferences.getAccentColor?.() || ""}`); diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index fcf9bc4..731d602 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -26,7 +26,8 @@ export const VesktopNative = { setBadgeCount: (count: number) => invoke(IpcEvents.SET_BADGE_COUNT, count), supportsWindowsTransparency: () => sendSync(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY), setTrayIcon: (iconURI: string) => invoke(IpcEvents.SET_TRAY_ICON, iconURI), - getTrayIcon: (iconName: string) => invoke(IpcEvents.GET_TRAY_ICON, iconName) + getTrayIcon: (iconName: string) => invoke(IpcEvents.GET_TRAY_ICON, iconName), + getAccentColor: () => invoke(IpcEvents.GET_SYSTEM_ACCENT_COLOR) }, autostart: { isEnabled: () => sendSync(IpcEvents.AUTOSTART_ENABLED), diff --git a/src/renderer/components/settings/TrayColorPicker.tsx b/src/renderer/components/settings/TrayColorPicker.tsx index d88f162..5a0a606 100644 --- a/src/renderer/components/settings/TrayColorPicker.tsx +++ b/src/renderer/components/settings/TrayColorPicker.tsx @@ -9,7 +9,8 @@ import "./traySetting.css"; import { Margins } from "@vencord/types/utils"; import { findByCodeLazy } from "@vencord/types/webpack"; import { Forms } from "@vencord/types/webpack/common"; -import { setCurrentState } from "renderer/patches/tray"; +import { isInCall, setCurrentState } from "renderer/patches/tray"; +import { isLinux } from "renderer/utils"; import { SettingsComponent } from "./Settings"; @@ -20,6 +21,11 @@ const presets = [ "#F6BFAC" // Vesktop inpired ]; +if (!isLinux) + VesktopNative.app.getAccentColor().then(color => { + if (color) presets.unshift(color); + }); + export const TrayIconPicker: SettingsComponent = ({ settings }) => { if (!settings.tray) return null; return ( @@ -30,11 +36,11 @@ export const TrayIconPicker: SettingsComponent = ({ settings }) => { Choose a color for your tray icon! { const hexColor = newColor.toString(16).padStart(6, "0"); settings.trayColor = hexColor; - setCurrentState(); + if (isInCall) setCurrentState(); }} showEyeDropper={false} suggestedColors={presets} diff --git a/src/renderer/patches/tray.ts b/src/renderer/patches/tray.ts index c0be6f0..b326b58 100644 --- a/src/renderer/patches/tray.ts +++ b/src/renderer/patches/tray.ts @@ -11,7 +11,7 @@ import { FluxDispatcher, UserStore } from "@vencord/types/webpack/common"; const muteActions = findByPropsLazy("isSelfMute"); const deafActions = findByPropsLazy("isSelfDeaf"); -var inCall = false; +export var isInCall = false; const logger = new Logger("VesktopTrayIcon"); async function changeIconColor(iconName: string) { @@ -64,20 +64,20 @@ onceReady.then(() => { }); FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_DEAF", () => { - if (inCall) setCurrentState(); + if (isInCall) setCurrentState(); }); FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_MUTE", () => { - if (inCall) setCurrentState(); + if (isInCall) setCurrentState(); }); FluxDispatcher.subscribe("RTC_CONNECTION_STATE", params => { if (params.state === "RTC_CONNECTED") { - inCall = true; + isInCall = true; setCurrentState(); } else if (params.state === "RTC_DISCONNECTED") { VesktopNative.app.setTrayIcon("icon"); - inCall = false; + isInCall = false; } }); }); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index f68826a..002e0c6 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -52,5 +52,6 @@ export const enum IpcEvents { CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE", SET_TRAY_ICON = "VCD_SET_TRAY_ICON", - GET_TRAY_ICON = "VCD_GET_TRAY_ICON" + GET_TRAY_ICON = "VCD_GET_TRAY_ICON", + GET_SYSTEM_ACCENT_COLOR = "VCD_GET_ACCENT_COLOR" } diff --git a/static/idle.svg b/static/idle.svg old mode 100644 new mode 100755 index 43bbb4b..9631763 --- a/static/idle.svg +++ b/static/idle.svg @@ -1,5 +1,5 @@ - - - - - + + + + + diff --git a/static/speaking.svg b/static/speaking.svg old mode 100644 new mode 100755 index dad855d..a003616 --- a/static/speaking.svg +++ b/static/speaking.svg @@ -1,5 +1,5 @@ - - - - - + + + + +