Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,13 @@ function registerIpcHandlers(): void {
}

nativeTheme.themeSource = theme;

// Keep the native window background in sync so resize does not flash
// a stale color while the renderer catches up.
const bg = themeBackgroundColor();
for (const win of BrowserWindow.getAllWindows()) {
win.setBackgroundColor(bg);
}
});

ipcMain.removeHandler(CONTEXT_MENU_CHANNEL);
Expand Down Expand Up @@ -1220,6 +1227,16 @@ function getIconOption(): { icon: string } | Record<string, never> {
return iconPath ? { icon: iconPath } : {};
}

// Background colors that match the app's CSS theme tokens.
// Dark: color-mix(in srgb, neutral-950 95%, white) ≈ #161616
// Light: white
const THEME_BG_DARK = "#161616";
const THEME_BG_LIGHT = "#ffffff";
Comment on lines +1230 to +1234
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly a fan of duplicating the colors here, especially for an easy-to-miss bug like this one. We should have a single-source-of-truth somewhere and import it both places.


function themeBackgroundColor(): string {
return nativeTheme.shouldUseDarkColors ? THEME_BG_DARK : THEME_BG_LIGHT;
}

function createWindow(): BrowserWindow {
const window = new BrowserWindow({
width: 1100,
Expand All @@ -1228,6 +1245,7 @@ function createWindow(): BrowserWindow {
minHeight: 620,
show: false,
autoHideMenuBar: true,
backgroundColor: themeBackgroundColor(),
...getIconOption(),
title: APP_DISPLAY_NAME,
titleBarStyle: "hiddenInset",
Expand Down
12 changes: 12 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
rel="stylesheet"
/>
<title>T3 Code (Alpha)</title>
<script>
// Apply theme background before first paint to prevent white flash.
// Must run synchronously in <head> before any rendering occurs.
(function () {
var t = localStorage.getItem("t3code:theme") || "system";
var d =
t === "dark" ||
(t === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.style.backgroundColor = d ? "#161616" : "#ffffff";
if (d) document.documentElement.classList.add("dark");
})();
</script>
</head>
<body>
<div id="root"></div>
Expand Down