Skip to content

Commit 53b6375

Browse files
Apply PR #28247: fix(desktop): avoid white flash when restoring window
2 parents 65d2280 + 9ce8067 commit 53b6375

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/desktop/src/main/windows.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import windowState from "electron-window-state"
2+
import { resolveThemeVariant } from "@opencode-ai/ui/theme/resolve"
23
import { app, BrowserWindow, dialog, net, nativeImage, nativeTheme, protocol } from "electron"
34
import { dirname, isAbsolute, join, relative, resolve } from "node:path"
45
import { fileURLToPath, pathToFileURL } from "node:url"
56
import type { TitlebarTheme } from "../preload/types"
7+
import type { DesktopTheme } from "@opencode-ai/ui/theme/types"
8+
import oc2ThemeJson from "../../../ui/src/theme/themes/oc-2.json"
69
import { exportDebugLogs, write as writeLog } from "./logging"
710
import { createUnresponsiveSampler } from "./unresponsive"
811

@@ -15,6 +18,11 @@ const notificationPermission = "notifications"
1518
const rendererPermissions = new Set([clipboardWritePermission, notificationPermission])
1619
const documentPolicyHeader = "Document-Policy"
1720
const jsCallStacksDocumentPolicy = "include-js-call-stacks-in-crash-reports"
21+
const oc2Theme = oc2ThemeJson as DesktopTheme
22+
const oc2Background = {
23+
light: resolveThemeVariant(oc2Theme.light, false)["background-base"],
24+
dark: resolveThemeVariant(oc2Theme.dark, true)["background-base"],
25+
}
1826

1927
protocol.registerSchemesAsPrivileged([
2028
{
@@ -41,6 +49,7 @@ export function setRelaunchHandler(handler: () => void) {
4149

4250
export function setBackgroundColor(color: string) {
4351
backgroundColor = color
52+
BrowserWindow.getAllWindows().forEach((win) => win.setBackgroundColor(color))
4453
}
4554

4655
export function getBackgroundColor(): string | undefined {
@@ -60,6 +69,10 @@ function tone() {
6069
return nativeTheme.shouldUseDarkColors ? "dark" : "light"
6170
}
6271

72+
function defaultBackgroundColor() {
73+
return oc2Background[tone()]
74+
}
75+
6376
function overlay(theme: Partial<TitlebarTheme> = {}, zoom = 1) {
6477
const mode = theme.mode ?? tone()
6578
return {
@@ -101,7 +114,7 @@ export function createMainWindow() {
101114
autoHideMenuBar: true,
102115
title: "OpenCode",
103116
icon: iconPath(),
104-
backgroundColor,
117+
backgroundColor: backgroundColor ?? defaultBackgroundColor(),
105118
...(process.platform === "darwin"
106119
? {
107120
titleBarStyle: "hidden" as const,
@@ -159,7 +172,7 @@ export function createLoadingWindow() {
159172
show: true,
160173
autoHideMenuBar: true,
161174
icon: iconPath(),
162-
backgroundColor,
175+
backgroundColor: backgroundColor ?? defaultBackgroundColor(),
163176
...(process.platform === "darwin" ? { titleBarStyle: "hidden" as const } : {}),
164177
...(process.platform === "win32"
165178
? {

0 commit comments

Comments
 (0)