From 43c025929b2f22caf17ec4b04138c4e18f9b1619 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Sat, 11 Apr 2026 11:06:08 -0700 Subject: [PATCH] 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. --- src/main/windows.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/windows.ts b/src/main/windows.ts index ffa9bd0..df8d39d 100644 --- a/src/main/windows.ts +++ b/src/main/windows.ts @@ -1,7 +1,28 @@ import { BrowserWindow, shell } from "electron"; +import { execFileSync } from "child_process"; + +import { isDevMode } from "../utils/devmode"; 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 { 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.webContents.on("will-navigate", (event, url) =>