diff options
author | Vendicated <vendicated@riseup.net> | 2022-10-01 00:42:50 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-10-01 00:42:50 +0200 |
commit | 8161a07dba401f04dac93f861e6b2cffe53ab7e3 (patch) | |
tree | 1499e825bcd6a162bc43507f492b262e9b1901ed /src/utils/updater.ts | |
parent | 9aaa47ea4e9ac068bf5fcbb997e31d722f43f1e5 (diff) | |
download | Vencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.tar.gz Vencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.tar.bz2 Vencord-8161a07dba401f04dac93f861e6b2cffe53ab7e3.zip |
Add in client updater, Notices API
Diffstat (limited to 'src/utils/updater.ts')
-rw-r--r-- | src/utils/updater.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/utils/updater.ts b/src/utils/updater.ts new file mode 100644 index 0000000..b3fa812 --- /dev/null +++ b/src/utils/updater.ts @@ -0,0 +1,51 @@ +import IpcEvents from "./IpcEvents"; +import Logger from "./logger"; +import { IpcRes } from './types'; + +export const UpdateLogger = new Logger("Updater", "white"); +export let isOutdated = false; +export let changes: Record<"hash" | "author" | "message", string>[]; + +async function Unwrap<T>(p: Promise<IpcRes<T>>) { + const res = await p; + + if (res.ok) return res.value; + throw res.error; +} + +export async function checkForUpdates() { + changes = await Unwrap(VencordNative.ipc.invoke<IpcRes<typeof changes>>(IpcEvents.GET_UPDATES)); + return (isOutdated = changes.length > 0); +} + +export async function update() { + if (!isOutdated) return true; + + const res = await Unwrap(VencordNative.ipc.invoke<IpcRes<boolean>>(IpcEvents.UPDATE)); + + if (res) + isOutdated = false; + + return res; +} + +export function getRepo() { + return Unwrap(VencordNative.ipc.invoke<IpcRes<string>>(IpcEvents.GET_REPO)); +} + +type Hashes = Record<"patcher.js" | "preload.js" | "renderer.js", string>; + +/** + * @returns true if hard restart is required + */ +export async function rebuild() { + const oldHashes = await Unwrap(VencordNative.ipc.invoke<IpcRes<Hashes>>(IpcEvents.GET_HASHES)); + + if (!await Unwrap(VencordNative.ipc.invoke<IpcRes<boolean>>(IpcEvents.BUILD))) + throw new Error("The Build failed. Please try manually building the new update"); + + const newHashes = await Unwrap(VencordNative.ipc.invoke<IpcRes<Hashes>>(IpcEvents.GET_HASHES)); + + return oldHashes["patcher.js"] !== newHashes["patcher.js"] || + oldHashes["preload.js"] !== newHashes["preload.js"]; +} |