diff --git a/Changelog.md b/Changelog.md index e53b4ebf3..87e8220fb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -34,6 +34,7 @@ - 修复 macOS TUN 模式下原有 DNS 被清除、关闭后 DNS 未恢复及联网后设置未生效 - 修复 macOS 断网时误报代理已回退直连,恢复联网后自动重试系统代理 +- 修复 macOS 切换主题后标题栏保留原有深浅色 diff --git a/src-tauri/capabilities/desktop.json b/src-tauri/capabilities/desktop.json index 46892088e..fbba5dd14 100755 --- a/src-tauri/capabilities/desktop.json +++ b/src-tauri/capabilities/desktop.json @@ -17,6 +17,8 @@ "autostart:allow-disable", "autostart:allow-is-enabled", "core:window:allow-set-theme", + "core:window:allow-set-background-color", + "core:webview:allow-set-webview-background-color", "notification:default", "http:default", "http:allow-fetch", diff --git a/src/pages/_layout/hooks/use-custom-theme.ts b/src/pages/_layout/hooks/use-custom-theme.ts index fd765f6fd..2a09dfe32 100644 --- a/src/pages/_layout/hooks/use-custom-theme.ts +++ b/src/pages/_layout/hooks/use-custom-theme.ts @@ -9,6 +9,7 @@ import { useEffect, useMemo } from 'react' import { useVerge } from '@/hooks/use-verge' import { defaultDarkTheme, defaultTheme } from '@/pages/_theme' import { useSetThemeMode, useThemeMode } from '@/services/states' +import getSystem from '@/utils/get-system' const CSS_INJECTION_SCOPE_ROOT = '[data-css-injection-root]' const CSS_INJECTION_SCOPE_LIMIT = @@ -139,6 +140,12 @@ export const useCustomTheme = () => { console.error(`Failed to set window theme to ${mode}:`, err) }) } + if (getSystem() === 'macos' && mode) { + const background = mode === 'light' ? defaultTheme : defaultDarkTheme + appWindow.setBackgroundColor(background.background_color).catch((err) => { + console.error('Failed to set window background:', err) + }) + } }, [mode, appWindow, theme_mode]) const theme = useMemo(() => {