diff --git a/scripts/build/common.mts b/scripts/build/common.mts index 5f1f3c5ef..c2321fcfd 100644 --- a/scripts/build/common.mts +++ b/scripts/build/common.mts @@ -262,20 +262,6 @@ export const stylePlugin: Plugin = { } }; -let buildsFinished = Promise.resolve(); -const buildsFinishedPlugin: Plugin = { - name: "builds-finished-plugin", - setup({ onEnd }) { - if (!watch) return; - - let resolve: () => void; - const done = new Promise(r => resolve = r); - buildsFinished = buildsFinished.then(() => done); - - onEnd(() => resolve()); - }, -}; - export const commonOpts = { logLevel: "info", bundle: true, @@ -283,7 +269,7 @@ export const commonOpts = { sourcemap: watch ? "inline" : "external", legalComments: "linked", banner, - plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin, buildsFinishedPlugin], + plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin], external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"], inject: ["./scripts/build/inject/react.mjs"], jsxFactory: "VencordCreateElement", @@ -301,8 +287,6 @@ export async function buildOrWatchAll() { if (watch) { const contexts = await Promise.all(builds.map(context)); await Promise.all(contexts.map(ctx => ctx.watch())); - - await buildsFinished; } else { try { await Promise.all(builds.map(build)); diff --git a/src/main/patcher.ts b/src/main/patcher.ts index 3e753c4da..aa346c5c1 100644 --- a/src/main/patcher.ts +++ b/src/main/patcher.ts @@ -27,7 +27,11 @@ import { IS_VANILLA } from "./utils/constants"; console.log("[Equicord] Starting up..."); // FIXME: remove at some point -export const isLegacyNonAsarVencord = IS_STANDALONE && !__dirname.endsWith(".asar"); +const isLegacyNonAsarVencord = IS_STANDALONE && !__dirname.endsWith(".asar"); +if (isLegacyNonAsarVencord) { + console.warn("This is a legacy non asar install! Migrating to asar and restarting..."); + require("./updater/http").migrateLegacyToAsar(); +} // Our injector file at app/index.js const injectorPath = require.main!.filename; diff --git a/src/main/updater/http.ts b/src/main/updater/http.ts index 30c997a98..2afc6d940 100644 --- a/src/main/updater/http.ts +++ b/src/main/updater/http.ts @@ -16,16 +16,10 @@ * along with this program. If not, see . */ -import { isLegacyNonAsarVencord } from "@main/patcher"; import { IpcEvents } from "@shared/IpcEvents"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { app, dialog, ipcMain } from "electron"; -import { - chmodSync as originalChmodSync, - existsSync as originalExistsSync, - renameSync as originalRenameSync, - writeFileSync as originalWriteFileSync, -} from "original-fs"; +import { writeFileSync as originalWriteFileSync } from "original-fs"; import { join } from "path"; import gitHash from "~git-hash"; @@ -37,8 +31,6 @@ import { ASAR_FILE, serializeErrors } from "./common"; const API_BASE = `https://api.github.com/repos/${gitRemote}`; let PendingUpdate: string | null = null; -let hasUpdateToApplyOnQuit = false; - async function githubGet(endpoint: string) { return get(API_BASE + endpoint, { headers: { @@ -84,9 +76,7 @@ async function applyUpdates() { if (!PendingUpdate) return true; const data = await get(PendingUpdate); - originalWriteFileSync(__dirname + ".new", data); - originalChmodSync(__dirname + ".new", "777"); - hasUpdateToApplyOnQuit = true; + originalWriteFileSync(__dirname, data); PendingUpdate = null; @@ -98,7 +88,7 @@ ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges)); ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates)); ipcMain.handle(IpcEvents.BUILD, serializeErrors(applyUpdates)); -async function migrateLegacyToAsar() { +export async function migrateLegacyToAsar() { try { const isFlatpak = process.platform === "linux" && !!process.env.FLATPAK_ID; if (isFlatpak) throw "Flatpak Discord can't automatically be migrated."; @@ -122,29 +112,3 @@ async function migrateLegacyToAsar() { }); } } - -function applyPreviousUpdate() { - originalChmodSync(__dirname + ".new", "777"); - originalRenameSync(__dirname + ".new", __dirname); - - app.relaunch(); - app.exit(); -} - - -app.on("will-quit", () => { - if (hasUpdateToApplyOnQuit) { - originalChmodSync(__dirname + ".new", "777"); - originalRenameSync(__dirname + ".new", __dirname); - } -}); - -if (isLegacyNonAsarVencord) { - console.warn("This is a legacy non asar install! Migrating to asar and restarting..."); - migrateLegacyToAsar(); -} - -if (originalExistsSync(__dirname + ".new")) { - console.warn("Found previous not applied update, applying now and restarting..."); - applyPreviousUpdate(); -}