@devries-cameron20 / t3code Mirror · read-only / commits / 41b513d99a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 22:00 UTC

revert: "fix(desktop): saved connections survive the Beta rename on macOS and Linux" (#20907) (#22219)

Co-authored-by: Julius Marminge <julius@marminge.se>

Julius Marminge committed Oct 20, 2026 at 01:30 UTC 41b513d99aac6ba4d4a4000a3a3a1320b0f79dad
7 files changed +17 -437
apps/desktop/src/app/DesktopConnectionCatalogStore.test.ts
+4 -259
@@ -1,14 +1,9 @@
1 -// @effect-diagnostics nodeBuiltinImport:off - The recovery fixtures use Chromium OSCrypt ciphertext.
2 -import * as NodeCrypto from "node:crypto";
3 -
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, describe, it } from "@effect/vitest";
3 import { ConnectionCatalogDocument } from "@t3tools/client-runtime/platform";
4 import { EnvironmentId, type PersistedSavedEnvironmentRecord } from "@t3tools/contracts";
8 -import * as Deferred from "effect/Deferred";
5 import * as Effect from "effect/Effect";
6 import * as Base64 from "effect/encoding/Base64";
11 -import * as Fiber from "effect/Fiber";
7 import * as FileSystem from "effect/FileSystem";
8 import * as Path from "effect/Path";
9 import * as Layer from "effect/Layer";
@@ -16,65 +11,12 @@ import * as Option from "effect/Option";
11 import * as PlatformError from "effect/PlatformError";
12 import * as Ref from "effect/Ref";
13 import * as Schema from "effect/Schema";
19 -import * as Sink from "effect/Sink";
20 -import * as Stream from "effect/Stream";
21 -import { ChildProcessSpawner } from "effect/process";
22 -import { beforeEach, vi } from "vite-plus/test";
14
15 import * as ElectronSafeStorage from "../electron/ElectronSafeStorage.ts";
25 -import { LinuxBrowserSecretPath } from "../preview/BrowserImport/LinuxBrowserSecret.ts";
16 import * as DesktopSavedEnvironments from "../settings/DesktopSavedEnvironments.ts";
17 import * as DesktopConfig from "./DesktopConfig.ts";
18 import * as DesktopConnectionCatalogStore from "./DesktopConnectionCatalogStore.ts";
19 import * as DesktopEnvironment from "./DesktopEnvironment.ts";
30 -import * as DesktopSafeStorageIdentity from "./DesktopSafeStorageIdentity.ts";
31 -
32 -const { getBetaPassword } = vi.hoisted(() => ({
33 - getBetaPassword: vi.fn<() => string | null>(),
34 -}));
35 -
36 -vi.mock("@napi-rs/keyring", () => ({
37 - Entry: class {
38 - readonly getPassword;
39 - constructor(service: string, account: string) {
40 - this.getPassword = () =>
41 - service === "T3 Code (Beta) Safe Storage" && account === "T3 Code (Beta)"
42 - ? getBetaPassword()
43 - : null;
44 - }
45 - },
46 -}));
47 -
48 -beforeEach(() => {
49 - getBetaPassword.mockReset().mockReturnValue(null);
50 -});
51 -
52 -const savedCatalog = JSON.stringify({
53 - schemaVersion: 1,
54 - targets: [
55 - { _tag: "RelayConnectionTarget", environmentId: "relay-environment", label: "Saved relay" },
56 - ],
57 - profiles: [],
58 - credentials: [],
59 - remoteDpopTokens: [],
60 - disabledEnvironmentIds: [],
61 -});
62 -
63 -const encryptBetaCatalog = (platform: NodeJS.Platform, catalog = savedCatalog) => {
64 - const key = NodeCrypto.pbkdf2Sync(
65 - "beta-secret",
66 - "saltysalt",
67 - platform === "darwin" ? 1003 : 1,
68 - 16,
69 - "sha1",
70 - );
71 - const cipher = NodeCrypto.createCipheriv("aes-128-cbc", key, Buffer.alloc(16, " "));
72 - return Buffer.concat([
73 - Buffer.from(platform === "darwin" ? "v10" : "v11"),
74 - cipher.update(catalog, "utf8"),
75 - cipher.final(),
76 - ]);
77 -};
20
21 const textDecoder = new TextDecoder();
22 const textEncoder = new TextEncoder();
@@ -86,11 +28,7 @@ const encodeLegacySavedEnvironments = Schema.encodeEffect(
28 Schema.Struct({ version: Schema.Literal(1), records: Schema.Array(Schema.Unknown) }),
29 ),
30 );
89 -function layerSafeStorageFor(
90 - available: boolean,
91 - failDecrypt: Ref.Ref<boolean> | null = null,
92 - currentSecret?: string,
93 -) {
31 +function layerSafeStorageFor(available: boolean, failDecrypt: Ref.Ref<boolean> | null = null) {
32 return Layer.succeed(ElectronSafeStorage.ElectronSafeStorage, {
33 isEncryptionAvailable: Effect.succeed(available),
34 encryptString: (value) => Effect.succeed(textEncoder.encode(`encrypted:${value}`)),
@@ -101,23 +39,6 @@ function layerSafeStorageFor(
39 !decoded.startsWith("encrypted:") ||
40 (failDecrypt !== null && (yield* Ref.get(failDecrypt)))
41 ) {
104 - if (currentSecret !== undefined) {
105 - return yield* Effect.try({
106 - try: () => {
107 - const key = NodeCrypto.pbkdf2Sync(currentSecret, "saltysalt", 1003, 16, "sha1");
108 - const decipher = NodeCrypto.createDecipheriv(
109 - "aes-128-cbc",
110 - key,
111 - Buffer.alloc(16, " "),
112 - );
113 - return Buffer.concat([
114 - decipher.update(value.subarray(3)),
115 - decipher.final(),
116 - ]).toString("utf8");
117 - },
118 - catch: (cause) => new ElectronSafeStorage.ElectronSafeStorageDecryptError({ cause }),
119 - });
120 - }
42 return yield* new ElectronSafeStorage.ElectronSafeStorageDecryptError({
43 cause: new Error("invalid encrypted catalog"),
44 });
@@ -129,52 +50,16 @@ function layerSafeStorageFor(
50 } satisfies ElectronSafeStorage.ElectronSafeStorage["Service"]);
51 }
52
132 -const layerLinuxKeyAccess = (lookup: Effect.Effect<string | null>) =>
133 - Layer.merge(
134 - Layer.succeed(LinuxBrowserSecretPath, "/bundled/browser-secret/t3-browser-secret"),
135 - Layer.succeed(
136 - ChildProcessSpawner.ChildProcessSpawner,
137 - ChildProcessSpawner.make((command) =>
138 - Effect.gen(function* () {
139 - const secret =
140 - command._tag === "StandardCommand" && command.args[0] === "T3 Code (Beta)"
141 - ? yield* lookup
142 - : null;
143 - return ChildProcessSpawner.makeHandle({
144 - pid: ChildProcessSpawner.ProcessId(1),
145 - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(secret === null ? 2 : 0)),
146 - isRunning: Effect.succeed(false),
147 - kill: () => Effect.void,
148 - unref: Effect.succeed(Effect.void),
149 - stdin: Sink.drain,
150 - stdout: Stream.encodeText(Stream.make(secret ?? "")),
151 - stderr: Stream.empty,
152 - all: Stream.empty,
153 - getInputFd: () => Sink.drain,
154 - getOutputFd: () => Stream.empty,
155 - });
156 - }),
157 - ),
158 - ),
159 - );
160 -
161 -interface RecoveryOptions {
162 - readonly platform?: NodeJS.Platform;
163 - readonly linuxKeyLookup?: Effect.Effect<string | null>;
164 - readonly currentSecret?: string | undefined;
165 -}
166 -
53 function layerFor(
54 baseDir: string,
55 encryptionAvailable = true,
56 failDecrypt: Ref.Ref<boolean> | null = null,
57 fileSystemLayer: Layer.Layer<FileSystem.FileSystem> = NodeServices.layer,
172 - recovery: RecoveryOptions = {},
58 ) {
59 const layerEnvironment = DesktopEnvironment.layer({
60 dirname: "/repo/apps/desktop/src",
61 homeDirectory: baseDir,
177 - platform: recovery.platform ?? "darwin",
62 + platform: "darwin",
63 processArch: "arm64",
64 appVersion: "1.2.3",
65 appPath: "/repo",
@@ -186,18 +71,10 @@ function layerFor(
71 Layer.mergeAll(NodeServices.layer, DesktopConfig.layerTest({ T3CODE_HOME: baseDir })),
72 ),
73 );
189 - const layerSafeStorage = layerSafeStorageFor(
190 - encryptionAvailable,
191 - failDecrypt,
192 - recovery.currentSecret,
193 - );
74 + const layerSafeStorage = layerSafeStorageFor(encryptionAvailable, failDecrypt);
75 const layerDependencies = Layer.mergeAll(
76 layerEnvironment,
77 layerSafeStorage,
197 - DesktopSafeStorageIdentity.layer.pipe(
198 - Layer.provide(layerEnvironment),
199 - Layer.provide(layerLinuxKeyAccess(recovery.linuxKeyLookup ?? Effect.succeed(null))),
200 - ),
78 NodeServices.layer,
79 fileSystemLayer,
80 );
@@ -214,16 +91,13 @@ function layerFor(
91 const withStore = <A, E, R>(
92 effect: Effect.Effect<A, E, R | DesktopConnectionCatalogStore.DesktopConnectionCatalogStore>,
93 encryptionAvailable = true,
217 - recovery: RecoveryOptions = {},
94 ) =>
95 Effect.gen(function* () {
96 const fileSystem = yield* FileSystem.FileSystem;
97 const baseDir = yield* fileSystem.makeTempDirectoryScoped({
98 prefix: "t3-desktop-connection-catalog-test-",
99 });
224 - return yield* effect.pipe(
225 - Effect.provide(layerFor(baseDir, encryptionAvailable, null, NodeServices.layer, recovery)),
226 - );
100 + return yield* effect.pipe(Effect.provide(layerFor(baseDir, encryptionAvailable)));
101 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped);
102
103 describe("DesktopConnectionCatalogStore", () => {
@@ -566,133 +440,4 @@ describe("DesktopConnectionCatalogStore", () => {
440 assert.deepStrictEqual(yield* store.get, Option.some('{"schemaVersion":1,"targets":[]}'));
441 }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
442 );
569 -
570 - const writeBetaCatalog = (
571 - platform: NodeJS.Platform,
572 - encryptedCatalog = encryptBetaCatalog(platform),
573 - ) =>
574 - Effect.gen(function* () {
575 - const path = yield* Path.Path;
576 - const environment = yield* DesktopEnvironment.DesktopEnvironment;
577 - const fileSystem = yield* FileSystem.FileSystem;
578 - const catalogPath = path.join(environment.stateDir, "connection-catalog.json");
579 - const contents = `${JSON.stringify({
580 - version: 1,
581 - encryptedCatalog: Base64.encode(encryptedCatalog),
582 - })}\n`;
583 - yield* fileSystem.makeDirectory(environment.stateDir, { recursive: true });
584 - yield* fileSystem.writeFileString(catalogPath, contents);
585 - return { catalogPath, contents };
586 - });
587 -
588 - it.effect.each([
589 - { platform: "darwin" as const, currentSecret: undefined, label: "macOS" },
590 - { platform: "linux" as const, currentSecret: undefined, label: "Linux" },
591 - {
592 - platform: "darwin" as const,
593 - currentSecret: "wrong-key-494",
594 - label: "macOS with valid padding under the wrong current key",
595 - },
596 - ])(
597 - "recovers a Beta catalog on $label and reopens it without the Beta key",
598 - ({ platform, currentSecret }) =>
599 - withStore(
600 - Effect.gen(function* () {
601 - getBetaPassword.mockReturnValue("beta-secret");
602 - const fileSystem = yield* FileSystem.FileSystem;
603 - const environment = yield* DesktopEnvironment.DesktopEnvironment;
604 - const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
605 - const { catalogPath, contents } = yield* writeBetaCatalog(platform);
606 -
607 - assert.deepStrictEqual(yield* store.get, Option.some(savedCatalog));
608 - assert.notEqual(yield* fileSystem.readFileString(catalogPath), contents);
609 -
610 - getBetaPassword.mockReturnValue(null);
611 - const reopened = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore.pipe(
612 - Effect.provide(
613 - layerFor(environment.homeDirectory, true, null, NodeServices.layer, { platform }),
614 - ),
615 - );
616 - assert.deepStrictEqual(yield* reopened.get, Option.some(savedCatalog));
617 - }),
618 - true,
619 - { platform, currentSecret, linuxKeyLookup: Effect.succeed("beta-secret") },
620 - ),
621 - );
622 -
623 - it.effect.each([
624 - // This wrong key has valid CBC padding, so decryption alone cannot validate recovery.
625 - { platform: "darwin" as const, secret: "wrong-key-494", label: "a wrong Beta key" },
626 - { platform: "linux" as const, secret: null, label: "a missing Beta key" },
627 - {
628 - platform: "darwin" as const,
629 - secret: "beta-secret",
630 - label: "unencrypted input",
631 - encryptedCatalog: Buffer.from(savedCatalog),
632 - },
633 - {
634 - platform: "linux" as const,
635 - secret: "beta-secret",
636 - label: "an invalid catalog",
637 - encryptedCatalog: encryptBetaCatalog("linux", '{"schemaVersion":1,"targets":null}'),
638 - },
639 - ])("leaves the catalog bytes intact for $label", ({ platform, secret, encryptedCatalog }) =>
640 - withStore(
641 - Effect.gen(function* () {
642 - getBetaPassword.mockReturnValue(secret);
643 - const fileSystem = yield* FileSystem.FileSystem;
644 - const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
645 - const { catalogPath, contents } = yield* writeBetaCatalog(platform, encryptedCatalog);
646 -
647 - const error = yield* store.get.pipe(Effect.flip);
648 - assert.instanceOf(
649 - error,
650 - DesktopConnectionCatalogStore.DesktopConnectionCatalogStoreProtectionError,
651 - );
652 - assert.equal(error.operation, "decrypt-catalog");
653 - assert.equal(yield* fileSystem.readFileString(catalogPath), contents);
654 - }),
655 - true,
656 - { platform, linuxKeyLookup: Effect.succeed(secret) },
657 - ),
658 - );
659 -
660 - it.effect.each(["save", "clear"] as const)(
661 - "preserves a concurrent %s while Beta key recovery is waiting",
662 - (operation) =>
663 - Effect.gen(function* () {
664 - const lookupStarted = yield* Deferred.make<void>();
665 - const lookupReleased = yield* Deferred.make<void>();
666 - const linuxKeyLookup = Deferred.succeed(lookupStarted, undefined).pipe(
667 - Effect.andThen(Deferred.await(lookupReleased)),
668 - Effect.as("beta-secret"),
669 - );
670 - const newer = savedCatalog.replace("Saved relay", "Updated relay");
671 -
672 - yield* withStore(
673 - Effect.gen(function* () {
674 - const fileSystem = yield* FileSystem.FileSystem;
675 - const store = yield* DesktopConnectionCatalogStore.DesktopConnectionCatalogStore;
676 - const { catalogPath } = yield* writeBetaCatalog("linux");
677 - const recovery = yield* store.get.pipe(Effect.forkChild);
678 - yield* Deferred.await(lookupStarted);
679 - if (operation === "save") {
680 - assert.isTrue(yield* store.set(newer));
681 - } else {
682 - yield* store.clear;
683 - }
684 - yield* Deferred.succeed(lookupReleased, undefined);
685 - yield* Fiber.join(recovery);
686 -
687 - assert.deepStrictEqual(
688 - yield* store.get,
689 - operation === "save" ? Option.some(newer) : Option.none(),
690 - );
691 - assert.equal(yield* fileSystem.exists(catalogPath), operation === "save");
692 - }),
693 - true,
694 - { platform: "linux", linuxKeyLookup },
695 - );
696 - }),
697 - );
443 });
apps/desktop/src/app/DesktopConnectionCatalogStore.ts
+8 -50
@@ -21,12 +21,10 @@ import * as Layer from "effect/Layer";
21 import * as Option from "effect/Option";
22 import * as Path from "effect/Path";
23 import * as Schema from "effect/Schema";
24 -import * as Semaphore from "effect/Semaphore";
24
25 import * as ElectronSafeStorage from "../electron/ElectronSafeStorage.ts";
26 import * as DesktopSavedEnvironments from "../settings/DesktopSavedEnvironments.ts";
27 import * as DesktopEnvironment from "./DesktopEnvironment.ts";
29 -import * as DesktopSafeStorageIdentity from "./DesktopSafeStorageIdentity.ts";
28
29 const EncryptedConnectionCatalogDocument = Schema.Struct({
30 version: Schema.Literal(1),
@@ -47,8 +45,6 @@ const RuntimeConnectionCatalogDocumentJson = Schema.fromJsonString(
45 const encodeRuntimeConnectionCatalogDocumentJson = Schema.encodeEffect(
46 RuntimeConnectionCatalogDocumentJson,
47 );
50 -const decodeCatalogJsonOption = Schema.decodeOption(RuntimeConnectionCatalogDocumentJson);
51 -const decodeNativeCatalogJson = Schema.decodeEffect(Schema.fromJsonString(Schema.Unknown));
48
49 const DesktopConnectionCatalogStoreWriteOperation = Schema.Literals([
50 "create-temporary-file-name",
@@ -386,11 +382,9 @@ export const make = Effect.gen(function* () {
382 const fileSystem = yield* FileSystem.FileSystem;
383 const path = yield* Path.Path;
384 const safeStorage = yield* ElectronSafeStorage.ElectronSafeStorage;
389 - const safeStorageIdentity = yield* DesktopSafeStorageIdentity.DesktopSafeStorageIdentity;
385 const crypto = yield* Crypto.Crypto;
386 const savedEnvironments = yield* DesktopSavedEnvironments.DesktopSavedEnvironments;
387 const catalogPath = path.join(environment.stateDir, "connection-catalog.json");
393 - const writeLock = yield* Semaphore.make(1);
388 const encryptionAvailable = safeStorage.isEncryptionAvailable.pipe(
389 Effect.mapError(
390 (cause) =>
@@ -477,40 +471,6 @@ export const make = Effect.gen(function* () {
471 return Option.some(encoded);
472 });
473
480 - const recoverPreviousIdentityCatalog = Effect.fn(
481 - "desktop.connectionCatalogStore.recoverPreviousIdentityCatalog",
482 - )(function* (
483 - document: EncryptedConnectionCatalogDocument,
484 - encryptedCatalog: Uint8Array,
485 - cause: ElectronSafeStorage.ElectronSafeStorageDecryptError | Schema.SchemaError,
486 - ) {
487 - const recovered = Option.filter(
488 - yield* safeStorageIdentity.decryptWithPreviousName(encryptedCatalog),
489 - (catalog) => Option.isSome(decodeCatalogJsonOption(catalog)),
490 - );
491 - if (Option.isNone(recovered)) {
492 - return yield* new DesktopConnectionCatalogStoreProtectionError({
493 - operation: "decrypt-catalog",
494 - catalogPath,
495 - cause,
496 - });
497 - }
498 - // Reading the previous key can wait on a Keychain prompt, so a newer catalog
499 - // may have been saved since this one was read.
500 - yield* Effect.gen(function* () {
501 - const current = yield* readDocument(fileSystem, catalogPath);
502 - if (Option.isSome(current) && current.value.encryptedCatalog === document.encryptedCatalog) {
503 - yield* writeCatalog(recovered.value);
504 - }
505 - }).pipe(
506 - writeLock.withPermits(1),
507 - Effect.catch((error) =>
508 - Effect.logWarning("Could not re-encrypt the connection catalog.", { catalogPath, error }),
509 - ),
510 - );
511 - return recovered.value;
512 - });
513 -
474 return DesktopConnectionCatalogStore.of({
475 get: Effect.gen(function* () {
476 const document = yield* readDocument(fileSystem, catalogPath);
@@ -523,14 +483,13 @@ export const make = Effect.gen(function* () {
483 const decrypted = yield* decodeSecretBytes(catalogPath, document.value.encryptedCatalog).pipe(
484 Effect.flatMap((encryptedCatalog) =>
485 safeStorage.decryptString(encryptedCatalog).pipe(
526 - // CBC can decrypt with the wrong key without failing its padding check.
527 - Effect.tap((catalog) =>
528 - environment.platform === "darwin" || environment.platform === "linux"
529 - ? decodeNativeCatalogJson(catalog)
530 - : Effect.void,
531 - ),
532 - Effect.catch((cause) =>
533 - recoverPreviousIdentityCatalog(document.value, encryptedCatalog, cause),
486 + Effect.mapError(
487 + (cause) =>
488 + new DesktopConnectionCatalogStoreProtectionError({
489 + operation: "decrypt-catalog",
490 + catalogPath,
491 + cause,
492 + }),
493 ),
494 ),
495 ),
@@ -541,11 +500,10 @@ export const make = Effect.gen(function* () {
500 if (!(yield* encryptionAvailable)) {
501 return false;
502 }
544 - yield* writeCatalog(catalog).pipe(writeLock.withPermits(1));
503 + yield* writeCatalog(catalog);
504 return true;
505 }),
506 clear: fileSystem.remove(catalogPath, { force: true }).pipe(
548 - writeLock.withPermits(1),
507 Effect.catch((error) =>
508 Effect.logWarning("Could not clear the desktop connection catalog.", {
509 catalogPath,
apps/desktop/src/app/DesktopEnvironment.ts
+1 -11
@@ -15,10 +15,7 @@ import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
15 import * as DesktopConfig from "./DesktopConfig.ts";
16 import { resolveLinuxDesktopEntryName } from "./DesktopEarlyElectronStartup.ts";
17 import { resolveDesktopBaseDir, resolveDesktopStateDir } from "./DesktopStatePaths.ts";
18 -import {
19 - isNightlyDesktopVersion,
20 - resolveDefaultDesktopUpdateChannel,
21 -} from "../updates/updateChannels.ts";
18 +import { isNightlyDesktopVersion } from "../updates/updateChannels.ts";
19 import type { OtlpProtocol } from "@t3tools/shared/observability";
20
21 export interface MakeDesktopEnvironmentInput {
@@ -113,13 +110,6 @@ export function resolveDesktopAppBranding(input: {
110 };
111 }
112
116 -// Keep Chromium's encryption identity on the names shipped before branding changed.
117 -export function resolveDesktopSafeStorageName(appVersion: string): string {
118 - return resolveDefaultDesktopUpdateChannel(appVersion) === "nightly"
119 - ? "T3 Code (Nightly)"
120 - : "T3 Code (Alpha)";
121 -}
122 -
113 function normalizeDesktopArch(arch: string): DesktopRuntimeArch {
114 if (arch === "arm64") return "arm64";
115 if (arch === "x64") return "x64";
apps/desktop/src/app/DesktopPreReadyPlatform.test.ts
+2 -43
@@ -11,8 +11,6 @@ const {
11 hasSwitchMock,
12 registerSchemesMock,
13 setDesktopNameMock,
14 - setNameMock,
15 - appState,
14 mkdirSyncMock,
15 readFileSyncMock,
16 writeFileSyncMock,
@@ -24,8 +22,6 @@ const {
22 hasSwitchMock: vi.fn(),
23 registerSchemesMock: vi.fn(),
24 setDesktopNameMock: vi.fn(),
27 - setNameMock: vi.fn(),
28 - appState: { version: "0.0.37", isPackaged: true },
25 mkdirSyncMock: vi.fn(),
26 readFileSyncMock: vi.fn(),
27 writeFileSyncMock: vi.fn(),
@@ -36,11 +32,8 @@ const {
32 vi.mock("electron", () => ({
33 app: {
34 setDesktopName: setDesktopNameMock,
39 - setName: setNameMock,
40 - getVersion: () => appState.version,
41 - get isPackaged() {
42 - return appState.isPackaged;
43 - },
35 + getVersion: () => "0.0.37",
36 + isPackaged: true,
37 getAppPath: () => "/tmp/.mount_T3/resources/app.asar",
38 commandLine: {
39 appendSwitch: appendSwitchMock,
@@ -78,9 +71,6 @@ describe("DesktopPreReadyPlatform", () => {
71 hasSwitchMock.mockReset();
72 registerSchemesMock.mockReset();
73 setDesktopNameMock.mockReset();
81 - setNameMock.mockReset();
82 - appState.version = "0.0.37";
83 - appState.isPackaged = true;
74 mkdirSyncMock.mockReset();
75 readFileSyncMock.mockReset();
76 writeFileSyncMock.mockReset();
@@ -276,37 +266,6 @@ describe("DesktopPreReadyPlatform", () => {
266 ).pipe(Effect.ensuring(Effect.sync(() => vi.unstubAllEnvs())));
267 });
268
279 - it.effect.each([
280 - { platform: "linux" as const, version: "0.1.0", isPackaged: true },
281 - { platform: "darwin" as const, version: "0.1.1-preview.20261017.3", isPackaged: false },
282 - { platform: "win32" as const, version: "0.1.0", isPackaged: true },
283 - ])(
284 - "preserves the $platform encryption identity before startup yields",
285 - ({ platform, version, isPackaged }) => {
286 - appState.version = version;
287 - appState.isPackaged = isPackaged;
288 - getSwitchValueMock.mockReturnValue("");
289 - let appName = "T3 Code (Beta)";
290 - setNameMock.mockImplementation((name: string) => {
291 - appName = name;
292 - });
293 - return Effect.scoped(
294 - Effect.gen(function* () {
295 - const nameBeforeYield = Promise.resolve().then(() => appName);
296 - yield* Layer.build(
297 - DesktopPreReadyPlatform.layer.pipe(
298 - Layer.provide(Layer.succeed(HostProcess.Platform, platform)),
299 - ),
300 - );
301 - assert.equal(
302 - yield* Effect.promise(() => nameBeforeYield),
303 - platform === "win32" ? "T3 Code (Beta)" : "T3 Code (Alpha)",
304 - );
305 - }),
306 - );
307 - },
308 - );
309 -
269 it.effect("keeps startup available when the early desktop entry cannot be written", () => {
270 getSwitchValueMock.mockReturnValue("");
271 mkdirSyncMock.mockImplementation(() => {
apps/desktop/src/app/DesktopPreReadyPlatform.ts
+1 -6
@@ -10,7 +10,7 @@ import * as Electron from "electron";
10 import * as HostProcess from "@t3tools/shared/HostProcess";
11
12 import * as DesktopEarlyElectronStartup from "./DesktopEarlyElectronStartup.ts";
13 -import { resolveDesktopAppBranding, resolveDesktopSafeStorageName } from "./DesktopEnvironment.ts";
13 +import { resolveDesktopAppBranding } from "./DesktopEnvironment.ts";
14 import { renderUrlHandlerDesktopEntry } from "./DesktopLinuxUrlHandler.ts";
15 import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
16
@@ -54,11 +54,6 @@ export const make = Effect.gen(function* () {
54 const platform = yield* HostProcess.Platform;
55 const homeDirectory = yield* HostProcess.HomeDirectory;
56 return yield* Effect.sync((): DesktopPreReadyElectronOptions["Service"] => {
57 - // Chromium reads the safeStorage key's name before startup first yields.
58 - // DesktopAppIdentity's later rename only changes the branded app name.
59 - if (platform === "darwin" || platform === "linux") {
60 - Electron.app.setName(resolveDesktopSafeStorageName(Electron.app.getVersion()));
61 - }
57 const linuxPasswordStoreCommandLine =
58 platform === "linux"
59 ? readCommandLineSwitchValue(Electron.app.commandLine, "password-store")
apps/desktop/src/app/DesktopSafeStorageIdentity.ts deleted
-63
@@ -1,63 +0,0 @@
1 -import * as Context from "effect/Context";
2 -import * as Effect from "effect/Effect";
3 -import * as Layer from "effect/Layer";
4 -import * as Option from "effect/Option";
5 -import { ChildProcessSpawner } from "effect/process";
6 -
7 -import { decryptChromiumValue } from "../preview/BrowserImport/ChromiumCookies.ts";
8 -import { resolveChromiumKeys } from "../preview/BrowserImport/ChromiumKeys.ts";
9 -import * as DesktopEnvironment from "./DesktopEnvironment.ts";
10 -
11 -export class DesktopSafeStorageIdentity extends Context.Service<
12 - DesktopSafeStorageIdentity,
13 - {
14 - readonly decryptWithPreviousName: (
15 - encrypted: Uint8Array,
16 - ) => Effect.Effect<Option.Option<string>>;
17 - }
18 ->()("@t3tools/desktop/app/DesktopSafeStorageIdentity") {}
19 -
20 -const make = Effect.gen(function* () {
21 - const environment = yield* DesktopEnvironment.DesktopEnvironment;
22 - const services = yield* Effect.context<ChildProcessSpawner.ChildProcessSpawner>();
23 -
24 - const decryptWithPreviousName = Effect.fn("desktop.safeStorageIdentity.decryptWithPreviousName")(
25 - function* (encrypted: Uint8Array) {
26 - if (environment.platform !== "darwin" && environment.platform !== "linux") {
27 - return Option.none<string>();
28 - }
29 - if (
30 - DesktopEnvironment.resolveDesktopSafeStorageName(environment.appVersion) !==
31 - "T3 Code (Alpha)"
32 - ) {
33 - return Option.none<string>();
34 - }
35 - // Cookie imports also accept plaintext; safeStorage requires an OSCrypt prefix.
36 - const prefix = Buffer.from(encrypted.subarray(0, 3)).toString("latin1");
37 - if (prefix !== (environment.platform === "darwin" ? "v10" : "v11")) {
38 - return Option.none<string>();
39 - }
40 - const keys = yield* resolveChromiumKeys({
41 - platform: environment.platform,
42 - keychainService: "T3 Code (Beta) Safe Storage",
43 - keychainAccount: "T3 Code (Beta)",
44 - linuxSecretApplication: "T3 Code (Beta)",
45 - }).pipe(
46 - Effect.tapError((error) =>
47 - Effect.logWarning("Could not read the Beta safe storage key.", {
48 - reason: error.reason,
49 - }),
50 - ),
51 - Effect.option,
52 - );
53 - return Option.flatMapNullishOr(keys, (material) =>
54 - decryptChromiumValue(encrypted, material, "", undefined, environment.platform),
55 - );
56 - },
57 - Effect.provide(services),
58 - );
59 -
60 - return DesktopSafeStorageIdentity.of({ decryptWithPreviousName });
61 -});
62 -
63 -export const layer = Layer.effect(DesktopSafeStorageIdentity, make);
apps/desktop/src/main.ts
+1 -5
@@ -38,7 +38,6 @@ import * as DesktopAppActivation from "./app/DesktopAppActivation.ts";
38 import * as DesktopWebLinks from "./app/DesktopWebLinks.ts";
39 import * as DesktopAppIdentity from "./app/DesktopAppIdentity.ts";
40 import * as DesktopConnectionCatalogStore from "./app/DesktopConnectionCatalogStore.ts";
41 -import * as DesktopSafeStorageIdentity from "./app/DesktopSafeStorageIdentity.ts";
41 import * as DesktopClerk from "./app/DesktopClerk.ts";
42 import * as DesktopCliCommand from "./app/DesktopCliCommand.ts";
43 import * as DesktopApplicationMenu from "./window/DesktopApplicationMenu.ts";
@@ -147,10 +146,7 @@ const layerDesktopFoundation = Layer.mergeAll(
146 DesktopLegacyLocalStorage.layer,
147 DesktopAppSettings.layer,
148 DesktopClientSettings.layer,
150 - DesktopConnectionCatalogStore.layer.pipe(
151 - Layer.provideMerge(DesktopSavedEnvironments.layer),
152 - Layer.provide(DesktopSafeStorageIdentity.layer.pipe(Layer.provide(LinuxBrowserSecret.layer))),
153 - ),
149 + DesktopConnectionCatalogStore.layer.pipe(Layer.provideMerge(DesktopSavedEnvironments.layer)),
150 DesktopAssets.layer,
151 DesktopObservability.layer,
152 DesktopRendererHistory.layer,