aboutsummaryrefslogtreecommitdiffstats
path: root/vesktop-patches/0002-Vencord-Remove-Vencord-build-downloader.patch
blob: ebc95d809b30477b7ebb1816ec2cb9195fb4fd51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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