migrate legacy installs
This commit is contained in:
parent
7148c29ed1
commit
2ace675c00
|
@ -22,18 +22,23 @@ 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...");
|
||||
|
||||
// FIXME: remove at some point
|
||||
const isLegacyNonAsarVencord = IS_STANDALONE && !__dirname.endsWith(".asar");
|
||||
if (isLegacyNonAsarVencord) {
|
||||
console.warn("This is a legacy non asar install! Migrating to asar and restarting...");
|
||||
migrateLegacyToAsar();
|
||||
}
|
||||
|
||||
// Our injector file at app/index.js
|
||||
const injectorPath = require.main!.filename;
|
||||
|
||||
// special discord_arch_electron injection method
|
||||
const asarName = require.main!.path.endsWith("app.asar") ? "_app.asar" : "app.asar";
|
||||
|
||||
// The original app.asar
|
||||
const asarPath = join(dirname(injectorPath), "..", asarName);
|
||||
const asarPath = join(dirname(injectorPath), "..", "_app.asar");
|
||||
|
||||
const discordPkg = require(join(asarPath, "package.json"));
|
||||
require.main!.filename = join(asarPath, discordPkg.main);
|
||||
|
@ -41,7 +46,7 @@ require.main!.filename = join(asarPath, discordPkg.main);
|
|||
// @ts-ignore Untyped method? Dies from cringe
|
||||
app.setAppPath(asarPath);
|
||||
|
||||
if (!IS_VANILLA) {
|
||||
if (!IS_VANILLA && !isLegacyNonAsarVencord) {
|
||||
const settings = RendererSettings.store;
|
||||
// Repatch after host updates on Windows
|
||||
if (process.platform === "win32") {
|
||||
|
@ -157,5 +162,7 @@ if (!IS_VANILLA) {
|
|||
console.log("[Vencord] Running in vanilla mode. Not loading Vencord");
|
||||
}
|
||||
|
||||
console.log("[Vencord] Loading original Discord app.asar");
|
||||
require(require.main!.filename);
|
||||
if (!isLegacyNonAsarVencord) {
|
||||
console.log("[Vencord] Loading original Discord app.asar");
|
||||
require(require.main!.filename);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
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 { join } from "path";
|
||||
|
||||
|
@ -76,14 +76,7 @@ async function applyUpdates() {
|
|||
if (!PendingUpdate) return true;
|
||||
|
||||
const data = await get(PendingUpdate);
|
||||
|
||||
if (__dirname.endsWith(".asar")) {
|
||||
await writeFile(__dirname, data);
|
||||
} else { // legacy plain folder install
|
||||
await writeFile(join(__dirname, "../vencord.asar"), data);
|
||||
|
||||
await writeFile(__filename, '// legacy install workaround\n\nrequire("../vencord.asar");');
|
||||
}
|
||||
await writeFile(__dirname, data);
|
||||
|
||||
PendingUpdate = null;
|
||||
|
||||
|
@ -94,3 +87,22 @@ ipcMain.handle(IpcEvents.GET_REPO, serializeErrors(() => `https://github.com/${g
|
|||
ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges));
|
||||
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));
|
||||
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\");");
|
||||
app.relaunch();
|
||||
} catch (e) {
|
||||
console.error("Failed to migrate to asar", e);
|
||||
|
||||
app.whenReady().then(() => {
|
||||
dialog.showErrorBox(
|
||||
"Legacy Install",
|
||||
"The way Vencord loaded was changed and the updater failed to migrate. Please reinstall using the Vencord Installer!"
|
||||
);
|
||||
app.quit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue