mirror of
https://github.com/felixrieseberg/windows95.git
synced 2026-05-09 00:24:09 +00:00
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:
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user