feat: store image in settings instead of using direct path

This commit is contained in:
MrGarlic1 2024-06-17 01:09:13 -04:00
parent 6e4f9a3d54
commit 663a2a576b
3 changed files with 7 additions and 7 deletions

View file

@ -18,6 +18,7 @@ export const PORTABLE =
const LEGACY_DATA_DIR = join(app.getPath("appData"), "VencordDesktop", "VencordDesktop"); const LEGACY_DATA_DIR = join(app.getPath("appData"), "VencordDesktop", "VencordDesktop");
export const DATA_DIR = export const DATA_DIR =
process.env.VENCORD_USER_DATA_DIR || (PORTABLE ? join(vesktopDir, "Data") : join(app.getPath("userData"))); 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 }); mkdirSync(DATA_DIR, { recursive: true });

View file

@ -8,7 +8,7 @@ if (process.platform === "linux") import("./venmic");
import { execFile } from "child_process"; 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 } from "electron";
import { mkdirSync, readFileSync, watch } from "fs"; import { copyFileSync, mkdirSync, readFileSync, watch } from "fs";
import { open, readFile } from "fs/promises"; import { open, readFile } from "fs/promises";
import { release } from "os"; import { release } from "os";
import { join } from "path"; import { join } from "path";
@ -18,7 +18,7 @@ import { debounce } from "shared/utils/debounce";
import { IpcEvents } from "../shared/IpcEvents"; 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 { TRAY_ICON_PATH, VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
import { mainWin } from "./mainWindow"; import { mainWin } from "./mainWindow";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { handle, handleSync } from "./utils/ipcWrappers"; import { handle, handleSync } from "./utils/ipcWrappers";
@ -44,10 +44,8 @@ handleSync(
handleSync(IpcEvents.GET_TRAY_ICON, () => { handleSync(IpcEvents.GET_TRAY_ICON, () => {
if (!Settings.store.trayIconPath) return nativeImage.createFromPath(ICON_PATH).toDataURL(); if (!Settings.store.trayIconPath) return nativeImage.createFromPath(ICON_PATH).toDataURL();
const img = nativeImage.createFromPath(TRAY_ICON_PATH).resize({ width: 64, height: 64 });
const img = nativeImage.createFromPath(Settings.store.trayIconPath).resize({ width: 64, height: 64 });
if (img.isEmpty()) return nativeImage.createFromPath(ICON_PATH).toDataURL(); if (img.isEmpty()) return nativeImage.createFromPath(ICON_PATH).toDataURL();
return img.toDataURL(); return img.toDataURL();
}); });
@ -137,7 +135,7 @@ handle(IpcEvents.SELECT_TRAY_ICON, async () => {
const dir = res.filePaths[0]; const dir = res.filePaths[0];
const image = nativeImage.createFromPath(dir); const image = nativeImage.createFromPath(dir);
if (image.isEmpty()) return "invalid"; if (image.isEmpty()) return "invalid";
copyFileSync(dir, TRAY_ICON_PATH);
return dir; return dir;
}); });

View file

@ -35,6 +35,7 @@ import {
MessageBoxChoice, MessageBoxChoice,
MIN_HEIGHT, MIN_HEIGHT,
MIN_WIDTH, MIN_WIDTH,
TRAY_ICON_PATH,
VENCORD_FILES_DIR VENCORD_FILES_DIR
} from "./constants"; } from "./constants";
import { Settings, State, VencordSettings } from "./settings"; import { Settings, State, VencordSettings } from "./settings";
@ -124,7 +125,7 @@ function initTray(win: BrowserWindow) {
} }
]); ]);
var trayImage = nativeImage.createFromPath(ICON_PATH); 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 (trayImage.isEmpty()) trayImage = nativeImage.createFromPath(ICON_PATH);
if (process.platform === "darwin") { if (process.platform === "darwin") {