aboutsummaryrefslogtreecommitdiff
path: root/src/ipcMain/updater.ts
diff options
context:
space:
mode:
authorVen <vendicated@riseup.net>2022-10-23 23:23:52 +0200
committerGitHub <noreply@github.com>2022-10-23 23:23:52 +0200
commit5fac8be0ae68cbbdf3514973cbf925a31a765ef5 (patch)
tree8c184e0a2a9c8f4480e4c3880a58833e089a3da6 /src/ipcMain/updater.ts
parentffbb52512cd61764cfe04c1cf2707eb63d5e57bf (diff)
downloadVencord-5fac8be0ae68cbbdf3514973cbf925a31a765ef5.tar.gz
Vencord-5fac8be0ae68cbbdf3514973cbf925a31a765ef5.tar.bz2
Vencord-5fac8be0ae68cbbdf3514973cbf925a31a765ef5.zip
Vencord Standalone without git/node (#148)
Diffstat (limited to 'src/ipcMain/updater.ts')
-rw-r--r--src/ipcMain/updater.ts113
1 files changed, 0 insertions, 113 deletions
diff --git a/src/ipcMain/updater.ts b/src/ipcMain/updater.ts
deleted file mode 100644
index 6987916..0000000
--- a/src/ipcMain/updater.ts
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Vencord, a modification for Discord's desktop app
- * Copyright (c) 2022 Vendicated and contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
-*/
-
-import { execFile as cpExecFile } from "child_process";
-import { createHash } from "crypto";
-import { ipcMain } from "electron";
-import { createReadStream } from "fs";
-import { join } from "path";
-import { promisify } from "util";
-
-import IpcEvents from "../utils/IpcEvents";
-
-const VENCORD_SRC_DIR = join(__dirname, "..");
-
-const execFile = promisify(cpExecFile);
-
-function git(...args: string[]) {
- return execFile("git", args, {
- cwd: VENCORD_SRC_DIR
- });
-}
-
-async function calculateHashes() {
- const hashes = {} as Record<string, string>;
-
- await Promise.all(
- ["patcher.js", "preload.js", "renderer.js"].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;
-}
-
-function serializeErrors(func: (...args: any[]) => any) {
- return async function () {
- try {
- return {
- ok: true,
- value: await func(...arguments)
- };
- } catch (e: any) {
- return {
- ok: false,
- error: e instanceof Error ? {
- // prototypes get lost, so turn error into plain object
- ...e
- } : e
- };
- }
- };
-}
-
-async function getRepo() {
- const res = await git("remote", "get-url", "origin");
- return res.stdout.trim()
- .replace(/git@(.+):/, "https://$1/")
- .replace(/\.git$/, "");
-}
-
-async function calculateGitChanges() {
- await git("fetch");
-
- const res = await git("log", "HEAD...origin/main", "--pretty=format:%an/%h/%s");
-
- const commits = res.stdout.trim();
- return commits ? commits.split("\n").map(line => {
- const [author, hash, ...rest] = line.split("/");
- return {
- hash, author, message: rest.join("/")
- };
- }) : [];
-}
-
-async function pull() {
- const res = await git("pull");
- return res.stdout.includes("Fast-forward");
-}
-
-async function build() {
- const res = await execFile("node", ["scripts/build/build.mjs"], {
- cwd: VENCORD_SRC_DIR
- });
- 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));
-ipcMain.handle(IpcEvents.BUILD, serializeErrors(build));