This repository has been archived on 2025-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
project-client/src/main/utils/vencordLoader.ts
2024-07-19 22:14:22 +02:00

55 lines
1.4 KiB
TypeScript

/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { existsSync } from "fs";
import { join } from "path";
import { USER_AGENT, VENCORD_DIR } from "../constants";
import { downloadFile, fetchie } from "./http";
const API_BASE = "https://api.github.com";
export interface ReleaseData {
name: string;
tag_name: string;
html_url: string;
assets: Array<{
name: string;
browser_download_url: string;
}>;
}
export async function githubGet(endpoint: string) {
const opts: RequestInit = {
headers: {
Accept: "application/vnd.github+json",
"User-Agent": USER_AGENT
}
};
if (process.env.GITHUB_TOKEN) (opts.headers! as any).Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
return fetchie(API_BASE + endpoint, opts, { retryOnNetworkError: true });
}
export async function downloadVencordAsar() {
await downloadFile(
"https://github.com/Vendicated/Vencord/releases/latest/download/vesktop.asar",
VENCORD_DIR,
{},
{ retryOnNetworkError: true }
);
}
export function isValidVencordInstall(dir: string) {
return existsSync(join(dir, "vesktop/main.js"));
}
export async function ensureVencordFiles() {
if (existsSync(VENCORD_DIR)) return;
await downloadVencordAsar();
}