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 @@...@@ -1,4 +1,4 @@
1import { execFileSync, spawn, type ChildProcess } from "node:child_process";1import { spawn, type ChildProcess } from "node:child_process";
2import { randomBytes } from "node:crypto";2import { randomBytes } from "node:crypto";
3import fs from "node:fs";3import fs from "node:fs";
4import net from "node:net";4import net from "node:net";
...@@ -110,28 +110,13 @@ function resolveEmbeddedCommitHash(): string | null {...@@ -110,28 +110,13 @@ function resolveEmbeddedCommitHash(): string | null {
110 }110 }
111}111}
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
126function resolveAboutCommitHash(): string | null {113function resolveAboutCommitHash(): string | null {
127 if (aboutCommitHashCache !== undefined) {114 if (aboutCommitHashCache !== undefined) {
128 return aboutCommitHashCache;115 return aboutCommitHashCache;
129 }116 }
130117
131 aboutCommitHashCache =118 aboutCommitHashCache =
132 normalizeCommitHash(process.env.T3CODE_COMMIT_HASH) ??119 normalizeCommitHash(process.env.T3CODE_COMMIT_HASH) ?? resolveEmbeddedCommitHash();
133 resolveEmbeddedCommitHash() ??
134 resolveGitCommitHash();
135120
136 return aboutCommitHashCache;121 return aboutCommitHashCache;
137}122}
...@@ -483,11 +468,7 @@ function registerIpcHandlers(): void {...@@ -483,11 +468,7 @@ function registerIpcHandlers(): void {
483 ipcMain.removeHandler(CONTEXT_MENU_CHANNEL);468 ipcMain.removeHandler(CONTEXT_MENU_CHANNEL);
484 ipcMain.handle(469 ipcMain.handle(
485 CONTEXT_MENU_CHANNEL,470 CONTEXT_MENU_CHANNEL,
486 async (471 async (_event, items: ContextMenuItem[], position?: { x: number; y: number }) => {
487 _event,
488 items: ContextMenuItem[],
489 position?: { x: number; y: number },
490 ) => {
491 const normalizedItems = items472 const normalizedItems = items
492 .filter((item) => typeof item.id === "string" && typeof item.label === "string")473 .filter((item) => typeof item.id === "string" && typeof item.label === "string")
493 .map((item) => ({474 .map((item) => ({
...@@ -538,7 +519,7 @@ function registerIpcHandlers(): void {...@@ -538,7 +519,7 @@ function registerIpcHandlers(): void {
538 const menu = Menu.buildFromTemplate(template);519 const menu = Menu.buildFromTemplate(template);
539 menu.popup({520 menu.popup({
540 window,521 window,
541 ...(popupPosition ?? {}),522 ...popupPosition,
542 callback: () => resolve(null),523 callback: () => resolve(null),
543 });524 });
544 });525 });