From fdc58caecc427dc398ea8ccafb147a5a1b4a3234 Mon Sep 17 00:00:00 2001 From: 1024x2 Date: Wed, 14 Aug 2024 00:25:41 +0100 Subject: Add initial Vextop patchset and script --- ...2-Vencord-Remove-Vencord-build-downloader.patch | 156 +++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch (limited to 'vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch') diff --git a/vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch b/vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch new file mode 100644 index 0000000..ebc95d8 --- /dev/null +++ b/vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch @@ -0,0 +1,156 @@ +From 65b6370ecce6416ea68e41e8c5ba9a63d97b9017 Mon Sep 17 00:00:00 2001 +From: 1024x2 <2pow11@gmail.com> +Date: Wed, 14 Aug 2024 00:11:40 +0100 +Subject: [PATCH 2/3] Vencord: Remove Vencord build downloader + +This commit only makes sense in the context of Vexcord, sorry :( +--- + src/main/constants.ts | 1 + + src/main/utils/http.ts | 58 --------------------------------- + src/main/utils/vencordLoader.ts | 34 ++++--------------- + 3 files changed, 7 insertions(+), 86 deletions(-) + delete mode 100644 src/main/utils/http.ts + +diff --git a/src/main/constants.ts b/src/main/constants.ts +index 40d91a5..36ab41f 100644 +--- a/src/main/constants.ts ++++ b/src/main/constants.ts +@@ -48,6 +48,7 @@ export const VENCORD_THEMES_DIR = join(DATA_DIR, "themes"); + // needs to be inline require because of circular dependency + // as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised + export const VENCORD_FILES_DIR = ++ process.env.VENCORD_FILES_DIR || + (require("./settings") as typeof import("./settings")).State.store.vencordDir || + join(SESSION_DATA_DIR, "vencordFiles"); + +diff --git a/src/main/utils/http.ts b/src/main/utils/http.ts +deleted file mode 100644 +index baee81e..0000000 +--- a/src/main/utils/http.ts ++++ /dev/null +@@ -1,58 +0,0 @@ +-/* +- * 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 { createWriteStream } from "fs"; +-import { Readable } from "stream"; +-import { pipeline } from "stream/promises"; +-import { setTimeout } from "timers/promises"; +- +-interface FetchieOptions { +- retryOnNetworkError?: boolean; +-} +- +-export async function downloadFile(url: string, file: string, options: RequestInit = {}, fetchieOpts?: FetchieOptions) { +- const res = await fetchie(url, options, fetchieOpts); +- await pipeline( +- // @ts-expect-error odd type error +- Readable.fromWeb(res.body!), +- createWriteStream(file, { +- autoClose: true +- }) +- ); +-} +- +-const ONE_MINUTE_MS = 1000 * 60; +- +-export async function fetchie(url: string, options?: RequestInit, { retryOnNetworkError }: FetchieOptions = {}) { +- let res: Response | undefined; +- +- try { +- res = await fetch(url, options); +- } catch (err) { +- if (retryOnNetworkError) { +- console.error("Failed to fetch", url + ".", "Gonna retry with backoff."); +- +- for (let tries = 0, delayMs = 500; tries < 20; tries++, delayMs = Math.min(2 * delayMs, ONE_MINUTE_MS)) { +- await setTimeout(delayMs); +- try { +- res = await fetch(url, options); +- break; +- } catch {} +- } +- } +- +- if (!res) throw new Error(`Failed to fetch ${url}\n${err}`); +- } +- +- if (res.ok) return res; +- +- let msg = `Got non-OK response for ${url}: ${res.status} ${res.statusText}`; +- +- const reason = await res.text().catch(() => ""); +- if (reason) msg += `\n${reason}`; +- +- throw new Error(msg); +-} +diff --git a/src/main/utils/vencordLoader.ts b/src/main/utils/vencordLoader.ts +index c0bac6a..3f08ad0 100644 +--- a/src/main/utils/vencordLoader.ts ++++ b/src/main/utils/vencordLoader.ts +@@ -4,14 +4,11 @@ + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +-import { mkdirSync } from "fs"; +-import { access, constants as FsConstants } from "fs/promises"; ++import { mkdir, access, constants as FsConstants } from "fs/promises"; + import { join } from "path"; + + import { USER_AGENT, VENCORD_FILES_DIR } from "../constants"; +-import { downloadFile, fetchie } from "./http"; +- +-const API_BASE = "https://api.github.com"; ++import { app, dialog } from "electron"; + + export const FILES_TO_DOWNLOAD = [ + "vencordDesktopMain.js", +@@ -31,30 +28,11 @@ export interface ReleaseData { + } + + 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 }); ++ throw new Error("No"); + } + + export async function downloadVencordFiles() { +- const release = await githubGet("/repos/Vendicated/Vencord/releases/latest"); +- +- const { assets }: ReleaseData = await release.json(); +- +- await Promise.all( +- assets +- .filter(({ name }) => FILES_TO_DOWNLOAD.some(f => name.startsWith(f))) +- .map(({ name, browser_download_url }) => +- downloadFile(browser_download_url, join(VENCORD_FILES_DIR, name), {}, { retryOnNetworkError: true }) +- ) +- ); ++ dialog.showErrorBox("No", "Go away"); + } + + const existsAsync = (path: string) => +@@ -69,7 +47,7 @@ export async function isValidVencordInstall(dir: string) { + export async function ensureVencordFiles() { + if (await isValidVencordInstall(VENCORD_FILES_DIR)) return; + +- mkdirSync(VENCORD_FILES_DIR, { recursive: true }); ++ dialog.showErrorBox("Could not find Vencord files!", "Please specify a folder containing \"vencordDesktopMain.js\" in the environment variable VENCORD_FILES_DIR."); + +- await downloadVencordFiles(); ++ app.exit(1); + } +-- +2.45.2 + -- cgit v1.2.3