diff options
author | V <vendicated@riseup.net> | 2023-04-09 04:04:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-09 04:04:02 +0200 |
commit | 08822dd19064ea5b707117c5ed51f62dd0a8e316 (patch) | |
tree | 1020c2dad28f5dc502f797ca09066145fcc12109 /src/main | |
parent | bfa20f2634a0f3f73a03135f9ddb9d0dfe566e88 (diff) | |
download | Vencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.tar.gz Vencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.tar.bz2 Vencord-08822dd19064ea5b707117c5ed51f62dd0a8e316.zip |
Improvements for VencordDesktop (#847)
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/index.ts | 5 | ||||
-rw-r--r-- | src/main/updater/common.ts | 27 | ||||
-rw-r--r-- | src/main/updater/git.ts | 3 | ||||
-rw-r--r-- | src/main/updater/http.ts | 20 |
4 files changed, 13 insertions, 42 deletions
diff --git a/src/main/index.ts b/src/main/index.ts index b04ef6c..cb723bb 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -32,9 +32,10 @@ if (IS_VENCORD_DESKTOP || !IS_VANILLA) { if (url.endsWith("/")) url = url.slice(0, -1); switch (url) { case "renderer.js.map": + case "vencordDesktopRenderer.js.map": case "preload.js.map": - case "patcher.js.map": // doubt - case "main.js.map": + case "patcher.js.map": + case "vencordDesktopMain.js.map": cb(join(__dirname, url)); break; default: diff --git a/src/main/updater/common.ts b/src/main/updater/common.ts index bc628f0..7cea82d 100644 --- a/src/main/updater/common.ts +++ b/src/main/updater/common.ts @@ -16,28 +16,13 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { createHash } from "crypto"; -import { createReadStream } from "fs"; -import { join } from "path"; -export async function calculateHashes() { - const hashes = {} as Record<string, string>; - - await Promise.all( - [IS_DISCORD_DESKTOP ? "patcher.js" : "main.js", "preload.js", "renderer.js", "renderer.css"].map(file => new Promise<void>(r => { - const fis = createReadStream(join(__dirname, file)); - const hash = createHash("sha1", { encoding: "hex" }); - fis.once("end", () => { - hash.end(); - hashes[file] = hash.read(); - r(); - }); - fis.pipe(hash); - })) - ); - - return hashes; -} +export const VENCORD_FILES = [ + IS_DISCORD_DESKTOP ? "patcher.js" : "vencordDesktopMain.js", + "preload.js", + IS_DISCORD_DESKTOP ? "renderer.js" : "vencordDesktopRenderer.js", + "renderer.css" +]; export function serializeErrors(func: (...args: any[]) => any) { return async function () { diff --git a/src/main/updater/git.ts b/src/main/updater/git.ts index 89c2d3c..d6a29a8 100644 --- a/src/main/updater/git.ts +++ b/src/main/updater/git.ts @@ -22,7 +22,7 @@ import { ipcMain } from "electron"; import { join } from "path"; import { promisify } from "util"; -import { calculateHashes, serializeErrors } from "./common"; +import { serializeErrors } from "./common"; const VENCORD_SRC_DIR = join(__dirname, ".."); @@ -76,7 +76,6 @@ async function build() { return !res.stderr.includes("Build failed"); } -ipcMain.handle(IpcEvents.GET_HASHES, serializeErrors(calculateHashes)); ipcMain.handle(IpcEvents.GET_REPO, serializeErrors(getRepo)); ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges)); ipcMain.handle(IpcEvents.UPDATE, serializeErrors(pull)); diff --git a/src/main/updater/http.ts b/src/main/updater/http.ts index a2e2aad..e2a3520 100644 --- a/src/main/updater/http.ts +++ b/src/main/updater/http.ts @@ -26,7 +26,7 @@ import gitHash from "~git-hash"; import gitRemote from "~git-remote"; import { get } from "../utils/simpleGet"; -import { calculateHashes, serializeErrors } from "./common"; +import { serializeErrors, VENCORD_FILES } from "./common"; const API_BASE = `https://api.github.com/repos/${gitRemote}`; let PendingUpdates = [] as [string, string][]; @@ -57,13 +57,6 @@ async function calculateGitChanges() { })); } -const FILES_TO_DOWNLOAD = [ - IS_DISCORD_DESKTOP ? "patcher.js" : "vencordDesktopMain.js", - "preload.js", - IS_DISCORD_DESKTOP ? "renderer.js" : "vencordDesktopRenderer.js", - "renderer.css" -]; - async function fetchUpdates() { const release = await githubGet("/releases/latest"); @@ -73,7 +66,7 @@ async function fetchUpdates() { return false; data.assets.forEach(({ name, browser_download_url }) => { - if (FILES_TO_DOWNLOAD.some(s => name.startsWith(s))) { + if (VENCORD_FILES.some(s => name.startsWith(s))) { PendingUpdates.push([name, browser_download_url]); } }); @@ -83,13 +76,7 @@ async function fetchUpdates() { async function applyUpdates() { await Promise.all(PendingUpdates.map( async ([name, data]) => writeFile( - join( - __dirname, - IS_VENCORD_DESKTOP - // vencordDesktopRenderer.js -> renderer.js - ? name.replace(/vencordDesktop(\w)/, (_, c) => c.toLowerCase()) - : name - ), + join(__dirname, name), await get(data) ) )); @@ -97,7 +84,6 @@ async function applyUpdates() { return true; } -ipcMain.handle(IpcEvents.GET_HASHES, serializeErrors(calculateHashes)); ipcMain.handle(IpcEvents.GET_REPO, serializeErrors(() => `https://github.com/${gitRemote}`)); ipcMain.handle(IpcEvents.GET_UPDATES, serializeErrors(calculateGitChanges)); ipcMain.handle(IpcEvents.UPDATE, serializeErrors(fetchUpdates)); |