From d9c469755b6fe8c3c1c2004dfff7edfb9ef41f42 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 19 Jul 2024 01:20:09 +0200 Subject: [PATCH] fixes --- src/main/patcher.ts | 3 +-- src/main/updater/http.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/patcher.ts b/src/main/patcher.ts index 7b484ff5f..555ada109 100644 --- a/src/main/patcher.ts +++ b/src/main/patcher.ts @@ -22,7 +22,6 @@ import { dirname, join } from "path"; import { initIpc } from "./ipcMain"; import { RendererSettings } from "./settings"; -import { migrateLegacyToAsar } from "./updater/http"; import { IS_VANILLA } from "./utils/constants"; console.log("[Vencord] Starting up..."); @@ -31,7 +30,7 @@ console.log("[Vencord] Starting up..."); const isLegacyNonAsarVencord = IS_STANDALONE && !__dirname.endsWith(".asar"); if (isLegacyNonAsarVencord) { console.warn("This is a legacy non asar install! Migrating to asar and restarting..."); - migrateLegacyToAsar(); + require("./updater/http").migrateLegacyToAsar(); } // Our injector file at app/index.js diff --git a/src/main/updater/http.ts b/src/main/updater/http.ts index 4138c6ac8..01dd33592 100644 --- a/src/main/updater/http.ts +++ b/src/main/updater/http.ts @@ -19,7 +19,7 @@ import { IpcEvents } from "@shared/IpcEvents"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { app, dialog, ipcMain } from "electron"; -import { writeFile } from "fs/promises"; +import { writeFileSync as originalWriteFileSync } from "original-fs"; import { join } from "path"; import gitHash from "~git-hash"; @@ -76,7 +76,7 @@ async function applyUpdates() { if (!PendingUpdate) return true; const data = await get(PendingUpdate); - await writeFile(__dirname, data); + originalWriteFileSync(__dirname, data); PendingUpdate = null; @@ -90,10 +90,13 @@ ipcMain.handle(IpcEvents.BUILD, serializeErrors(applyUpdates)); export async function migrateLegacyToAsar() { try { - const data = await get(`https://github.com/${gitRemote}/releases/latest/desktop.asar`); - await writeFile(join(__dirname, "../vencord.asar"), data); - await writeFile(__filename, '// Legacy shim for new asar\n\nrequire("../vencord.asar");'); + const data = await get(`https://github.com/${gitRemote}/releases/latest/download/desktop.asar`); + + originalWriteFileSync(join(__dirname, "../vencord.asar"), data); + originalWriteFileSync(__filename, '// Legacy shim for new asar\n\nrequire("../vencord.asar");'); + app.relaunch(); + app.quit(); } catch (e) { console.error("Failed to migrate to asar", e);