mirror of
https://github.com/Equicord/Equicord.git
synced 2025-03-14 14:10:26 -04:00
Merge remote-tracking branch 'upstream/asar-bundle'
This commit is contained in:
commit
698290f117
3 changed files with 52 additions and 9 deletions
|
@ -262,6 +262,20 @@ 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<void>(r => resolve = r);
|
||||||
|
buildsFinished = buildsFinished.then(() => done);
|
||||||
|
|
||||||
|
onEnd(() => resolve());
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const commonOpts = {
|
export const commonOpts = {
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
bundle: true,
|
bundle: true,
|
||||||
|
@ -269,7 +283,7 @@ export const commonOpts = {
|
||||||
sourcemap: watch ? "inline" : "external",
|
sourcemap: watch ? "inline" : "external",
|
||||||
legalComments: "linked",
|
legalComments: "linked",
|
||||||
banner,
|
banner,
|
||||||
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin],
|
plugins: [fileUrlPlugin, gitHashPlugin, gitRemotePlugin, stylePlugin, buildsFinishedPlugin],
|
||||||
external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"],
|
external: ["~plugins", "~git-hash", "~git-remote", "/assets/*"],
|
||||||
inject: ["./scripts/build/inject/react.mjs"],
|
inject: ["./scripts/build/inject/react.mjs"],
|
||||||
jsxFactory: "VencordCreateElement",
|
jsxFactory: "VencordCreateElement",
|
||||||
|
@ -287,6 +301,8 @@ export async function buildOrWatchAll() {
|
||||||
if (watch) {
|
if (watch) {
|
||||||
const contexts = await Promise.all(builds.map(context));
|
const contexts = await Promise.all(builds.map(context));
|
||||||
await Promise.all(contexts.map(ctx => ctx.watch()));
|
await Promise.all(contexts.map(ctx => ctx.watch()));
|
||||||
|
|
||||||
|
await buildsFinished;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await Promise.all(builds.map(build));
|
await Promise.all(builds.map(build));
|
||||||
|
|
|
@ -27,11 +27,7 @@ import { IS_VANILLA } from "./utils/constants";
|
||||||
console.log("[Equicord] Starting up...");
|
console.log("[Equicord] Starting up...");
|
||||||
|
|
||||||
// FIXME: remove at some point
|
// FIXME: remove at some point
|
||||||
const isLegacyNonAsarVencord = IS_STANDALONE && !__dirname.endsWith(".asar");
|
export 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
|
// Our injector file at app/index.js
|
||||||
const injectorPath = require.main!.filename;
|
const injectorPath = require.main!.filename;
|
||||||
|
|
|
@ -16,10 +16,15 @@
|
||||||
* 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 { IpcEvents } from "@shared/IpcEvents";
|
import { IpcEvents } from "@shared/IpcEvents";
|
||||||
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
|
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
|
||||||
import { app, dialog, ipcMain } from "electron";
|
import { app, dialog, ipcMain } from "electron";
|
||||||
import { writeFileSync as originalWriteFileSync } from "original-fs";
|
import {
|
||||||
|
existsSync as originalExistsSync,
|
||||||
|
renameSync as originalRenameSync,
|
||||||
|
writeFileSync as originalWriteFileSync,
|
||||||
|
} from "original-fs";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
|
||||||
import gitHash from "~git-hash";
|
import gitHash from "~git-hash";
|
||||||
|
@ -31,6 +36,8 @@ import { ASAR_FILE, 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 PendingUpdate: string | null = null;
|
||||||
|
|
||||||
|
let hasUpdateToApplyOnQuit = false;
|
||||||
|
|
||||||
async function githubGet(endpoint: string) {
|
async function githubGet(endpoint: string) {
|
||||||
return get(API_BASE + endpoint, {
|
return get(API_BASE + endpoint, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -76,7 +83,8 @@ async function applyUpdates() {
|
||||||
if (!PendingUpdate) return true;
|
if (!PendingUpdate) return true;
|
||||||
|
|
||||||
const data = await get(PendingUpdate);
|
const data = await get(PendingUpdate);
|
||||||
originalWriteFileSync(__dirname, data);
|
originalWriteFileSync(__dirname + ".new", data);
|
||||||
|
hasUpdateToApplyOnQuit = true;
|
||||||
|
|
||||||
PendingUpdate = null;
|
PendingUpdate = null;
|
||||||
|
|
||||||
|
@ -88,7 +96,7 @@ ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges));
|
||||||
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));
|
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));
|
||||||
ipcMain.handle(IpcEvents.BUILD, serializeErrors(applyUpdates));
|
ipcMain.handle(IpcEvents.BUILD, serializeErrors(applyUpdates));
|
||||||
|
|
||||||
export async function migrateLegacyToAsar() {
|
async function migrateLegacyToAsar() {
|
||||||
try {
|
try {
|
||||||
const isFlatpak = process.platform === "linux" && !!process.env.FLATPAK_ID;
|
const isFlatpak = process.platform === "linux" && !!process.env.FLATPAK_ID;
|
||||||
if (isFlatpak) throw "Flatpak Discord can't automatically be migrated.";
|
if (isFlatpak) throw "Flatpak Discord can't automatically be migrated.";
|
||||||
|
@ -112,3 +120,26 @@ export async function migrateLegacyToAsar() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyPreviousUpdate() {
|
||||||
|
originalRenameSync(__dirname + ".new", __dirname);
|
||||||
|
|
||||||
|
app.relaunch();
|
||||||
|
app.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
app.on("will-quit", () => {
|
||||||
|
if (hasUpdateToApplyOnQuit)
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue