Skip to content

Commit 50374ab

Browse files
authored
feat(app): change traffic light position, fix sequoia bug (anomalyco#35081)
1 parent 0497e8b commit 50374ab

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

packages/app/src/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ declare global {
186186
deepLinks?: string[]
187187
}
188188
api?: {
189-
setTitlebar?: (theme: { mode: "light" | "dark" }) => Promise<void>
189+
setTitlebar?: (theme: { mode: "light" | "dark"; scheme?: "system" | "light" | "dark" }) => Promise<void>
190190
exportDebugLogs?: () => Promise<string>
191191
}
192192
}
@@ -320,8 +320,8 @@ export function AppBaseProviders(props: ParentProps<{ locale?: Locale }>) {
320320
<MetaProvider>
321321
<Font />
322322
<ThemeProvider
323-
onThemeApplied={(_, mode) => {
324-
void window.api?.setTitlebar?.({ mode })
323+
onThemeApplied={(_, mode, scheme) => {
324+
void window.api?.setTitlebar?.({ mode, scheme })
325325
}}
326326
>
327327
<LanguageProvider locale={props.locale}>

packages/desktop/src/main/windows.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export function setAppQuitting(quitting = true) {
7171

7272
export function setBackgroundColor(color: string) {
7373
backgroundColor = color
74-
BrowserWindow.getAllWindows().forEach((win) => win.setBackgroundColor(color))
74+
BrowserWindow.getAllWindows().forEach((win) => {
75+
win.setBackgroundColor(color)
76+
if (process.platform === "darwin") win.invalidateShadow()
77+
})
7578
}
7679

7780
export function getBackgroundColor(): string | undefined {
@@ -106,6 +109,13 @@ function overlay(theme: Partial<TitlebarTheme> = {}, zoom = 1) {
106109

107110
export function setTitlebar(win: BrowserWindow, theme: Partial<TitlebarTheme> = {}) {
108111
titlebarThemes.set(win, theme)
112+
// macOS draws the window frame hairline and shadow using the NSWindow
113+
// appearance, which follows nativeTheme rather than the rendered content.
114+
// Align it with the app theme so a light app on a dark system does not get
115+
// the dark-appearance border and shadow. A "system" scheme must map to
116+
// "system" (not the resolved mode) or prefers-color-scheme stops tracking
117+
// OS appearance changes in the renderer.
118+
if (process.platform === "darwin") nativeTheme.themeSource = theme.scheme ?? theme.mode ?? "system"
109119
updateTitlebar(win)
110120
}
111121

@@ -172,7 +182,7 @@ export function createMainWindow(id: string = randomUUID()) {
172182
...(process.platform === "darwin"
173183
? {
174184
titleBarStyle: "hidden" as const,
175-
trafficLightPosition: { x: 12, y: 14 },
185+
trafficLightPosition: { x: 14, y: 14 },
176186
}
177187
: {}),
178188
...(process.platform === "win32"

packages/desktop/src/preload/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type UpdaterAPI = {
3131
export type LinuxDisplayBackend = "wayland" | "auto"
3232
export type TitlebarTheme = {
3333
mode: "light" | "dark"
34+
scheme?: "system" | "light" | "dark"
3435
}
3536
export type FatalRendererError = {
3637
error: string

packages/ui/src/theme/context.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ function cacheThemeVariants(theme: DesktopTheme, themeId: string) {
173173

174174
export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
175175
name: "Theme",
176-
init: (props: { defaultTheme?: string; onThemeApplied?: (theme: DesktopTheme, mode: "light" | "dark") => void }) => {
176+
init: (props: {
177+
defaultTheme?: string
178+
onThemeApplied?: (theme: DesktopTheme, mode: "light" | "dark", scheme: ColorScheme) => void
179+
}) => {
177180
const themeId = normalize(read(STORAGE_KEYS.THEME_ID) ?? props.defaultTheme) ?? "oc-2"
178181
const colorScheme = (read(STORAGE_KEYS.COLOR_SCHEME) as ColorScheme | null) ?? "system"
179182
const mode = colorScheme === "system" ? getSystemMode() : colorScheme
@@ -212,9 +215,9 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
212215
return task
213216
}
214217

215-
const applyTheme = (theme: DesktopTheme, themeId: string, mode: "light" | "dark") => {
218+
const applyTheme = (theme: DesktopTheme, themeId: string, mode: "light" | "dark", scheme: ColorScheme) => {
216219
applyThemeCss(theme, themeId, mode)
217-
props.onThemeApplied?.(theme, mode)
220+
props.onThemeApplied?.(theme, mode, scheme)
218221
}
219222

220223
const ids = () => {
@@ -278,7 +281,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
278281
createEffect(() => {
279282
const theme = store.themes[store.themeId]
280283
if (!theme) return
281-
applyTheme(theme, store.themeId, store.mode)
284+
applyTheme(theme, store.themeId, store.mode, store.colorScheme)
282285
})
283286

284287
const setTheme = (id: string) => {
@@ -333,7 +336,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
333336
? getSystemMode()
334337
: store.previewScheme
335338
: store.mode
336-
applyTheme(theme, next, mode)
339+
applyTheme(theme, next, mode, store.previewScheme ?? store.colorScheme)
337340
})
338341
},
339342
previewColorScheme: (scheme: ColorScheme) => {
@@ -344,7 +347,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
344347
if (!theme) return
345348
if ((store.previewThemeId ?? store.themeId) !== id) return
346349
if (store.previewScheme !== scheme) return
347-
applyTheme(theme, id, mode)
350+
applyTheme(theme, id, mode, scheme)
348351
})
349352
},
350353
commitPreview: () => {
@@ -362,7 +365,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
362365
setStore("previewScheme", null)
363366
void load(store.themeId).then((theme) => {
364367
if (!theme) return
365-
applyTheme(theme, store.themeId, store.mode)
368+
applyTheme(theme, store.themeId, store.mode, store.colorScheme)
366369
})
367370
},
368371
}

0 commit comments

Comments
 (0)