fix(desktop): allow V1 and V2 to run concurrently #12480
Mergedjuliusmarmingemerged 6 commits into
t3code/codex-turn-mapping fromrefs/pull/12480/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/app/initializeV2DesktopProfile.ts line 42OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +22,21 @@22+ const path = yield* Path.Path;23+ yield* Effect.gen(function* () {24+ const destinationState = path.join(destinationPath, "Local State");25+ if (yield* fs.exists(destinationState)) return;26+ const legacyPath = path.join(appDataDirectory, legacyUserDataDirName);27+ const sourcePath = (yield* fs.exists(legacyPath))28+ ? legacyPath29+ : path.join(appDataDirectory, "t3code");30+ const sourceState = path.join(sourcePath, "Local State");31+ if (!(yield* fs.exists(sourceState))) return;32+ const state = yield* fs.readFileString(sourceState);33+ yield* fs.makeDirectory(destinationPath, { recursive: true });34+ yield* fs35+ .writeFileString(destinationState, state, { flag: "wx" })36+ .pipe(37+ Effect.catch((error) =>38+ error.reason._tag === "AlreadyExists" ? Effect.void : Effect.fail(error),39+ ),40+ );41+ }).pipe(42+ Effect.mapError((cause) => new V2DesktopProfileInitializationError({ destinationPath, cause })),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/app/DesktopClerk.ts lines 93 to 95OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -88,10 +89,7 @@8889 const environment = yield* DesktopEnvironment.DesktopEnvironment;8990 const electronApp = yield* ElectronApp.ElectronApp;909191- // Electron scopes the single-instance lock to the userData directory and92- // creates that directory when the lock is acquired. The SDK bridge takes93- // the lock at creation, so userData must already point at the real94- // directory here — under the default productName-derived path, acquiring95- // the lock would create "T3 Code (Alpha)" and make the legacy-install96- // detection in resolveUserDataPath match on fresh installs.97- const userDataPath = yield* DesktopAppIdentity.resolveUserDataPath;92+ // The SDK bridge acquires Electron's profile-scoped single-instance lock.93+ const userDataPath = yield* DesktopUserData.resolveUserDataPath(environment).pipe(94+ Effect.provideService(Path.Path, environment.path),95+ );apps/desktop/src/app/DesktopAppIdentity.ts lines 87 to 89OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -112,7 +84,6 @@11284 return commitHash;11385 });11486115- const userDataPath = resolveUserDataPath.pipe(116- Effect.provide(117- yield* Effect.context<DesktopEnvironment.DesktopEnvironment | FileSystem.FileSystem>(),118- ),87+ const userDataPath = DesktopUserData.resolveUserDataPath(environment).pipe(88+ Effect.provideService(FileSystem.FileSystem, fileSystem),89+ Effect.provideService(Path.Path, environment.path),
- apps/desktop/src/app/DesktopUserData.ts lines 63 to 67OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+ const legacyPath = path.join(input.appDataDirectory, names.legacy);48+ const inspect = (resourcePath: string) =>49+ fs50+ .exists(resourcePath)51+ .pipe(52+ Effect.mapError((cause) =>53+ DesktopUserDataInitializationError.fromFileSystem(cause, "inspect", resourcePath),54+ ),55+ );56+ if (input.isDevelopment) {57+ return (yield* inspect(legacyPath)) ? legacyPath : destinationPath;58+ }59+ // Chromium databases require their own profile for each running version.60+ if (input.platform !== "win32") return destinationPath;61+ const destinationState = path.join(destinationPath, "Local State");62+ if (yield* inspect(destinationState)) return destinationPath;63+ const sourcePath = (yield* inspect(legacyPath))64+ ? legacyPath65+ : path.join(input.appDataDirectory, "t3code");66+ const sourceState = path.join(sourcePath, "Local State");67+ if (!(yield* inspect(sourceState))) return destinationPath;
- @@ -0,0 +40,21 @@40+ }) {41+ const fs = yield* FileSystem.FileSystem;42+ const path = yield* Path.Path;43+ const names = input.isDevelopment44+ ? { current: "t3code-dev", legacy: "T3 Code (Dev)" }45+ : { current: "t3code-v2", legacy: "T3 Code (Alpha)" };46+ const destinationPath = path.join(input.appDataDirectory, names.current);47+ const legacyPath = path.join(input.appDataDirectory, names.legacy);48+ const inspect = (resourcePath: string) =>49+ fs50+ .exists(resourcePath)51+ .pipe(52+ Effect.mapError((cause) =>53+ DesktopUserDataInitializationError.fromFileSystem(cause, "inspect", resourcePath),54+ ),55+ );56+ if (input.isDevelopment) {57+ return (yield* inspect(legacyPath)) ? legacyPath : destinationPath;58+ }59+ // Chromium databases require their own profile for each running version.60+ if (input.platform !== "win32") return destinationPath;
juliusmarminge merged this84afa46
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed