mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Change mod loader to support multiple links. (#547)
This commit is contained in:
parent
41578787d5
commit
e61b99e735
1 changed files with 63 additions and 33 deletions
96
src/utils.ts
96
src/utils.ts
|
@ -395,45 +395,75 @@ async function updateModBundle(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export let modInstallState: string;
|
export let modInstallState: string;
|
||||||
export async function installModLoader(): Promise<void> {
|
export function updateModInstallState() {
|
||||||
|
modInstallState = "modDownload";
|
||||||
|
|
||||||
|
updateModBundle();
|
||||||
|
import("./extensions/plugin");
|
||||||
|
|
||||||
|
modInstallState = "done";
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function installModLoader(): Promise<void>
|
||||||
|
{
|
||||||
if ((await getConfig("mods")) == "none") {
|
if ((await getConfig("mods")) == "none") {
|
||||||
modInstallState = "none";
|
modInstallState = "none";
|
||||||
fs.rmSync(`${app.getPath("userData")}/plugins/loader`, {recursive: true, force: true});
|
fs.rmSync(`${app.getPath("userData")}/plugins/loader`, {recursive: true, force: true});
|
||||||
|
|
||||||
import("./extensions/plugin");
|
import("./extensions/plugin");
|
||||||
console.log("[Mod loader] Skipping");
|
console.log("[Mod loader] Skipping");
|
||||||
} else {
|
|
||||||
const pluginFolder = `${app.getPath("userData")}/plugins/`;
|
return;
|
||||||
if (!fs.existsSync(`${pluginFolder}loader`) || !fs.existsSync(`${pluginFolder}loader/dist/bundle.css`)) {
|
}
|
||||||
try {
|
|
||||||
fs.rmSync(`${app.getPath("userData")}/plugins/loader`, {recursive: true, force: true});
|
const pluginFolder = `${app.getPath("userData")}/plugins/`;
|
||||||
modInstallState = "installing";
|
if (fs.existsSync(`${pluginFolder}loader`) && fs.existsSync(`${pluginFolder}loader/dist/bundle.css`)){
|
||||||
let zipPath = `${app.getPath("temp")}/loader.zip`;
|
updateModInstallState();
|
||||||
if (!fs.existsSync(pluginFolder)) {
|
return;
|
||||||
fs.mkdirSync(pluginFolder);
|
}
|
||||||
console.log("[Mod loader] Created missing plugin folder");
|
|
||||||
}
|
try {
|
||||||
let loaderZip = await fetch("https://armcord.app/loader.zip");
|
fs.rmSync(`${app.getPath("userData")}/plugins/loader`, {recursive: true, force: true});
|
||||||
if (!loaderZip.ok) throw new Error(`unexpected response ${loaderZip.statusText}`);
|
modInstallState = "installing";
|
||||||
await streamPipeline(loaderZip.body, fs.createWriteStream(zipPath));
|
|
||||||
await extract(zipPath, {dir: path.join(app.getPath("userData"), "plugins")});
|
let zipPath = `${app.getPath("temp")}/loader.zip`;
|
||||||
modInstallState = "modDownload";
|
|
||||||
updateModBundle();
|
if(!fs.existsSync(pluginFolder)) {
|
||||||
import("./extensions/plugin");
|
fs.mkdirSync (pluginFolder);
|
||||||
modInstallState = "done";
|
console.log("[Mod loader] Created missing plugin folder");
|
||||||
} catch (e) {
|
|
||||||
console.log("[Mod loader] Failed to install modloader");
|
|
||||||
console.error(e);
|
|
||||||
dialog.showErrorBox(
|
|
||||||
"Oops, something went wrong.",
|
|
||||||
"ArmCord couldn't install internal mod loader, please check if you have stable internet connection and restart the app. If this issue persists, report it on the support server/Github issues."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
modInstallState = "modDownload";
|
|
||||||
updateModBundle();
|
|
||||||
import("./extensions/plugin");
|
|
||||||
modInstallState = "done";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add more of these later if needed!
|
||||||
|
let URLs = ['https://armcord.app/loader.zip', 'https://armcord.vercel.app/loader.zip', 'https://raw.githubusercontent.com/ArmCord/website/new/public/loader.zip'];
|
||||||
|
let loaderZip: any;
|
||||||
|
|
||||||
|
while (true){
|
||||||
|
if(URLs.length <= 0)
|
||||||
|
throw new Error(`unexpected response ${loaderZip.statusText}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
loaderZip = await fetch(URLs[0]);
|
||||||
|
} catch (err) {
|
||||||
|
console.log('[Mod loader] Failed to download. Links left to try: ' + (URLs.length - 1));
|
||||||
|
URLs.splice(0, 1);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await streamPipeline(loaderZip.body, fs.createWriteStream(zipPath));
|
||||||
|
await extract(zipPath, {dir: path.join(app.getPath("userData"), "plugins")});
|
||||||
|
|
||||||
|
updateModInstallState();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("[Mod loader] Failed to install modloader");
|
||||||
|
console.error(e);
|
||||||
|
dialog.showErrorBox(
|
||||||
|
"Oops, something went wrong.",
|
||||||
|
"ArmCord couldn't install internal mod loader, please check if you have stable internet connection and restart the app. If this issue persists, report it on the support server/Github issues."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue