From 02bd04e3a595f374d527468685eb7be7e6b4d82f Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 14:24:13 -0400 Subject: [PATCH 1/6] moved tray icon option from Vesktop settings to tray context menu item --- src/main/mainWindow.ts | 62 ++++++++++++++++--- src/renderer/components/settings/Settings.tsx | 3 +- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 58b580a..fc04402 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -102,6 +102,21 @@ function initTray(win: BrowserWindow) { await clearData(win); } }, + { + label: "Change Tray Icon", + async click() { + await setTrayIcon(); + /* + switch (choice) { + case "invalid": + return; + case "cancelled": + return; + } + Settings.store.trayIconPath = choice; + */ + } + }, { type: "separator" }, @@ -120,12 +135,7 @@ function initTray(win: BrowserWindow) { } } ]); - tray = new Tray(ICON_PATH); - if (Settings.store.trayIconPath) { - const trayImage = nativeImage.createFromPath(Settings.store.trayIconPath); - if (!trayImage.isEmpty()) tray.setImage(trayImage.resize({width: 32, height: 32})); - } - + tray = new Tray(getTrayIcon()); tray.setToolTip("Vesktop"); tray.setContextMenu(trayMenu); tray.on("click", onTrayClick); @@ -277,7 +287,7 @@ function getWindowBoundsOptions(): BrowserWindowConstructorOptions { options.x = x; options.y = y; } - + if (!Settings.store.disableMinSize) { options.minWidth = MIN_WIDTH; options.minHeight = MIN_HEIGHT; @@ -486,3 +496,41 @@ export async function createWindows() { initArRPC(); } + +export function getTrayIcon(): string { + if (Settings.store.trayIconPath) { + const trayImage = nativeImage.createFromPath(Settings.store.trayIconPath); + if (!trayImage.isEmpty()) return Settings.store.trayIconPath; + } + + return ICON_PATH; +} + +async function setTrayIcon(): Promise { + const userSelection = await dialog.showMessageBox(mainWin!, { + type: "question", + title: "Change/Reset tray icon", + message: "Would you like to change or reset the Vesktop tray icon?", + buttons: ["Change", "Reset"], + defaultId: 0, + cancelId: 2, + icon: getTrayIcon() + }); + if (userSelection.response == 2) return; + if (userSelection.response == 1) { + Settings.store.trayIconPath = void 0; + return; + } + const res = await dialog.showOpenDialog(mainWin!, { + properties: ["openFile"], + filters: [{ name: "Image", extensions: ["png", "jpg"] }], + defaultPath: getTrayIcon() + }); + if (!res.filePaths.length) return; + + const dir = res.filePaths[0]; + const image = nativeImage.createFromPath(dir); + if (image.isEmpty()) return; + + Settings.store.trayIconPath = dir; +} diff --git a/src/renderer/components/settings/Settings.tsx b/src/renderer/components/settings/Settings.tsx index 3127308..c162c26 100644 --- a/src/renderer/components/settings/Settings.tsx +++ b/src/renderer/components/settings/Settings.tsx @@ -127,8 +127,7 @@ const SettingsOptions: Record> defaultValue: false } ], - "Tray Icon Image": [TrayIconImagePicker], - "Vencord Location": [VencordLocationPicker], + "Tray Icon Image": [TrayIconImagePicker] }; function SettingsSections() { From a3f38ce2059e7a9c95274bbdab9d19619e2937da Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 14:25:24 -0400 Subject: [PATCH 2/6] removed deprecated references to tray icon setting --- src/main/ipc.ts | 16 +---- src/preload/VesktopNative.ts | 3 +- .../settings/TrayIconImagePicker.tsx | 62 ------------------- src/shared/IpcEvents.ts | 1 - 4 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 src/renderer/components/settings/TrayIconImagePicker.tsx diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 46afde5..8fad6b0 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -18,7 +18,7 @@ import { IpcEvents } from "../shared/IpcEvents"; import { setBadgeCount } from "./appBadge"; import { autoStart } from "./autoStart"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; -import { mainWin } from "./mainWindow"; +import { mainWin, getTrayIcon } from "./mainWindow"; import { Settings } from "./settings"; import { handle, handleSync } from "./utils/ipcWrappers"; import { PopoutWindows } from "./utils/popout"; @@ -121,20 +121,6 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => { return dir; }); -handle(IpcEvents.SELECT_TRAY_ICON, async () => { - const res = await dialog.showOpenDialog(mainWin!, { - properties: ["openFile"], - filters: [{name: "Image", extensions: ["png", "jpg"]}] - }); - if (!res.filePaths.length) return "cancelled"; - - const dir = res.filePaths[0]; - const image = nativeImage.createFromPath(dir); - if(image.isEmpty()) return "invalid"; - - return dir; -}); - handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => setBadgeCount(count)); handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) => { diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 467bfb6..184b095 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -33,8 +33,7 @@ export const VesktopNative = { }, fileManager: { showItemInFolder: (path: string) => invoke(IpcEvents.SHOW_ITEM_IN_FOLDER, path), - selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR), - selectTrayIcon: () => invoke>(IpcEvents.SELECT_TRAY_ICON) + selectVencordDir: () => invoke>(IpcEvents.SELECT_VENCORD_DIR) }, settings: { get: () => sendSync(IpcEvents.GET_SETTINGS), diff --git a/src/renderer/components/settings/TrayIconImagePicker.tsx b/src/renderer/components/settings/TrayIconImagePicker.tsx deleted file mode 100644 index 352e51e..0000000 --- a/src/renderer/components/settings/TrayIconImagePicker.tsx +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SPDX-License-Identifier: GPL-3.0 - * Vesktop, a desktop app aiming to give you a snappier Discord Experience - * Copyright (c) 2023 Vendicated and Vencord contributors - */ - -import { Button, Forms, Toasts } from "@vencord/types/webpack/common"; - -import { SettingsComponent } from "./Settings"; - -export const TrayIconImagePicker: SettingsComponent = ({ settings }) => { - return ( - <> - - Tray icon is currently {" "} - {settings.trayIconPath ? ( - { - e.preventDefault(); - VesktopNative.fileManager.showItemInFolder(settings.trayIconPath!); - }} - > - {settings.trayIconPath} - - ) : ( - "the default location" - )} - -
- - -
- - ); -}; diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 407403b..df64403 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -24,7 +24,6 @@ export const enum IpcEvents { SET_SETTINGS = "VCD_SET_SETTINGS", SELECT_VENCORD_DIR = "VCD_SELECT_VENCORD_DIR", - SELECT_TRAY_ICON = "VCD_SELECT_TRAY_ICON", UPDATER_GET_DATA = "VCD_UPDATER_GET_DATA", UPDATER_DOWNLOAD = "VCD_UPDATER_DOWNLOAD", From 0a654fec802fa8b3cf505baa38d6129bd19ac00f Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 14:27:11 -0400 Subject: [PATCH 3/6] re-add vencord location setting --- src/renderer/components/settings/Settings.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/renderer/components/settings/Settings.tsx b/src/renderer/components/settings/Settings.tsx index c162c26..d6de13c 100644 --- a/src/renderer/components/settings/Settings.tsx +++ b/src/renderer/components/settings/Settings.tsx @@ -15,7 +15,6 @@ import { AutoStartToggle } from "./AutoStartToggle"; import { DiscordBranchPicker } from "./DiscordBranchPicker"; import { NotificationBadgeToggle } from "./NotificationBadgeToggle"; import { VencordLocationPicker } from "./VencordLocationPicker"; -import { TrayIconImagePicker } from "./TrayIconImagePicker"; import { WindowsTransparencyControls } from "./WindowsTransparencyControls"; interface BooleanSetting { @@ -127,7 +126,7 @@ const SettingsOptions: Record> defaultValue: false } ], - "Tray Icon Image": [TrayIconImagePicker] + "Vencord Location": [VencordLocationPicker] }; function SettingsSections() { From 706748f5a59342d1014726b0e41c2648e49e2964 Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 14:30:36 -0400 Subject: [PATCH 4/6] cleanup --- src/main/ipc.ts | 2 +- src/main/mainWindow.ts | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 8fad6b0..e0bf131 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -18,7 +18,7 @@ import { IpcEvents } from "../shared/IpcEvents"; import { setBadgeCount } from "./appBadge"; import { autoStart } from "./autoStart"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; -import { mainWin, getTrayIcon } from "./mainWindow"; +import { mainWin } from "./mainWindow"; import { Settings } from "./settings"; import { handle, handleSync } from "./utils/ipcWrappers"; import { PopoutWindows } from "./utils/popout"; diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index fc04402..b5b74bf 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -106,15 +106,6 @@ function initTray(win: BrowserWindow) { label: "Change Tray Icon", async click() { await setTrayIcon(); - /* - switch (choice) { - case "invalid": - return; - case "cancelled": - return; - } - Settings.store.trayIconPath = choice; - */ } }, { From a85ac17bef8841a4b54bcb53c651b18b6a294a3e Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 14:52:45 -0400 Subject: [PATCH 5/6] fixed crash if a very large tray image was selected --- src/main/mainWindow.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index b5b74bf..ce625c3 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -126,7 +126,8 @@ function initTray(win: BrowserWindow) { } } ]); - tray = new Tray(getTrayIcon()); + const trayImage = nativeImage.createFromPath(getTrayIcon()).resize({ width: 32, height: 32 }); + tray = new Tray(trayImage); tray.setToolTip("Vesktop"); tray.setContextMenu(trayMenu); tray.on("click", onTrayClick); @@ -493,7 +494,6 @@ export function getTrayIcon(): string { const trayImage = nativeImage.createFromPath(Settings.store.trayIconPath); if (!trayImage.isEmpty()) return Settings.store.trayIconPath; } - return ICON_PATH; } From 73f6a321aab255c85aa6a67477035f616cfcae6e Mon Sep 17 00:00:00 2001 From: MrGarlic Date: Sun, 5 May 2024 19:07:51 -0400 Subject: [PATCH 6/6] fixed pnpm issues --- src/main/mainWindow.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index ce625c3..ddeaa1d 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -11,8 +11,8 @@ import { dialog, Menu, MenuItemConstructorOptions, - nativeTheme, nativeImage, + nativeTheme, Tray } from "electron"; import { rm } from "fs/promises"; @@ -21,6 +21,7 @@ import { IpcEvents } from "shared/IpcEvents"; import { isTruthy } from "shared/utils/guards"; import { once } from "shared/utils/once"; import type { SettingsStore } from "shared/utils/SettingsStore"; + import { ICON_PATH } from "../shared/paths"; import { createAboutWindow } from "./about"; import { initArRPC } from "./arrpc"; @@ -507,8 +508,8 @@ async function setTrayIcon(): Promise { cancelId: 2, icon: getTrayIcon() }); - if (userSelection.response == 2) return; - if (userSelection.response == 1) { + if (userSelection.response === 2) return; + if (userSelection.response === 1) { Settings.store.trayIconPath = void 0; return; }