Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): activate verified AppImage updates #21622

Openjuliusmarmingewants to merge 5 commits intodesktop-app-12/appimage-replacement fromrefs/pull/21622/headopened View on GitHub

Showing 4 changed files with 170 additions and 0 deletions (loading 3).

x
0 of 4 viewed, 4 left
170 additions and 0 deletionsapps/desktop/src/electron/AppImageInstall.tsAdded
View file
@@ -0,0 +1,170 @@
+// @effect-diagnostics nodeBuiltinImport:off - electron-updater installs synchronously while the app quits.
+import * as NodeChildProcess from "node:child_process";
+import * as NodeCrypto from "node:crypto";
+import * as NodeFS from "node:fs";
+import * as NodePath from "node:path";
+​
+import type { AppImageUpdater } from "electron-updater";
+import type { InstallOptions } from "electron-updater/out/BaseUpdater.js";
+​
+function syncPath(path: string): void {
+ const fd = NodeFS.openSync(path, "r");
+ try {
+ NodeFS.fsyncSync(fd);
+ } finally {
+ NodeFS.closeSync(fd);
+ }
+}
+​
+function verifyAndSync(path: string, sourceSize: number, sha512: string): void {
+ const fd = NodeFS.openSync(path, "r");
+ try {
+ if (NodeFS.fstatSync(fd).size !== sourceSize) {
+ throw new Error("The AppImage update has an invalid size.");
+ }
+ const hash = NodeCrypto.createHash("sha512");
+ const buffer = Buffer.allocUnsafe(1024 * 1024);
+ let read: number;
+ while ((read = NodeFS.readSync(fd, buffer, 0, buffer.length, null)) > 0) {
+ hash.update(buffer.subarray(0, read));
+ }