Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): load saved connections with async safe storage #17311

Closedtarushvkodes(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/17311/headopened View on GitHub

Showing 2 changed files with 130 additions and 6 deletions.

x
0 of 2 viewed, 2 left
105 additions and 0 deletionsapps/desktop/src/electron/ElectronSafeStorage.test.tsAdded
View file
@@ -0,0 +1,105 @@
+import { assert, describe, it } from "@effect/vitest";
+import * as HostProcess from "@t3tools/shared/HostProcess";
+import * as Effect from "effect/Effect";
+import * as Fiber from "effect/Fiber";
+import { beforeEach, vi } from "vite-plus/test";
+​
+const safeStorage = vi.hoisted(() => ({
+ isEncryptionAvailable: vi.fn(),
+ encryptString: vi.fn(),
+ decryptString: vi.fn(),
+ isAsyncEncryptionAvailable: vi.fn(),
+ encryptStringAsync: vi.fn(),
+ decryptStringAsync: vi.fn(),
+}));
+​
+vi.mock("electron", () => ({ safeStorage }));
+​
+import * as ElectronSafeStorage from "./ElectronSafeStorage.ts";
+​
+describe("ElectronSafeStorage", () => {
+ beforeEach(() => vi.resetAllMocks());
+​
+ it.effect("waits for provider readiness and round trips an encrypted catalog", () =>
+ Effect.gen(function* () {
+ const ready = Promise.withResolvers<boolean>();
+ // Windows can report synchronous storage unavailable while the async provider starts.
+ safeStorage.isEncryptionAvailable.mockReturnValue(false);
+ safeStorage.isAsyncEncryptionAvailable.mockReturnValue(ready.promise);
+ safeStorage.encryptStringAsync.mockImplementation(async (value: string) =>
+ Buffer.from(`encrypted:${value}`),