From 3772db9eeac82b38871031fb6c179a0fdaeffca6 Mon Sep 17 00:00:00 2001 From: MrGarlic1 <61215937+MrGarlic1@users.noreply.github.com> Date: Tue, 28 May 2024 20:03:01 -0400 Subject: [PATCH] Windows Portable: store settings in portable folder (#592) Co-authored-by: MrGarlic Co-authored-by: vee --- src/main/constants.ts | 17 ++++++++++++++--- src/updater/main.ts | 8 ++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index 1a02d5e..1bce303 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -5,11 +5,22 @@ */ import { app } from "electron"; -import { existsSync, readdirSync, renameSync, rmdirSync } from "fs"; -import { join } from "path"; +import { existsSync, mkdirSync, readdirSync, renameSync, rmdirSync } from "fs"; +import { dirname, join } from "path"; + +const vesktopDir = dirname(process.execPath); + +export const PORTABLE = + process.platform === "win32" && + !process.execPath.toLowerCase().endsWith("electron.exe") && + !existsSync(join(vesktopDir, "Uninstall Vesktop.exe")); const LEGACY_DATA_DIR = join(app.getPath("appData"), "VencordDesktop", "VencordDesktop"); -export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR || join(app.getPath("userData")); +export const DATA_DIR = + process.env.VENCORD_USER_DATA_DIR || (PORTABLE ? join(vesktopDir, "Data") : join(app.getPath("userData"))); + +mkdirSync(DATA_DIR, { recursive: true }); + // TODO: remove eventually if (existsSync(LEGACY_DATA_DIR)) { try { diff --git a/src/updater/main.ts b/src/updater/main.ts index 207687e..4c19ffd 100644 --- a/src/updater/main.ts +++ b/src/updater/main.ts @@ -5,6 +5,7 @@ */ import { app, BrowserWindow, shell } from "electron"; +import { PORTABLE } from "main/constants"; import { Settings, State } from "main/settings"; import { handle } from "main/utils/ipcWrappers"; import { makeLinksOpenExternally } from "main/utils/makeLinksOpenExternally"; @@ -23,17 +24,12 @@ let updateData: UpdateData; handle(IpcEvents.UPDATER_GET_DATA, () => updateData); handle(IpcEvents.UPDATER_DOWNLOAD, () => { - const portable = !!process.env.PORTABLE_EXECUTABLE_FILE; - const { assets } = updateData.release; const url = (() => { switch (process.platform) { case "win32": return assets.find(a => { - if (!a.name.endsWith(".exe")) return false; - - const isSetup = a.name.includes("Setup"); - return portable ? !isSetup : isSetup; + return a.name.endsWith(PORTABLE ? "win.zip" : ".exe"); })!.browser_download_url; case "darwin": return assets.find(a =>