feat(app): change traffic light position, fix sequoia bug (#35081)

This commit is contained in:
Aarav Sareen
2026-07-07 12:49:28 +08:00
committed by GitHub
parent 0497e8badf
commit 50374abab8
4 changed files with 26 additions and 12 deletions
+3 -3
View File
@@ -186,7 +186,7 @@ declare global {
deepLinks?: string[] deepLinks?: string[]
} }
api?: { api?: {
setTitlebar?: (theme: { mode: "light" | "dark" }) => Promise<void> setTitlebar?: (theme: { mode: "light" | "dark"; scheme?: "system" | "light" | "dark" }) => Promise<void>
exportDebugLogs?: () => Promise<string> exportDebugLogs?: () => Promise<string>
} }
} }
@@ -320,8 +320,8 @@ export function AppBaseProviders(props: ParentProps<{ locale?: Locale }>) {
<MetaProvider> <MetaProvider>
<Font /> <Font />
<ThemeProvider <ThemeProvider
onThemeApplied={(_, mode) => { onThemeApplied={(_, mode, scheme) => {
void window.api?.setTitlebar?.({ mode }) void window.api?.setTitlebar?.({ mode, scheme })
}} }}
> >
<LanguageProvider locale={props.locale}> <LanguageProvider locale={props.locale}>
+12 -2
View File
@@ -71,7 +71,10 @@ export function setAppQuitting(quitting = true) {
export function setBackgroundColor(color: string) { export function setBackgroundColor(color: string) {
backgroundColor = color backgroundColor = color
BrowserWindow.getAllWindows().forEach((win) => win.setBackgroundColor(color)) BrowserWindow.getAllWindows().forEach((win) => {
win.setBackgroundColor(color)
if (process.platform === "darwin") win.invalidateShadow()
})
} }
export function getBackgroundColor(): string | undefined { export function getBackgroundColor(): string | undefined {
@@ -106,6 +109,13 @@ function overlay(theme: Partial<TitlebarTheme> = {}, zoom = 1) {
export function setTitlebar(win: BrowserWindow, theme: Partial<TitlebarTheme> = {}) { export function setTitlebar(win: BrowserWindow, theme: Partial<TitlebarTheme> = {}) {
titlebarThemes.set(win, theme) titlebarThemes.set(win, theme)
// macOS draws the window frame hairline and shadow using the NSWindow
// appearance, which follows nativeTheme rather than the rendered content.
// Align it with the app theme so a light app on a dark system does not get
// the dark-appearance border and shadow. A "system" scheme must map to
// "system" (not the resolved mode) or prefers-color-scheme stops tracking
// OS appearance changes in the renderer.
if (process.platform === "darwin") nativeTheme.themeSource = theme.scheme ?? theme.mode ?? "system"
updateTitlebar(win) updateTitlebar(win)
} }
@@ -172,7 +182,7 @@ export function createMainWindow(id: string = randomUUID()) {
...(process.platform === "darwin" ...(process.platform === "darwin"
? { ? {
titleBarStyle: "hidden" as const, titleBarStyle: "hidden" as const,
trafficLightPosition: { x: 12, y: 14 }, trafficLightPosition: { x: 14, y: 14 },
} }
: {}), : {}),
...(process.platform === "win32" ...(process.platform === "win32"
+1
View File
@@ -31,6 +31,7 @@ export type UpdaterAPI = {
export type LinuxDisplayBackend = "wayland" | "auto" export type LinuxDisplayBackend = "wayland" | "auto"
export type TitlebarTheme = { export type TitlebarTheme = {
mode: "light" | "dark" mode: "light" | "dark"
scheme?: "system" | "light" | "dark"
} }
export type FatalRendererError = { export type FatalRendererError = {
error: string error: string
+10 -7
View File
@@ -173,7 +173,10 @@ function cacheThemeVariants(theme: DesktopTheme, themeId: string) {
export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
name: "Theme", name: "Theme",
init: (props: { defaultTheme?: string; onThemeApplied?: (theme: DesktopTheme, mode: "light" | "dark") => void }) => { init: (props: {
defaultTheme?: string
onThemeApplied?: (theme: DesktopTheme, mode: "light" | "dark", scheme: ColorScheme) => void
}) => {
const themeId = normalize(read(STORAGE_KEYS.THEME_ID) ?? props.defaultTheme) ?? "oc-2" const themeId = normalize(read(STORAGE_KEYS.THEME_ID) ?? props.defaultTheme) ?? "oc-2"
const colorScheme = (read(STORAGE_KEYS.COLOR_SCHEME) as ColorScheme | null) ?? "system" const colorScheme = (read(STORAGE_KEYS.COLOR_SCHEME) as ColorScheme | null) ?? "system"
const mode = colorScheme === "system" ? getSystemMode() : colorScheme const mode = colorScheme === "system" ? getSystemMode() : colorScheme
@@ -212,9 +215,9 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
return task return task
} }
const applyTheme = (theme: DesktopTheme, themeId: string, mode: "light" | "dark") => { const applyTheme = (theme: DesktopTheme, themeId: string, mode: "light" | "dark", scheme: ColorScheme) => {
applyThemeCss(theme, themeId, mode) applyThemeCss(theme, themeId, mode)
props.onThemeApplied?.(theme, mode) props.onThemeApplied?.(theme, mode, scheme)
} }
const ids = () => { const ids = () => {
@@ -278,7 +281,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
createEffect(() => { createEffect(() => {
const theme = store.themes[store.themeId] const theme = store.themes[store.themeId]
if (!theme) return if (!theme) return
applyTheme(theme, store.themeId, store.mode) applyTheme(theme, store.themeId, store.mode, store.colorScheme)
}) })
const setTheme = (id: string) => { const setTheme = (id: string) => {
@@ -333,7 +336,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
? getSystemMode() ? getSystemMode()
: store.previewScheme : store.previewScheme
: store.mode : store.mode
applyTheme(theme, next, mode) applyTheme(theme, next, mode, store.previewScheme ?? store.colorScheme)
}) })
}, },
previewColorScheme: (scheme: ColorScheme) => { previewColorScheme: (scheme: ColorScheme) => {
@@ -344,7 +347,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
if (!theme) return if (!theme) return
if ((store.previewThemeId ?? store.themeId) !== id) return if ((store.previewThemeId ?? store.themeId) !== id) return
if (store.previewScheme !== scheme) return if (store.previewScheme !== scheme) return
applyTheme(theme, id, mode) applyTheme(theme, id, mode, scheme)
}) })
}, },
commitPreview: () => { commitPreview: () => {
@@ -362,7 +365,7 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
setStore("previewScheme", null) setStore("previewScheme", null)
void load(store.themeId).then((theme) => { void load(store.themeId).then((theme) => {
if (!theme) return if (!theme) return
applyTheme(theme, store.themeId, store.mode) applyTheme(theme, store.themeId, store.mode, store.colorScheme)
}) })
}, },
} }