Skip to content

Commit eff64d4

Browse files
committed
Handle window control changes on desktop relaunch
- Extract platform titlebar options into a shared helper - Relaunch Electron when `hideWindowControls` changes - Clarify in settings UI that the change applies after restart
1 parent 2a67cc7 commit eff64d4

4 files changed

Lines changed: 145 additions & 43 deletions

File tree

‎apps/desktop/src/main.ts‎

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as Path from "node:path";
77
import {
88
app,
99
BrowserWindow,
10-
type BrowserWindowConstructorOptions,
1110
clipboard,
1211
dialog,
1312
ipcMain,
@@ -86,6 +85,10 @@ import { isArm64HostRunningIntelBuild, resolveDesktopRuntimeInfo } from "./runti
8685
import { resolveDesktopAppBranding } from "./appBranding.ts";
8786
import { bindFirstRevealTrigger, type RevealSubscription } from "./windowReveal.ts";
8887
import { resolveTailscaleAdvertisedEndpoints } from "./tailscaleEndpointProvider.ts";
88+
import {
89+
getWindowTitleBarOptions,
90+
shouldRelaunchForClientSettingsChange,
91+
} from "./windowTitleBar.ts";
8992

9093
syncShellEnvironment();
9194

@@ -176,11 +179,6 @@ function resolvePickFolderDefaultPath(rawOptions: unknown): string | undefined {
176179
}
177180
const DESKTOP_LOOPBACK_HOST = "127.0.0.1";
178181
const DESKTOP_REQUIRED_PORT_PROBE_HOSTS = ["0.0.0.0", "::"] as const;
179-
const TITLEBAR_HEIGHT = 40;
180-
const TITLEBAR_COLOR = "#01000000"; // #00000000 does not work correctly on Linux
181-
const TITLEBAR_LIGHT_SYMBOL_COLOR = "#1f2937";
182-
const TITLEBAR_DARK_SYMBOL_COLOR = "#f8fafc";
183-
184182
function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextMenuItem[] {
185183
const normalizedItems: ContextMenuItem[] = [];
186184

@@ -210,11 +208,6 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
210208
return normalizedItems;
211209
}
212210

213-
type WindowTitleBarOptions = Pick<
214-
BrowserWindowConstructorOptions,
215-
"titleBarOverlay" | "titleBarStyle" | "trafficLightPosition"
216-
>;
217-
218211
type DesktopUpdateErrorContext = DesktopUpdateState["errorContext"];
219212
type LinuxDesktopNamedApp = Electron.App & {
220213
setDesktopName?: (desktopName: string) => void;
@@ -1677,9 +1670,19 @@ function registerIpcHandlers(): void {
16771670
throw new Error("Invalid client settings payload.");
16781671
}
16791672

1680-
clientSettings = rawSettings as ClientSettings;
1681-
writeClientSettings(CLIENT_SETTINGS_PATH, clientSettings);
1673+
const nextClientSettings = rawSettings as ClientSettings;
1674+
const shouldRelaunch = shouldRelaunchForClientSettingsChange(
1675+
clientSettings,
1676+
nextClientSettings,
1677+
);
1678+
1679+
clientSettings = nextClientSettings;
1680+
writeClientSettings(CLIENT_SETTINGS_PATH, nextClientSettings);
16821681
syncAllWindowAppearance();
1682+
1683+
if (shouldRelaunch) {
1684+
relaunchDesktopApp("client-settings-hideWindowControls");
1685+
}
16831686
});
16841687

16851688
ipcMain.removeHandler(GET_SAVED_ENVIRONMENT_REGISTRY_CHANNEL);
@@ -2010,40 +2013,16 @@ function getInitialWindowBackgroundColor(): string {
20102013
return nativeTheme.shouldUseDarkColors ? "#0a0a0a" : "#ffffff";
20112014
}
20122015

2013-
function getWindowTitleBarOptions(hideWindowControls: boolean): WindowTitleBarOptions {
2014-
if (process.platform === "darwin") {
2015-
if (hideWindowControls) {
2016-
return { titleBarStyle: "hidden" };
2017-
}
2018-
return {
2019-
titleBarStyle: "hiddenInset",
2020-
trafficLightPosition: { x: 16, y: 18 },
2021-
};
2022-
}
2023-
2024-
if (hideWindowControls) {
2025-
return {
2026-
titleBarStyle: "hidden",
2027-
titleBarOverlay: {
2028-
color: TITLEBAR_COLOR,
2029-
height: TITLEBAR_HEIGHT,
2030-
symbolColor: nativeTheme.shouldUseDarkColors
2031-
? TITLEBAR_DARK_SYMBOL_COLOR
2032-
: TITLEBAR_LIGHT_SYMBOL_COLOR,
2033-
},
2034-
};
2035-
}
2036-
2037-
return { titleBarStyle: "default" };
2038-
}
2039-
20402016
function syncWindowAppearance(window: BrowserWindow): void {
20412017
if (window.isDestroyed()) {
20422018
return;
20432019
}
20442020

20452021
window.setBackgroundColor(getInitialWindowBackgroundColor());
2046-
const { titleBarOverlay } = getWindowTitleBarOptions(clientSettings.hideWindowControls);
2022+
const { titleBarOverlay } = getWindowTitleBarOptions({
2023+
platform: process.platform,
2024+
hideWindowControls: clientSettings.hideWindowControls,
2025+
});
20472026
if (typeof titleBarOverlay === "object") {
20482027
window.setTitleBarOverlay(titleBarOverlay);
20492028
}
@@ -2068,7 +2047,10 @@ function createWindow(): BrowserWindow {
20682047
backgroundColor: getInitialWindowBackgroundColor(),
20692048
...getIconOption(),
20702049
title: APP_DISPLAY_NAME,
2071-
...getWindowTitleBarOptions(clientSettings.hideWindowControls),
2050+
...getWindowTitleBarOptions({
2051+
platform: process.platform,
2052+
hideWindowControls: clientSettings.hideWindowControls,
2053+
}),
20722054
webPreferences: {
20732055
preload: Path.join(__dirname, "preload.cjs"),
20742056
contextIsolation: true,
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { ClientSettings } from "@t3tools/contracts";
3+
4+
import {
5+
getWindowTitleBarOptions,
6+
shouldRelaunchForClientSettingsChange,
7+
} from "./windowTitleBar.ts";
8+
9+
const baseClientSettings: ClientSettings = {
10+
autoOpenPlanSidebar: true,
11+
confirmThreadArchive: false,
12+
confirmThreadDelete: true,
13+
diffIgnoreWhitespace: true,
14+
diffWordWrap: false,
15+
hideWindowControls: false,
16+
favorites: [],
17+
providerModelPreferences: {},
18+
sidebarProjectGroupingMode: "repository",
19+
sidebarProjectGroupingOverrides: {},
20+
sidebarProjectSortOrder: "updated_at",
21+
sidebarThreadSortOrder: "updated_at",
22+
timestampFormat: "locale",
23+
};
24+
25+
describe("getWindowTitleBarOptions", () => {
26+
it("keeps the default Linux titlebar when controls are visible", () => {
27+
expect(
28+
getWindowTitleBarOptions({
29+
platform: "linux",
30+
hideWindowControls: false,
31+
}),
32+
).toEqual({
33+
titleBarStyle: "default",
34+
});
35+
});
36+
37+
it("hides Linux controls by removing the overlay", () => {
38+
expect(
39+
getWindowTitleBarOptions({
40+
platform: "linux",
41+
hideWindowControls: true,
42+
}),
43+
).toEqual({
44+
titleBarStyle: "hidden",
45+
});
46+
});
47+
48+
it("keeps macOS traffic lights visible when controls are not hidden", () => {
49+
expect(
50+
getWindowTitleBarOptions({
51+
platform: "darwin",
52+
hideWindowControls: false,
53+
}),
54+
).toEqual({
55+
titleBarStyle: "hiddenInset",
56+
trafficLightPosition: { x: 16, y: 18 },
57+
});
58+
});
59+
});
60+
61+
describe("shouldRelaunchForClientSettingsChange", () => {
62+
it("relaunches when hideWindowControls changes", () => {
63+
expect(
64+
shouldRelaunchForClientSettingsChange(baseClientSettings, {
65+
...baseClientSettings,
66+
hideWindowControls: true,
67+
}),
68+
).toBe(true);
69+
});
70+
71+
it("does not relaunch for unrelated client setting changes", () => {
72+
expect(
73+
shouldRelaunchForClientSettingsChange(baseClientSettings, {
74+
...baseClientSettings,
75+
diffWordWrap: true,
76+
}),
77+
).toBe(false);
78+
});
79+
});

‎apps/desktop/src/windowTitleBar.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { BrowserWindowConstructorOptions } from "electron";
2+
import type { ClientSettings } from "@t3tools/contracts";
3+
4+
export type WindowTitleBarOptions = Pick<
5+
BrowserWindowConstructorOptions,
6+
"titleBarOverlay" | "titleBarStyle" | "trafficLightPosition"
7+
>;
8+
9+
export function getWindowTitleBarOptions(input: {
10+
readonly platform: NodeJS.Platform;
11+
readonly hideWindowControls: boolean;
12+
}): WindowTitleBarOptions {
13+
const { platform, hideWindowControls } = input;
14+
15+
if (platform === "darwin") {
16+
if (hideWindowControls) {
17+
return { titleBarStyle: "hidden" };
18+
}
19+
return {
20+
titleBarStyle: "hiddenInset",
21+
trafficLightPosition: { x: 16, y: 18 },
22+
};
23+
}
24+
25+
if (hideWindowControls) {
26+
return {
27+
titleBarStyle: "hidden",
28+
};
29+
}
30+
31+
return { titleBarStyle: "default" };
32+
}
33+
34+
export function shouldRelaunchForClientSettingsChange(
35+
previousSettings: ClientSettings,
36+
nextSettings: ClientSettings,
37+
): boolean {
38+
return previousSettings.hideWindowControls !== nextSettings.hideWindowControls;
39+
}

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,9 @@ export function GeneralSettingsPanel() {
943943
<SettingsRow
944944
title="Window controls"
945945
description={
946-
isElectron ? "Hide the desktop minimize, maximize, and close buttons." : "Desktop only."
946+
isElectron
947+
? "Hide the desktop minimize, maximize, and close buttons. Applies after app relaunch."
948+
: "Desktop only."
947949
}
948950
resetAction={
949951
settings.hideWindowControls !== DEFAULT_UNIFIED_SETTINGS.hideWindowControls ? (

0 commit comments

Comments
 (0)