authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-02 18:21:27-08:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-02 18:53:21-08:00
loge319735ed1aedb5f117cd320511581e240f257d1
treeade9eed27b646ad85dfe732342d2b555fa642c25
parente7790490f16592d9b0a5418201921a58b1fb5fe7

Refactor commit hash resolution in About panel

- Remove git command execution for commit hash retrieval - Simplify commit hash resolution to use environment variable and embedded hash only - Clean up unused code in IPC handler registration

1 files changed, 4 insertions(+), 23 deletions(-)

apps/desktop/src/main.ts+4-23
......@@ -1,4 +1,4 @@
1import { execFileSync, spawn, type ChildProcess } from "node:child_process";
1import { spawn, type ChildProcess } from "node:child_process";
22import { randomBytes } from "node:crypto";
33import fs from "node:fs";
44import net from "node:net";
......@@ -110,28 +110,13 @@ function resolveEmbeddedCommitHash(): string | null {
110110 }
111111}
112112
113function 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
126113function resolveAboutCommitHash(): string | null {
127114 if (aboutCommitHashCache !== undefined) {
128115 return aboutCommitHashCache;
129116 }
130117
131118 aboutCommitHashCache =
132 normalizeCommitHash(process.env.T3CODE_COMMIT_HASH) ??
133 resolveEmbeddedCommitHash() ??
134 resolveGitCommitHash();
119 normalizeCommitHash(process.env.T3CODE_COMMIT_HASH) ?? resolveEmbeddedCommitHash();
135120
136121 return aboutCommitHashCache;
137122}
......@@ -483,11 +468,7 @@ function registerIpcHandlers(): void {
483468 ipcMain.removeHandler(CONTEXT_MENU_CHANNEL);
484469 ipcMain.handle(
485470 CONTEXT_MENU_CHANNEL,
486 async (
487 _event,
488 items: ContextMenuItem[],
489 position?: { x: number; y: number },
490 ) => {
471 async (_event, items: ContextMenuItem[], position?: { x: number; y: number }) => {
491472 const normalizedItems = items
492473 .filter((item) => typeof item.id === "string" && typeof item.label === "string")
493474 .map((item) => ({
......@@ -538,7 +519,7 @@ function registerIpcHandlers(): void {
538519 const menu = Menu.buildFromTemplate(template);
539520 menu.popup({
540521 window,
541 ...(popupPosition ?? {}),
522 ...popupPosition,
542523 callback: () => resolve(null),
543524 });
544525 });