diff options
Diffstat (limited to 'src/main/updater')
-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 |
3 files changed, 10 insertions, 40 deletions
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)); |