Skip to content

Commit c37294d

Browse files
ZytriuNksfork-maintainer
andauthored
fork: per-productName desktop identity (Alpha / Experimental / Dev) (#10)
* chore(fork): per-productName NSIS install-dir override + uninstall hook Fork builds of this branch install to D:\t3code\<stage>\<productName>\ instead of %LOCALAPPDATA%\Programs\<productName>\, so Alpha, Experimental, and Dev coexist on the same machine. The hook is emitted from scripts/build-desktop-artifact.ts via a per-stage install-dir-override.nsh that runs in customInit (after which SetOutPath sees the overridden $INSTDIR), and customUnInstallCheck / customUnInstallCheckCurrentUser short-circuit handleUninstallResult so the prior-version uninstaller exit code no longer triggers SetErrorLevel 2 / Quit. Without these hooks, silent install /S against an existing fork build falls into installUtil.nsh's UninstallLoop, retries the previous uninstaller five times, and finally surfaces the appCannotBeClosed dialog with /SD IDCANCEL. Built and tested on Windows via corepack pnpm dist:desktop:win:x64 with T3CODE_DESKTOP_VERSION=0.0.42-fork-1. Model: Claude (pi-coding-agent). * refactor(fork): derive desktop runtime identity from productName The launcher previously hard-coded T3 Code (Experimental) / t3code-experimental across appId, URL scheme, appUserModelId, Chromium userData, NSIS INSTDIR, and t3Home. With per-productName builds (Alpha / Experimental / Dev) installed side by side, each of those values is now resolved from the packaged app.asar/package.json productName so that Alpha gets the historical t3code identity, Experimental keeps t3code-experimental, and Dev gets t3code-dev, while sharing the same source tree. Touches DesktopApp / DesktopAppIdentity / DesktopClerk / DesktopEarlyElectronStartup / DesktopEnvironment / DesktopLinuxUrlHandler / DesktopPreReadyPlatform / DesktopStatePaths / DesktopUserData / DesktopBackendConfiguration / ElectronApp / ElectronProtocol / DesktopWindow / main.ts, plus the launcher script and its tests. New per-productName derivation tables live next to where each value is consumed; build-desktop-artifact.ts remains the single source of truth for the install-time side of the same map. Verified via vp test run across the seven touched suites (62 tests pass) and by running the three productName builds through dist:desktop:win:x64 with T3CODE_DESKTOP_VERSION=0.0.42-fork-1; installed side-by-side in D:\t3code\alpha, D:\t3code\experimental, D:\t3code\dev with isolated Chromium userData and t3Home directories. Model: Claude (pi-coding-agent). * chore(fork): add silent install helper for per-productName desktop builds scripts/fork-build/install-fork.ps1 strips the HKCU\...\Uninstall key for the chosen productName before invoking the NSIS installer with /S. With no prior uninstall string for installOldVersion to find, the NSIS UninstallLoop in installUtil.nsh is skipped entirely, so the appCannotBeClosed dialog never appears and silent install completes on the first try without losing user data in ~/.t3-<stage>/userdata/. Supports -Stage Alpha / Experimental / Dev / All, optional -Force to stop running T3 Code processes first, and optional -InstallerPath to override the default release/\T3-Code-T3Code<Stage>-*.exe glob. Docs in docs/operations/fork-build-and-install.md walk through identity derivation, build steps, install flow, and data migration for the three side-by-side productName builds. Model: Claude (pi-coding-agent). --------- Co-authored-by: fork-maintainer <fork-maintainer@local>
1 parent 510a734 commit c37294d

24 files changed

Lines changed: 708 additions & 65 deletions

‎apps/desktop/scripts/electron-launcher.mjs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,31 @@ const repoRoot = NodePath.resolve(desktopDir, "..", "..");
1515
const devBundleIdSuffix = NodePath.basename(repoRoot)
1616
.toLowerCase()
1717
.replaceAll(/[^a-z0-9]+/g, "");
18-
export const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Experimental)";
18+
// Build stage identity is derived from apps/desktop/package.json's productName
19+
// so the Alpha and Experimental launchers do not collide on protocol scheme
20+
// or app bundle id when both are installed on the same machine.
21+
import * as NodeFS from "node:fs";
22+
import * as NodePath from "node:path";
23+
const packageJsonPath = NodePath.join(desktopDir, "package.json");
24+
const packageJson = JSON.parse(NodeFS.readFileSync(packageJsonPath, "utf8"));
25+
const stageProductName = isDevelopment
26+
? "T3 Code (Dev)"
27+
: (packageJson.productName ?? "T3 Code (Experimental)");
28+
const STAGE_IDENTITY =
29+
stageProductName === "T3 Code (Alpha)"
30+
? {
31+
appBundleId: "com.t3tools.t3code",
32+
protocolSchemes: ["t3code"],
33+
}
34+
: {
35+
appBundleId: "com.t3tools.t3code.experimental",
36+
protocolSchemes: ["t3code-experimental"],
37+
};
38+
export const APP_DISPLAY_NAME = stageProductName;
1939
export const APP_BUNDLE_ID = isDevelopment
2040
? `com.t3tools.t3code.dev.${devBundleIdSuffix || "local"}`
21-
: "com.t3tools.t3code.experimental.pi";
22-
export const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code-experimental"];
41+
: STAGE_IDENTITY.appBundleId;
42+
export const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : STAGE_IDENTITY.protocolSchemes;
2343
const LAUNCHER_VERSION = 19;
2444
const developmentMacIconPngPath = NodePath.join(
2545
repoRoot,

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
describe("electron development launcher", () => {
2222
it("uses the Experimental identity for packaged launches", () => {
2323
assert.equal(APP_DISPLAY_NAME, "T3 Code (Experimental)");
24-
assert.equal(APP_BUNDLE_ID, "com.t3tools.t3code.experimental.pi");
24+
assert.equal(APP_BUNDLE_ID, "com.t3tools.t3code.experimental");
2525
assert.deepEqual(APP_PROTOCOL_SCHEMES, ["t3code-experimental"]);
2626
});
2727

‎apps/desktop/src/app/DesktopApp.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ const bootstrap = Effect.gen(function* () {
171171
// rather than through the local backend, so the window can open without one.
172172
const electronProtocol = yield* ElectronProtocol.ElectronProtocol;
173173
yield* electronProtocol.registerDesktopProtocol({
174-
scheme: ElectronProtocol.getDesktopScheme(environment.isDevelopment),
174+
scheme: ElectronProtocol.getDesktopScheme({
175+
isDevelopment: environment.isDevelopment,
176+
appName: environment.appName ?? "T3 Code (Experimental)",
177+
}),
175178
...(environment.isDevelopment
176179
? { targetOrigin: Option.getOrThrow(environment.devServerUrl) }
177180
: { assetDirectory: environment.clientAssetsDir }),

‎apps/desktop/src/app/DesktopAppIdentity.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ export const make = Effect.gen(function* () {
8585
return commitHash;
8686
});
8787

88-
const userDataPath = DesktopUserData.resolveUserDataPath(environment).pipe(
89-
Effect.provide(userDataContext),
90-
);
88+
const userDataPath = DesktopUserData.resolveUserDataPath({
89+
appDataDirectory: environment.appDataDirectory,
90+
isDevelopment: environment.isDevelopment,
91+
platform: environment.platform,
92+
appName: environment.appName ?? "T3 Code (Experimental)",
93+
}).pipe(Effect.provide(userDataContext));
9194

9295
const configure = Effect.gen(function* () {
9396
const commitHash = yield* resolveAboutCommitHash;

‎apps/desktop/src/app/DesktopClerk.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ export const desktopClerkFrontendApiHostname = resolveDesktopClerkFrontendApiHos
7272
: __T3CODE_BUILD_CLERK_PUBLISHABLE_KEY__,
7373
);
7474

75-
function createDesktopClerkBridge(stateDir: string, isDevelopment: boolean) {
75+
function createDesktopClerkBridge(stateDir: string, isDevelopment: boolean, appName: string) {
7676
return createClerkBridge({
7777
storage: storage({ path: stateDir }),
7878
passkeys: true,
7979
renderer: {
80-
scheme: ElectronProtocol.getDesktopScheme(isDevelopment),
80+
scheme: ElectronProtocol.getDesktopScheme({ isDevelopment, appName }),
8181
host: ElectronProtocol.DESKTOP_HOST,
8282
},
8383
});
@@ -89,12 +89,22 @@ export const make = Effect.gen(function* () {
8989
const electronApp = yield* ElectronApp.ElectronApp;
9090

9191
// The SDK bridge acquires Electron's profile-scoped single-instance lock.
92-
const userDataPath = yield* DesktopUserData.resolveUserDataPath(environment);
92+
const userDataPath = yield* DesktopUserData.resolveUserDataPath({
93+
appDataDirectory: environment.appDataDirectory,
94+
isDevelopment: environment.isDevelopment,
95+
platform: environment.platform,
96+
appName: environment.appName ?? "T3 Code (Experimental)",
97+
});
9398
yield* electronApp.setPath("userData", userDataPath);
9499

95100
const bridge = yield* Effect.acquireRelease(
96101
Effect.try({
97-
try: () => createDesktopClerkBridge(environment.stateDir, environment.isDevelopment),
102+
try: () =>
103+
createDesktopClerkBridge(
104+
environment.stateDir,
105+
environment.isDevelopment,
106+
environment.appName ?? "T3 Code (Experimental)",
107+
),
98108
catch: (cause) =>
99109
new DesktopClerkBridgeInitializationError({
100110
stateDir: environment.stateDir,

‎apps/desktop/src/app/DesktopEarlyElectronStartup.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ interface EarlyDesktopSettingsInput {
2222
readonly readFileString: (path: string) => string;
2323
}
2424

25-
type EarlyLinuxElectronOptionsInput = EarlyDesktopSettingsInput;
25+
interface EarlyLinuxElectronOptionsInput extends EarlyDesktopSettingsInput {
26+
readonly appName?: string;
27+
}
2628

2729
export interface EarlyLinuxElectronOptions {
2830
readonly isDevelopment: boolean;
@@ -31,10 +33,12 @@ export interface EarlyLinuxElectronOptions {
3133
readonly passwordStore: LinuxPasswordStoreSwitch | null;
3234
}
3335

34-
export const resolveLinuxDesktopEntryName = (isDevelopment: boolean): string =>
36+
export const resolveLinuxDesktopEntryName = (isDevelopment: boolean, appName?: string): string =>
3537
isDevelopment
3638
? "com.t3tools.T3Code.Development.desktop"
37-
: "com.t3tools.T3Code.Experimental.desktop";
39+
: appName === "T3 Code (Alpha)"
40+
? "com.t3tools.T3Code.desktop"
41+
: "com.t3tools.T3Code.Experimental.desktop";
3842

3943
const trimNonEmpty = (value: string | undefined): string | null => {
4044
const trimmed = value?.trim();
@@ -55,12 +59,14 @@ function resolveEarlyDesktopSettingsPath(input: {
5559
readonly env: NodeJS.ProcessEnv;
5660
readonly homeDirectory: string;
5761
readonly joinPath: JoinPath;
62+
readonly appName?: string;
5863
}): string {
5964
const t3Home = Option.fromUndefinedOr(input.env.T3CODE_HOME);
6065
const baseDir = resolveDesktopBaseDir({
6166
homeDirectory: input.homeDirectory,
6267
joinPath: input.joinPath,
6368
t3Home,
69+
appName: input.appName,
6470
});
6571
const stateDir = resolveDesktopStateDir({
6672
baseDir,
@@ -90,8 +96,12 @@ export function resolveEarlyLinuxElectronOptions(
9096
const isDevelopment = isDevelopmentEnvironment(input.env);
9197
return {
9298
isDevelopment,
93-
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code-experimental",
94-
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
99+
linuxWmClass: isDevelopment
100+
? "t3code-dev"
101+
: input.appName === "T3 Code (Alpha)"
102+
? "t3code"
103+
: "t3code-experimental",
104+
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment, input.appName),
95105
passwordStore: resolveLinuxPasswordStoreSwitch({
96106
preference,
97107
env: input.env,

‎apps/desktop/src/app/DesktopEnvironment.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe("DesktopEnvironment", () => {
165165

166166
assert.equal(development.stateDir, "/Users/alice/.t3-experimental/dev");
167167
assert.equal(production.stateDir, "/Users/alice/.t3-experimental/userdata");
168-
assert.equal(production.appUserModelId, "com.t3tools.t3code.experimental.pi");
168+
assert.equal(production.appUserModelId, "com.t3tools.t3code.experimental");
169169
}),
170170
);
171171

‎apps/desktop/src/app/DesktopEnvironment.ts‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface MakeDesktopEnvironmentInput {
2323
readonly platform: NodeJS.Platform;
2424
readonly processArch: string;
2525
readonly appVersion: string;
26+
readonly appName?: string;
2627
readonly appPath: string;
2728
readonly isPackaged: boolean;
2829
readonly resourcesPath: string;
@@ -39,6 +40,7 @@ export class DesktopEnvironment extends Context.Service<
3940
readonly isPackaged: boolean;
4041
readonly isDevelopment: boolean;
4142
readonly appVersion: string;
43+
readonly appName?: string;
4244
readonly appPath: string;
4345
readonly resourcesPath: string;
4446
readonly homeDirectory: string;
@@ -94,18 +96,25 @@ const APP_BASE_NAME = "T3 Code";
9496

9597
function resolveDesktopAppStageLabel(input: {
9698
readonly isDevelopment: boolean;
97-
readonly appVersion: string;
99+
readonly appName: string;
98100
}): DesktopAppStageLabel {
99101
if (input.isDevelopment) {
100102
return "Dev";
101103
}
102-
104+
// Derive the stage from Electron's reported app name (which on packaged
105+
// builds equals `productName` from package.json). Alpha and Experimental
106+
// builds both stage as themselves; any unrecognized name falls back to
107+
// Experimental to preserve the historical default.
108+
if (input.appName === "T3 Code (Alpha)") {
109+
return "Alpha";
110+
}
103111
return "Experimental";
104112
}
105113

106114
export function resolveDesktopAppBranding(input: {
107115
readonly isDevelopment: boolean;
108116
readonly appVersion: string;
117+
readonly appName: string;
109118
}): DesktopAppBranding {
110119
const stageLabel = resolveDesktopAppStageLabel(input);
111120
return {
@@ -153,6 +162,12 @@ const make = Effect.fn("desktop.environment.make")(function* (
153162
const homeDirectory = input.homeDirectory;
154163
const devServerUrl = config.devServerUrl;
155164
const isDevelopment = Option.isSome(devServerUrl);
165+
// Tests and dev wiring rarely know the packaged productName; defaulting to
166+
// Experimental keeps the historical behavior intact. The packaged launcher
167+
// always sets `appName` from Electron.app.getName() (which on packaged
168+
// builds is the staged `productName`), so production code never relies on
169+
// this fallback.
170+
const appName = input.appName ?? "T3 Code (Experimental)";
156171
const appDataDirectory =
157172
input.platform === "win32"
158173
? Option.getOrElse(config.appDataDirectory, () =>
@@ -165,6 +180,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
165180
homeDirectory,
166181
joinPath: path.join,
167182
t3Home: config.t3Home,
183+
appName: input.appName,
168184
});
169185
const rootDir = path.resolve(input.dirname, "../../..");
170186
const appRoot = input.isPackaged ? input.appPath : rootDir;
@@ -175,6 +191,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
175191
const branding = resolveDesktopAppBranding({
176192
isDevelopment,
177193
appVersion: input.appVersion,
194+
appName,
178195
});
179196
const displayName = branding.displayName;
180197
const stateDir = resolveDesktopStateDir({
@@ -197,6 +214,7 @@ const make = Effect.fn("desktop.environment.make")(function* (
197214
isPackaged: input.isPackaged,
198215
isDevelopment,
199216
appVersion: input.appVersion,
217+
appName,
200218
appPath: input.appPath,
201219
resourcesPath,
202220
homeDirectory,
@@ -232,10 +250,18 @@ const make = Effect.fn("desktop.environment.make")(function* (
232250
branding,
233251
displayName,
234252
appUserModelId: Option.getOrElse(config.appUserModelIdOverride, () =>
235-
isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code.experimental.pi",
253+
isDevelopment
254+
? "com.t3tools.t3code.dev"
255+
: appName === "T3 Code (Alpha)"
256+
? "com.t3tools.t3code"
257+
: "com.t3tools.t3code.experimental",
236258
),
237-
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment),
238-
linuxWmClass: isDevelopment ? "t3code-dev" : "t3code-experimental",
259+
linuxDesktopEntryName: resolveLinuxDesktopEntryName(isDevelopment, appName),
260+
linuxWmClass: isDevelopment
261+
? "t3code-dev"
262+
: appName === "T3 Code (Alpha)"
263+
? "t3code"
264+
: "t3code-experimental",
239265
linuxApplicationsDir,
240266
appImagePath: config.appImagePath,
241267
defaultDesktopSettings: DesktopAppSettings.resolveDefaultDesktopSettings(input.appVersion),

‎apps/desktop/src/app/DesktopLinuxUrlHandler.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export const make = Effect.gen(function* () {
9696
const fileSystem = yield* FileSystem.FileSystem;
9797
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
9898

99-
const scheme = ElectronProtocol.getDesktopScheme(environment.isDevelopment);
99+
const scheme = ElectronProtocol.getDesktopScheme({
100+
isDevelopment: environment.isDevelopment,
101+
appName: environment.appName ?? "T3 Code (Experimental)",
102+
});
100103
const desktopEntryPath = environment.path.join(
101104
environment.linuxApplicationsDir,
102105
environment.linuxDesktopEntryName,

‎apps/desktop/src/app/DesktopPreReadyPlatform.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,30 @@ export const resolveEarlyLinuxElectronOptionsFromProcess =
3838
homeDirectory: NodeOS.homedir(),
3939
joinPath: NodePath.posix.join,
4040
readFileString: (path) => NodeFS.readFileSync(path, "utf8"),
41+
appName: resolvePackagedProductName(),
4142
});
4243

44+
function resolvePackagedProductName(): string {
45+
// In packaged Linux builds the productName from `package.json` decides the
46+
// XDG WM class and desktop entry name; reading it before Electron fully
47+
// boots avoids a race where the .desktop entry resolves before the runtime
48+
// identity is set. Dev mode always uses the "T3 Code (Dev)" identity.
49+
if (Electron.app.isPackaged) {
50+
try {
51+
const packageJsonPath = NodePath.join(Electron.app.getAppPath(), "package.json");
52+
const parsed = JSON.parse(NodeFS.readFileSync(packageJsonPath, "utf8")) as {
53+
productName?: unknown;
54+
};
55+
if (typeof parsed.productName === "string") {
56+
return parsed.productName;
57+
}
58+
} catch {
59+
// Fall through to the default below.
60+
}
61+
}
62+
return "T3 Code (Experimental)";
63+
}
64+
4365
export class DesktopPreReadyElectronOptions extends Context.Service<
4466
DesktopPreReadyElectronOptions,
4567
{
@@ -73,10 +95,14 @@ export const make = Effect.gen(function* () {
7395
renderUrlHandlerDesktopEntry({
7496
displayName: resolveDesktopAppBranding({
7597
isDevelopment: linux.isDevelopment,
98+
appName: resolvePackagedProductName(),
7699
appVersion: Electron.app.getVersion(),
77100
}).displayName,
78101
execTarget: process.env.APPIMAGE?.trim() || process.execPath,
79-
scheme: ElectronProtocol.getDesktopScheme(linux.isDevelopment),
102+
scheme: ElectronProtocol.getDesktopScheme({
103+
isDevelopment: linux.isDevelopment,
104+
appName: resolvePackagedProductName(),
105+
}),
80106
}),
81107
"utf8",
82108
);

0 commit comments

Comments
 (0)