Revert Asar

Add Asar For Migrate - I forgot

Migrate

Remove Asar Upload
This commit is contained in:
thororen1234 2025-04-05 18:30:12 -04:00
parent 3a38192395
commit ba8d88cb40
No known key found for this signature in database
6 changed files with 67 additions and 17 deletions

View file

@ -43,9 +43,11 @@ if (IS_VESKTOP || !IS_VANILLA) {
} }
switch (url) { switch (url) {
case "renderer.js.map": case "renderer.js.map":
case "equibopRenderer.js.map":
case "preload.js.map": case "preload.js.map":
case "equibopPreload.js.map":
case "patcher.js.map": case "patcher.js.map":
case "main.js.map": case "equibopMain.js.map":
cb(join(__dirname, url)); cb(join(__dirname, url));
break; break;
default: default:

View file

@ -119,7 +119,7 @@ ipcMain.handle(IpcEvents.OPEN_MONACO_EDITOR, async () => {
autoHideMenuBar: true, autoHideMenuBar: true,
darkTheme: true, darkTheme: true,
webPreferences: { webPreferences: {
preload: join(__dirname, "preload.js"), preload: join(__dirname, IS_DISCORD_DESKTOP ? "preload.js" : "equibopPreload.js"),
contextIsolation: true, contextIsolation: true,
nodeIntegration: false, nodeIntegration: false,
sandbox: false sandbox: false

View file

@ -29,8 +29,11 @@ console.log("[Equicord] Starting up...");
// Our injector file at app/index.js // Our injector file at app/index.js
const injectorPath = require.main!.filename; 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 // The original app.asar
const asarPath = join(dirname(injectorPath), "..", "_app.asar"); const asarPath = join(dirname(injectorPath), "..", asarName);
const discordPkg = require(join(asarPath, "package.json")); const discordPkg = require(join(asarPath, "package.json"));
require.main!.filename = join(asarPath, discordPkg.main); require.main!.filename = join(asarPath, discordPkg.main);

View file

@ -16,7 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
export const ASAR_FILE = IS_VESKTOP ? "vesktop.asar" : IS_EQUIBOP ? "equibop.asar" : "desktop.asar"; export const EQUICORD_FILES = [
IS_DISCORD_DESKTOP ? "patcher.js" : "equibopMain.js",
IS_DISCORD_DESKTOP ? "preload.js" : "equibopPreload.js",
IS_DISCORD_DESKTOP ? "renderer.js" : "equibopRenderer.js",
IS_DISCORD_DESKTOP ? "renderer.css" : "equibopRenderer.css",
];
export function serializeErrors(func: (...args: any[]) => any) { export function serializeErrors(func: (...args: any[]) => any) {
return async function () { return async function () {

View file

@ -16,19 +16,26 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { isLegacyNonAsarVencord } from "@main/patcher";
import { get } from "@main/utils/simpleGet"; import { get } from "@main/utils/simpleGet";
import { IpcEvents } from "@shared/IpcEvents"; import { IpcEvents } from "@shared/IpcEvents";
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
import { ipcMain } from "electron"; import { app, dialog, ipcMain } from "electron";
import { writeFileSync as originalWriteFileSync } from "original-fs"; import { writeFile } from "fs/promises";
import {
existsSync,
unlinkSync,
writeFileSync,
} from "original-fs";
import { join } from "path";
import gitHash from "~git-hash"; import gitHash from "~git-hash";
import gitRemote from "~git-remote"; import gitRemote from "~git-remote";
import { ASAR_FILE, serializeErrors } from "./common"; import { EQUICORD_FILES, serializeErrors } from "./common";
const API_BASE = `https://api.github.com/repos/${gitRemote}`; const API_BASE = `https://api.github.com/repos/${gitRemote}`;
let PendingUpdate: string | null = null; let PendingUpdates = [] as [string, string][];
async function githubGet(endpoint: string) { async function githubGet(endpoint: string) {
return get(API_BASE + endpoint, { return get(API_BASE + endpoint, {
@ -65,23 +72,56 @@ async function fetchUpdates() {
return false; return false;
const asset = data.assets.find(a => a.name === ASAR_FILE); data.assets.forEach(({ name, browser_download_url }) => {
PendingUpdate = asset.browser_download_url; if (EQUICORD_FILES.some(s => name.startsWith(s))) {
PendingUpdates.push([name, browser_download_url]);
}
});
return true; return true;
} }
async function applyUpdates() { async function applyUpdates() {
if (!PendingUpdate) return true; await Promise.all(PendingUpdates.map(
async ([name, data]) => writeFile(
const data = await get(PendingUpdate); join(__dirname, name),
originalWriteFileSync(__dirname, data); await get(data)
)
PendingUpdate = null; ));
PendingUpdates = [];
return true; 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_REPO, serializeErrors(() => `https://github.com/${gitRemote}`));
ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges)); ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges));
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates)); ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));

View file

@ -28,7 +28,7 @@ contextBridge.exposeInMainWorld("VencordNative", VencordNative);
// Discord // Discord
if (location.protocol !== "data:") { if (location.protocol !== "data:") {
// #region cssInsert // #region cssInsert
const rendererCss = join(__dirname, "renderer.css"); const rendererCss = join(__dirname, IS_DISCORD_DESKTOP ? "renderer.css" : "equibopRenderer.css");
const style = document.createElement("style"); const style = document.createElement("style");
style.id = "vencord-css-core"; style.id = "vencord-css-core";