Refactor ipc to be strongly typed and hide impl details (#1018)

This commit is contained in:
V 2023-05-02 02:50:51 +02:00 committed by GitHub
parent 6a1cb133cd
commit c62d05e1b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 158 additions and 218 deletions

View file

@ -18,7 +18,6 @@
import gitHash from "~git-hash";
import IpcEvents from "./IpcEvents";
import Logger from "./Logger";
import { relaunch } from "./native";
import { IpcRes } from "./types";
@ -39,7 +38,7 @@ async function Unwrap<T>(p: Promise<IpcRes<T>>) {
}
export async function checkForUpdates() {
changes = await Unwrap(VencordNative.ipc.invoke<IpcRes<typeof changes>>(IpcEvents.GET_UPDATES));
changes = await Unwrap(VencordNative.updater.getUpdates());
if (changes.some(c => c.hash === gitHash)) {
isNewer = true;
return (isOutdated = false);
@ -50,22 +49,18 @@ export async function checkForUpdates() {
export async function update() {
if (!isOutdated) return true;
const res = await Unwrap(VencordNative.ipc.invoke<IpcRes<boolean>>(IpcEvents.UPDATE));
const res = await Unwrap(VencordNative.updater.update());
if (res)
if (res) {
isOutdated = false;
if (!await Unwrap(VencordNative.updater.rebuild()))
throw new Error("The Build failed. Please try manually building the new update");
}
return res;
}
export function getRepo() {
return Unwrap(VencordNative.ipc.invoke<IpcRes<string>>(IpcEvents.GET_REPO));
}
export async function rebuild() {
if (!await Unwrap(VencordNative.ipc.invoke<IpcRes<boolean>>(IpcEvents.BUILD)))
throw new Error("The Build failed. Please try manually building the new update");
}
export const getRepo = () => Unwrap(VencordNative.updater.getRepo());
export async function maybePromptToUpdate(confirmMessage: string, checkForDev = false) {
if (IS_WEB) return;
@ -78,7 +73,6 @@ export async function maybePromptToUpdate(confirmMessage: string, checkForDev =
if (wantsUpdate && isNewer) return alert("Your local copy has more recent commits. Please stash or reset them.");
if (wantsUpdate) {
await update();
await rebuild();
relaunch();
}
}