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 25, 11:00 UTC
Show desktop commit hash in About panel
- embed `t3codeCommitHash` into staged desktop package metadata during builds - resolve commit hash from env/package/git and display it as About panel version
Julius Marminge committed
Mar 2, 2026 at 18:05 UTC
e7790490f16592d9b0a5418201921a58b1fb5fe7
2 files changed
+79
-1
apps/desktop/src/main.ts
+59
-1
@@ -1,4 +1,4 @@
1
-import { spawn, type ChildProcess } from "node:child_process";
1
+import { execFileSync, spawn, type ChildProcess } from "node:child_process";
2
import { randomBytes } from "node:crypto";
3
import fs from "node:fs";
4
import net from "node:net";
@@ -26,6 +26,8 @@ const ROOT_DIR = path.resolve(__dirname, "../../..");
26
const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
27
const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
28
const APP_USER_MODEL_ID = "com.t3tools.t3code";
29
+const COMMIT_HASH_PATTERN = /^[0-9a-f]{7,40}$/i;
30
+const COMMIT_HASH_DISPLAY_LENGTH = 12;
31
32
let mainWindow: BrowserWindow | null = null;
33
let backendProcess: ChildProcess | null = null;
@@ -36,6 +38,7 @@ let restartAttempt = 0;
38
let restartTimer: ReturnType<typeof setTimeout> | null = null;
39
let isQuitting = false;
40
let desktopProtocolRegistered = false;
41
+let aboutCommitHashCache: string | null | undefined;
42
43
let destructiveMenuIconCache: Electron.NativeImage | null | undefined;
44
@@ -81,6 +84,58 @@ function resolveAppRoot(): string {
84
return app.getAppPath();
85
}
86
87
+function normalizeCommitHash(value: unknown): string | null {
88
+ if (typeof value !== "string") {
89
+ return null;
90
+ }
91
+ const trimmed = value.trim();
92
+ if (!COMMIT_HASH_PATTERN.test(trimmed)) {
93
+ return null;
94
+ }
95
+ return trimmed.slice(0, COMMIT_HASH_DISPLAY_LENGTH).toLowerCase();
96
+}
97
+
98
+function resolveEmbeddedCommitHash(): string | null {
99
+ const packageJsonPath = path.join(resolveAppRoot(), "package.json");
100
+ if (!fs.existsSync(packageJsonPath)) {
101
+ return null;
102
+ }
103
+
104
+ try {
105
+ const raw = fs.readFileSync(packageJsonPath, "utf8");
106
+ const parsed = JSON.parse(raw) as { t3codeCommitHash?: unknown };
107
+ return normalizeCommitHash(parsed.t3codeCommitHash);
108
+ } catch {
109
+ return null;
110
+ }
111
+}
112
+
113
+function resolveGitCommitHash(): string | null {
114
+ try {
115
+ const stdout = execFileSync("git", ["rev-parse", `--short=${COMMIT_HASH_DISPLAY_LENGTH}`, "HEAD"], {
116
+ cwd: ROOT_DIR,
117
+ encoding: "utf8",
118
+ stdio: ["ignore", "pipe", "ignore"],
119
+ });
120
+ return normalizeCommitHash(stdout);
121
+ } catch {
122
+ return null;
123
+ }
124
+}
125
+
126
+function resolveAboutCommitHash(): string | null {
127
+ if (aboutCommitHashCache !== undefined) {
128
+ return aboutCommitHashCache;
129
+ }
130
+
131
+ aboutCommitHashCache =
132
+ normalizeCommitHash(process.env.T3CODE_COMMIT_HASH) ??
133
+ resolveEmbeddedCommitHash() ??
134
+ resolveGitCommitHash();
135
+
136
+ return aboutCommitHashCache;
137
+}
138
+
139
function resolveBackendEntry(): string {
140
return path.join(resolveAppRoot(), "apps/server/dist/index.mjs");
141
}
@@ -277,8 +332,11 @@ function resolveIconPath(ext: "ico" | "icns" | "png"): string | null {
332
333
function configureAppIdentity(): void {
334
app.setName(APP_DISPLAY_NAME);
335
+ const commitHash = resolveAboutCommitHash();
336
app.setAboutPanelOptions({
337
applicationName: APP_DISPLAY_NAME,
338
+ applicationVersion: app.getVersion(),
339
+ version: commitHash ?? "unknown",
340
});
341
342
if (process.platform === "win32") {
scripts/build-desktop-artifact.ts
+20
@@ -1,5 +1,7 @@
1
#!/usr/bin/env node
2
3
+import { spawnSync } from "node:child_process";
4
+
5
import rootPackageJson from "../package.json" with { type: "json" };
6
import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
7
import serverPackageJson from "../apps/server/package.json" with { type: "json" };
@@ -84,6 +86,21 @@ class BuildScriptError extends Data.TaggedError("BuildScriptError")<{
86
readonly cause?: unknown;
87
}> {}
88
89
+function resolveGitCommitHash(repoRoot: string): string {
90
+ const result = spawnSync("git", ["rev-parse", "--short=12", "HEAD"], {
91
+ cwd: repoRoot,
92
+ encoding: "utf8",
93
+ });
94
+ if (result.status !== 0) {
95
+ return "unknown";
96
+ }
97
+ const hash = result.stdout.trim();
98
+ if (!/^[0-9a-f]{7,40}$/i.test(hash)) {
99
+ return "unknown";
100
+ }
101
+ return hash.toLowerCase();
102
+}
103
+
104
interface ResolvedBuildOptions {
105
readonly platform: typeof BuildPlatform.Type;
106
readonly target: string;
@@ -100,6 +117,7 @@ interface StagePackageJson {
117
readonly name: string;
118
readonly version: string;
119
readonly buildVersion: string;
120
+ readonly t3codeCommitHash: string;
121
readonly private: true;
122
readonly description: string;
123
readonly author: string;
@@ -436,6 +454,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions)
454
});
455
456
const appVersion = options.version ?? serverPackageJson.version;
457
+ const commitHash = resolveGitCommitHash(repoRoot);
458
const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
459
const stageRoot = yield* mkdir({
460
prefix: `t3code-desktop-${options.platform}-stage-`,
@@ -490,6 +509,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions)
509
name: "t3-code-desktop",
510
version: appVersion,
511
buildVersion: appVersion,
512
+ t3codeCommitHash: commitHash,
513
private: true,
514
description: "T3 Code desktop build",
515
author: "T3 Tools",