mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-14 17:13:03 -04:00
Revert Asar
Add Asar For Migrate - I forgot Migrate Remove Asar Upload
This commit is contained in:
parent
3a38192395
commit
ba8d88cb40
6 changed files with 67 additions and 17 deletions
|
@ -16,19 +16,26 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { isLegacyNonAsarVencord } from "@main/patcher";
|
||||
import { get } from "@main/utils/simpleGet";
|
||||
import { IpcEvents } from "@shared/IpcEvents";
|
||||
import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent";
|
||||
import { ipcMain } from "electron";
|
||||
import { writeFileSync as originalWriteFileSync } from "original-fs";
|
||||
import { app, dialog, ipcMain } from "electron";
|
||||
import { writeFile } from "fs/promises";
|
||||
import {
|
||||
existsSync,
|
||||
unlinkSync,
|
||||
writeFileSync,
|
||||
} from "original-fs";
|
||||
import { join } from "path";
|
||||
|
||||
import gitHash from "~git-hash";
|
||||
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}`;
|
||||
let PendingUpdate: string | null = null;
|
||||
let PendingUpdates = [] as [string, string][];
|
||||
|
||||
async function githubGet(endpoint: string) {
|
||||
return get(API_BASE + endpoint, {
|
||||
|
@ -65,23 +72,56 @@ async function fetchUpdates() {
|
|||
return false;
|
||||
|
||||
|
||||
const asset = data.assets.find(a => a.name === ASAR_FILE);
|
||||
PendingUpdate = asset.browser_download_url;
|
||||
data.assets.forEach(({ name, browser_download_url }) => {
|
||||
if (EQUICORD_FILES.some(s => name.startsWith(s))) {
|
||||
PendingUpdates.push([name, browser_download_url]);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async function applyUpdates() {
|
||||
if (!PendingUpdate) return true;
|
||||
|
||||
const data = await get(PendingUpdate);
|
||||
originalWriteFileSync(__dirname, data);
|
||||
|
||||
PendingUpdate = null;
|
||||
await Promise.all(PendingUpdates.map(
|
||||
async ([name, data]) => writeFile(
|
||||
join(__dirname, name),
|
||||
await get(data)
|
||||
)
|
||||
));
|
||||
PendingUpdates = [];
|
||||
|
||||
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_UPDATES, serializeErrors(calculateGitChanges));
|
||||
ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue