From 663a2a576b346c54d49cea151a5b2d48a146860a Mon Sep 17 00:00:00 2001 From: MrGarlic1 Date: Mon, 17 Jun 2024 01:09:13 -0400 Subject: [PATCH] feat: store image in settings instead of using direct path --- src/main/constants.ts | 1 + src/main/ipc.ts | 10 ++++------ src/main/mainWindow.ts | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index 1bce303..45a4749 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -18,6 +18,7 @@ export const PORTABLE = const LEGACY_DATA_DIR = join(app.getPath("appData"), "VencordDesktop", "VencordDesktop"); export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR || (PORTABLE ? join(vesktopDir, "Data") : join(app.getPath("userData"))); +export const TRAY_ICON_PATH = join(DATA_DIR, "settings", "tray_icon"); mkdirSync(DATA_DIR, { recursive: true }); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index ab0f778..1d2b1ce 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -8,7 +8,7 @@ if (process.platform === "linux") import("./venmic"); import { execFile } from "child_process"; import { app, BrowserWindow, clipboard, dialog, nativeImage, RelaunchOptions, session, shell } from "electron"; -import { mkdirSync, readFileSync, watch } from "fs"; +import { copyFileSync, mkdirSync, readFileSync, watch } from "fs"; import { open, readFile } from "fs/promises"; import { release } from "os"; import { join } from "path"; @@ -18,7 +18,7 @@ import { debounce } from "shared/utils/debounce"; 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 { TRAY_ICON_PATH, VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; import { mainWin } from "./mainWindow"; import { Settings } from "./settings"; import { handle, handleSync } from "./utils/ipcWrappers"; @@ -44,10 +44,8 @@ handleSync( handleSync(IpcEvents.GET_TRAY_ICON, () => { if (!Settings.store.trayIconPath) return nativeImage.createFromPath(ICON_PATH).toDataURL(); - - const img = nativeImage.createFromPath(Settings.store.trayIconPath).resize({ width: 64, height: 64 }); + const img = nativeImage.createFromPath(TRAY_ICON_PATH).resize({ width: 64, height: 64 }); if (img.isEmpty()) return nativeImage.createFromPath(ICON_PATH).toDataURL(); - return img.toDataURL(); }); @@ -137,7 +135,7 @@ handle(IpcEvents.SELECT_TRAY_ICON, async () => { const dir = res.filePaths[0]; const image = nativeImage.createFromPath(dir); if (image.isEmpty()) return "invalid"; - + copyFileSync(dir, TRAY_ICON_PATH); return dir; }); diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 8d70d85..222f39f 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -35,6 +35,7 @@ import { MessageBoxChoice, MIN_HEIGHT, MIN_WIDTH, + TRAY_ICON_PATH, VENCORD_FILES_DIR } from "./constants"; import { Settings, State, VencordSettings } from "./settings"; @@ -124,7 +125,7 @@ function initTray(win: BrowserWindow) { } ]); var trayImage = nativeImage.createFromPath(ICON_PATH); - if (Settings.store.trayIconPath) trayImage = nativeImage.createFromPath(Settings.store.trayIconPath); + if (Settings.store.trayIconPath) trayImage = nativeImage.createFromPath(TRAY_ICON_PATH); if (trayImage.isEmpty()) trayImage = nativeImage.createFromPath(ICON_PATH); if (process.platform === "darwin") {