From 047cc5da69fda79d21f928479e521b3f20951489 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:40:29 -0400 Subject: [PATCH] Migrate --- src/main/updater/http.ts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/updater/http.ts b/src/main/updater/http.ts index 494c53ab..6015b039 100644 --- a/src/main/updater/http.ts +++ b/src/main/updater/http.ts @@ -16,11 +16,17 @@ * along with this program. If not, see . */ +import { isLegacyNonAsarVencord } from "@main/patcher"; import { get } from "@main/utils/simpleGet"; import { IpcEvents } from "@shared/IpcEvents"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; -import { ipcMain } from "electron"; +import { app, dialog, ipcMain } from "electron"; import { writeFile } from "fs/promises"; +import { + existsSync, + unlinkSync, + writeFileSync, +} from "original-fs"; import { join } from "path"; import gitHash from "~git-hash"; @@ -87,6 +93,35 @@ async function applyUpdates() { return true; } +async function migrateAsarToLegacy() { + try { + const isFlatpak = process.platform === "linux" && !!process.env.FLATPAK_ID; + if (isFlatpak) throw "Flatpak Discord can't automatically be migrated."; + + const asarPath = join(__dirname, "../equicord.asar"); + if (existsSync(asarPath)) { + unlinkSync(asarPath); + } + + writeFileSync(__filename, "// Shim for legacy Equicord\n\nrequire(\"./index.js\");"); + + app.relaunch(); + app.exit(); + } catch (e) { + console.error("Failed to migrate to legacy", e); + + app.whenReady().then(() => { + dialog.showErrorBox( + "Migration Error", + "Failed to migrate back to the legacy version. Please reinstall using the Equicord Installer." + ); + app.exit(1); + }); + } +} + +if (!isLegacyNonAsarVencord) migrateAsarToLegacy(); + ipcMain.handle(IpcEvents.GET_REPO, serializeErrors(() => `https://github.com/${gitRemote}`)); ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges)); ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));