Show git branch in window title during development (#351)

When running via yarn start on a branch other than master/main, append
the branch name to the window title (e.g. "windows95 (my-feature)").
No-op in packaged builds.
This commit is contained in:
Felix Rieseberg
2026-04-11 11:06:08 -07:00
committed by GitHub
parent 3b62e1c9b5
commit 43c025929b

View File

@@ -1,7 +1,28 @@
import { BrowserWindow, shell } from "electron"; import { BrowserWindow, shell } from "electron";
import { execFileSync } from "child_process";
import { isDevMode } from "../utils/devmode";
let mainWindow: BrowserWindow | null = null; let mainWindow: BrowserWindow | null = null;
function getDevBranchSuffix(): string {
if (!isDevMode()) return "";
try {
const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
encoding: "utf8",
}).trim();
if (branch && branch !== "master" && branch !== "main") {
return ` (${branch})`;
}
} catch {
// git not available or not a repo — ignore
}
return "";
}
export function getOrCreateWindow(): BrowserWindow { export function getOrCreateWindow(): BrowserWindow {
if (mainWindow) return mainWindow; if (mainWindow) return mainWindow;
@@ -18,6 +39,14 @@ export function getOrCreateWindow(): BrowserWindow {
}, },
}); });
const branchSuffix = getDevBranchSuffix();
if (branchSuffix) {
mainWindow.on("page-title-updated", (event, title) => {
event.preventDefault();
mainWindow?.setTitle(`${title}${branchSuffix}`);
});
}
mainWindow.loadFile("./dist/static/index.html"); mainWindow.loadFile("./dist/static/index.html");
mainWindow.webContents.on("will-navigate", (event, url) => mainWindow.webContents.on("will-navigate", (event, url) =>