Skip to content

Commit b0d864a

Browse files
committed
feat(desktop): implement platform-specific window chrome
Introduce centralized window chrome configuration for Electron windows based on platform. Windows now uses a native frame with visible menu bar, while macOS retains hidden title bar with traffic lights at fixed position. Windows title bar overlay logic is now isolated and only applied when explicitly enabled. Refs: anomalyco#42
1 parent e8b6336 commit b0d864a

3 files changed

Lines changed: 38 additions & 16 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { mainWindowChrome } from "./window-chrome"
3+
4+
describe("main window chrome", () => {
5+
test("uses the standard Windows frame required by the native menu bar", () => {
6+
const options = mainWindowChrome("win32")
7+
8+
expect(options).toEqual({ autoHideMenuBar: false, frame: true })
9+
expect(options).not.toHaveProperty("titleBarStyle")
10+
expect(options).not.toHaveProperty("titleBarOverlay")
11+
})
12+
13+
test("preserves the macOS hidden title bar and traffic lights", () => {
14+
expect(mainWindowChrome("darwin")).toEqual({
15+
autoHideMenuBar: true,
16+
titleBarStyle: "hidden",
17+
trafficLightPosition: { x: 12, y: 14 },
18+
})
19+
})
20+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { BrowserWindowConstructorOptions } from "electron"
2+
3+
export function mainWindowChrome(platform: NodeJS.Platform): Partial<BrowserWindowConstructorOptions> {
4+
if (platform === "win32") return { autoHideMenuBar: false, frame: true }
5+
if (platform === "darwin") {
6+
return {
7+
autoHideMenuBar: true,
8+
titleBarStyle: "hidden",
9+
trafficLightPosition: { x: 12, y: 14 },
10+
}
11+
}
12+
return { autoHideMenuBar: true }
13+
}

‎packages/ellamaka-desktop/src/main/windows.ts‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { PINCH_ZOOM_ENABLED_KEY } from "./constants"
1010
import { exportDebugLogs, write as writeLog } from "./logging"
1111
import { getStore } from "./store"
1212
import { createUnresponsiveSampler } from "./unresponsive"
13+
import { mainWindowChrome } from "./window-chrome"
1314

1415
const root = dirname(fileURLToPath(import.meta.url))
1516
const rendererRoot = join(root, "../renderer")
@@ -43,6 +44,7 @@ let relaunchHandler = () => {
4344
app.exit(0)
4445
}
4546
const titlebarThemes = new WeakMap<BrowserWindow, Partial<TitlebarTheme>>()
47+
const titlebarOverlayWindows = new WeakSet<BrowserWindow>()
4648
const pinchZoomEnabled = new WeakMap<BrowserWindow, boolean>()
4749
const titlebarHeight = 40
4850
const maxZoomLevel = 10
@@ -93,7 +95,7 @@ export function setTitlebar(win: BrowserWindow, theme: Partial<TitlebarTheme> =
9395
}
9496

9597
export function updateTitlebar(win: BrowserWindow) {
96-
if (process.platform !== "win32") return
98+
if (process.platform !== "win32" || !titlebarOverlayWindows.has(win)) return
9799
win.setTitleBarOverlay(overlay(titlebarThemes.get(win), win.webContents.getZoomFactor()))
98100
}
99101

@@ -123,30 +125,16 @@ export function createMainWindow() {
123125
defaultHeight: 800,
124126
})
125127

126-
const mode = tone()
127128
const win = new BrowserWindow({
128129
x: state.x,
129130
y: state.y,
130131
width: state.width,
131132
height: state.height,
132133
show: false,
133-
autoHideMenuBar: process.platform !== "win32",
134134
title: "Ellamaka",
135135
icon: iconPath(),
136136
backgroundColor: backgroundColor ?? defaultBackgroundColor(),
137-
...(process.platform === "darwin"
138-
? {
139-
titleBarStyle: "hidden" as const,
140-
trafficLightPosition: { x: 12, y: 14 },
141-
}
142-
: {}),
143-
...(process.platform === "win32"
144-
? {
145-
frame: false,
146-
titleBarStyle: "hidden" as const,
147-
titleBarOverlay: overlay({ mode }),
148-
}
149-
: {}),
137+
...mainWindowChrome(process.platform),
150138
webPreferences: {
151139
preload: join(root, "../preload/index.js"),
152140
contextIsolation: true,
@@ -207,6 +195,7 @@ export function createLoadingWindow() {
207195
sandbox: true,
208196
},
209197
})
198+
if (process.platform === "win32") titlebarOverlayWindows.add(win)
210199

211200
allowRendererPermissions(win)
212201
wireWindowRecovery(win, "loading")

0 commit comments

Comments
 (0)