Skip to content

Commit 2aa826c

Browse files
Propagate desktop branding to the web app
- Add desktop app branding IPC and preload bridge - Resolve build-stage labels from the packaged app version - Use injected branding in web UI with test coverage
1 parent a1271cb commit 2aa826c

9 files changed

Lines changed: 159 additions & 4 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { resolveDesktopAppBranding, resolveDesktopAppStageLabel } from "./appBranding";
4+
5+
describe("resolveDesktopAppStageLabel", () => {
6+
it("uses Dev in desktop development", () => {
7+
expect(
8+
resolveDesktopAppStageLabel({
9+
isDevelopment: true,
10+
appVersion: "0.0.17-nightly.20260414.1",
11+
}),
12+
).toBe("Dev");
13+
});
14+
15+
it("uses Nightly for packaged nightly builds", () => {
16+
expect(
17+
resolveDesktopAppStageLabel({
18+
isDevelopment: false,
19+
appVersion: "0.0.17-nightly.20260414.1",
20+
}),
21+
).toBe("Nightly");
22+
});
23+
24+
it("uses Alpha for packaged stable builds", () => {
25+
expect(
26+
resolveDesktopAppStageLabel({
27+
isDevelopment: false,
28+
appVersion: "0.0.17",
29+
}),
30+
).toBe("Alpha");
31+
});
32+
});
33+
34+
describe("resolveDesktopAppBranding", () => {
35+
it("returns a complete desktop branding payload", () => {
36+
expect(
37+
resolveDesktopAppBranding({
38+
isDevelopment: false,
39+
appVersion: "0.0.17-nightly.20260414.1",
40+
}),
41+
).toEqual({
42+
baseName: "T3 Code",
43+
stageLabel: "Nightly",
44+
displayName: "T3 Code (Nightly)",
45+
});
46+
});
47+
});

‎apps/desktop/src/appBranding.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { DesktopAppBranding, DesktopAppStageLabel } from "@t3tools/contracts";
2+
3+
const APP_BASE_NAME = "T3 Code";
4+
const NIGHTLY_VERSION_PATTERN = /-nightly\.\d{8}\.\d+$/;
5+
6+
export function resolveDesktopAppStageLabel(input: {
7+
readonly isDevelopment: boolean;
8+
readonly appVersion: string;
9+
}): DesktopAppStageLabel {
10+
if (input.isDevelopment) {
11+
return "Dev";
12+
}
13+
14+
return NIGHTLY_VERSION_PATTERN.test(input.appVersion) ? "Nightly" : "Alpha";
15+
}
16+
17+
export function resolveDesktopAppBranding(input: {
18+
readonly isDevelopment: boolean;
19+
readonly appVersion: string;
20+
}): DesktopAppBranding {
21+
const stageLabel = resolveDesktopAppStageLabel(input);
22+
return {
23+
baseName: APP_BASE_NAME,
24+
stageLabel,
25+
displayName: `${APP_BASE_NAME} (${stageLabel})`,
26+
};
27+
}

‎apps/desktop/src/main.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { MenuItemConstructorOptions } from "electron";
2222
import type {
2323
ClientSettings,
2424
DesktopTheme,
25+
DesktopAppBranding,
2526
DesktopServerExposureMode,
2627
DesktopServerExposureState,
2728
DesktopUpdateChannel,
@@ -71,6 +72,7 @@ import {
7172
reduceDesktopUpdateStateOnUpdateAvailable,
7273
} from "./updateMachine";
7374
import { isArm64HostRunningIntelBuild, resolveDesktopRuntimeInfo } from "./runtimeArch";
75+
import { resolveDesktopAppBranding } from "./appBranding";
7476

7577
syncShellEnvironment();
7678

@@ -86,6 +88,7 @@ const UPDATE_SET_CHANNEL_CHANNEL = "desktop:update-set-channel";
8688
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
8789
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
8890
const UPDATE_CHECK_CHANNEL = "desktop:update-check";
91+
const GET_APP_BRANDING_CHANNEL = "desktop:get-app-branding";
8992
const GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL = "desktop:get-local-environment-bootstrap";
9093
const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings";
9194
const SET_CLIENT_SETTINGS_CHANNEL = "desktop:set-client-settings";
@@ -104,7 +107,11 @@ const SAVED_ENVIRONMENT_REGISTRY_PATH = Path.join(STATE_DIR, "saved-environments
104107
const DESKTOP_SCHEME = "t3";
105108
const ROOT_DIR = Path.resolve(__dirname, "../../..");
106109
const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
107-
const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
110+
const desktopAppBranding: DesktopAppBranding = resolveDesktopAppBranding({
111+
isDevelopment,
112+
appVersion: app.getVersion(),
113+
});
114+
const APP_DISPLAY_NAME = desktopAppBranding.displayName;
108115
const APP_USER_MODEL_ID = isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code";
109116
const LINUX_DESKTOP_ENTRY_NAME = isDevelopment ? "t3code-dev.desktop" : "t3code.desktop";
110117
const LINUX_WM_CLASS = isDevelopment ? "t3code-dev" : "t3code";
@@ -1516,6 +1523,11 @@ async function stopBackendAndWaitForExit(timeoutMs = 5_000): Promise<void> {
15161523
}
15171524

15181525
function registerIpcHandlers(): void {
1526+
ipcMain.removeAllListeners(GET_APP_BRANDING_CHANNEL);
1527+
ipcMain.on(GET_APP_BRANDING_CHANNEL, (event) => {
1528+
event.returnValue = desktopAppBranding;
1529+
});
1530+
15191531
ipcMain.removeAllListeners(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL);
15201532
ipcMain.on(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL, (event) => {
15211533
event.returnValue = {

‎apps/desktop/src/preload.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const UPDATE_SET_CHANNEL_CHANNEL = "desktop:update-set-channel";
1313
const UPDATE_CHECK_CHANNEL = "desktop:update-check";
1414
const UPDATE_DOWNLOAD_CHANNEL = "desktop:update-download";
1515
const UPDATE_INSTALL_CHANNEL = "desktop:update-install";
16+
const GET_APP_BRANDING_CHANNEL = "desktop:get-app-branding";
1617
const GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL = "desktop:get-local-environment-bootstrap";
1718
const GET_CLIENT_SETTINGS_CHANNEL = "desktop:get-client-settings";
1819
const SET_CLIENT_SETTINGS_CHANNEL = "desktop:set-client-settings";
@@ -25,6 +26,13 @@ const GET_SERVER_EXPOSURE_STATE_CHANNEL = "desktop:get-server-exposure-state";
2526
const SET_SERVER_EXPOSURE_MODE_CHANNEL = "desktop:set-server-exposure-mode";
2627

2728
contextBridge.exposeInMainWorld("desktopBridge", {
29+
getAppBranding: () => {
30+
const result = ipcRenderer.sendSync(GET_APP_BRANDING_CHANNEL);
31+
if (typeof result !== "object" || result === null) {
32+
return null;
33+
}
34+
return result as ReturnType<DesktopBridge["getAppBranding"]>;
35+
},
2836
getLocalEnvironmentBootstrap: () => {
2937
const result = ipcRenderer.sendSync(GET_LOCAL_ENVIRONMENT_BOOTSTRAP_CHANNEL);
3038
if (typeof result !== "object" || result === null) {

‎apps/web/src/branding.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { afterEach, describe, expect, it, vi } from "vitest";
2+
3+
const originalWindow = globalThis.window;
4+
5+
afterEach(() => {
6+
vi.resetModules();
7+
8+
if (originalWindow === undefined) {
9+
Reflect.deleteProperty(globalThis, "window");
10+
return;
11+
}
12+
13+
globalThis.window = originalWindow;
14+
});
15+
16+
describe("branding", () => {
17+
it("uses injected desktop branding when available", async () => {
18+
Object.defineProperty(globalThis, "window", {
19+
configurable: true,
20+
value: {
21+
desktopBridge: {
22+
getAppBranding: () => ({
23+
baseName: "T3 Code",
24+
stageLabel: "Nightly",
25+
displayName: "T3 Code (Nightly)",
26+
}),
27+
},
28+
},
29+
});
30+
31+
const branding = await import("./branding");
32+
33+
expect(branding.APP_BASE_NAME).toBe("T3 Code");
34+
expect(branding.APP_STAGE_LABEL).toBe("Nightly");
35+
expect(branding.APP_DISPLAY_NAME).toBe("T3 Code (Nightly)");
36+
});
37+
});

‎apps/web/src/branding.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
export const APP_BASE_NAME = "T3 Code";
2-
export const APP_STAGE_LABEL = import.meta.env.DEV ? "Dev" : "Alpha";
3-
export const APP_DISPLAY_NAME = `${APP_BASE_NAME} (${APP_STAGE_LABEL})`;
1+
import type { DesktopAppBranding } from "@t3tools/contracts";
2+
3+
function readInjectedDesktopAppBranding(): DesktopAppBranding | null {
4+
if (typeof window === "undefined") {
5+
return null;
6+
}
7+
8+
return window.desktopBridge?.getAppBranding?.() ?? null;
9+
}
10+
11+
const injectedDesktopAppBranding = readInjectedDesktopAppBranding();
12+
13+
export const APP_BASE_NAME = injectedDesktopAppBranding?.baseName ?? "T3 Code";
14+
export const APP_STAGE_LABEL =
15+
injectedDesktopAppBranding?.stageLabel ?? (import.meta.env.DEV ? "Dev" : "Alpha");
16+
export const APP_DISPLAY_NAME =
17+
injectedDesktopAppBranding?.displayName ?? `${APP_BASE_NAME} (${APP_STAGE_LABEL})`;
418
export const APP_VERSION = import.meta.env.APP_VERSION || "0.0.0";

‎apps/web/src/components/settings/SettingsPanels.browser.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ const createDesktopBridgeStub = (overrides?: {
279279
};
280280

281281
return {
282+
getAppBranding: vi.fn().mockReturnValue(null),
282283
getLocalEnvironmentBootstrap: () => ({
283284
label: "Local environment",
284285
httpBaseUrl: "http://127.0.0.1:3773",

‎apps/web/src/localApi.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ function createLocalStorageStub(): Storage {
157157

158158
function makeDesktopBridge(overrides: Partial<DesktopBridge> = {}): DesktopBridge {
159159
return {
160+
getAppBranding: () => null,
160161
getLocalEnvironmentBootstrap: () => null,
161162
getClientSettings: async () => null,
162163
setClientSettings: async () => undefined,

‎packages/contracts/src/ipc.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ export type DesktopUpdateStatus =
7474
export type DesktopRuntimeArch = "arm64" | "x64" | "other";
7575
export type DesktopTheme = "light" | "dark" | "system";
7676
export type DesktopUpdateChannel = "latest" | "nightly";
77+
export type DesktopAppStageLabel = "Alpha" | "Dev" | "Nightly";
78+
79+
export interface DesktopAppBranding {
80+
baseName: string;
81+
stageLabel: DesktopAppStageLabel;
82+
displayName: string;
83+
}
7784

7885
export interface DesktopRuntimeInfo {
7986
hostArch: DesktopRuntimeArch;
@@ -134,6 +141,7 @@ export interface DesktopServerExposureState {
134141
}
135142

136143
export interface DesktopBridge {
144+
getAppBranding: () => DesktopAppBranding | null;
137145
getLocalEnvironmentBootstrap: () => DesktopEnvironmentBootstrap | null;
138146
getClientSettings: () => Promise<ClientSettings | null>;
139147
setClientSettings: (settings: ClientSettings) => Promise<void>;

0 commit comments

Comments
 (0)