diff --git a/v3/pkg/application/theme_webview_window_darwin.go b/v3/pkg/application/theme_webview_window_darwin.go index 110f3c476..a4a9bebbd 100644 --- a/v3/pkg/application/theme_webview_window_darwin.go +++ b/v3/pkg/application/theme_webview_window_darwin.go @@ -4,9 +4,9 @@ package application import "fmt" -// getOppositeAppearance returns the macOS appearance that represents +// getOppositeMacAppearance returns the macOS appearance that represents // the opposite light/dark variant. -func (w *macosWebviewWindow) getOppositeAppearance(name string) (MacAppearanceType, error) { +func getOppositeMacAppearance(name string) (MacAppearanceType, error) { if name == "NSAppearanceNameDarkAqua" { return "NSAppearanceNameAqua", nil } @@ -16,10 +16,9 @@ func (w *macosWebviewWindow) getOppositeAppearance(name string) (MacAppearanceTy return "NSAppearanceNameDarkAqua", err } -// isAppearanceDark reports whether the current window appearance +// isMacAppearanceDark reports whether the current window appearance // corresponds to a dark macOS appearance. -func (w *macosWebviewWindow) isAppearanceDark() bool { - appr := w.getEffectiveAppearanceName() +func isMacAppearanceDark(appr string) bool { // Check if the appearance name contains "Dark" switch appr { case "NSAppearanceNameDarkAqua", @@ -40,7 +39,7 @@ func (w *macosWebviewWindow) syncTheme() { } currentAppearance := w.getEffectiveAppearanceName() - currentDark := w.isAppearanceDark() + currentDark := isMacAppearanceDark(currentAppearance) switch globalApplication.theme { case AppSystemDefault: @@ -48,12 +47,12 @@ func (w *macosWebviewWindow) syncTheme() { return case AppDark: if !currentDark { - appr, _ := w.getOppositeAppearance(currentAppearance) + appr, _ := getOppositeMacAppearance(currentAppearance) w.setAppearanceByName(appr) } case AppLight: if currentDark { - appr, _ := w.getOppositeAppearance(currentAppearance) + appr, _ := getOppositeMacAppearance(currentAppearance) w.setAppearanceByName(appr) } } @@ -74,18 +73,18 @@ func (w *macosWebviewWindow) setTheme(theme WinTheme) { } currentAppearance := w.getEffectiveAppearanceName() - isDark := w.isAppearanceDark() + isDark := isMacAppearanceDark(currentAppearance) w.parent.followApplicationTheme = false switch theme { case WinThemeDark: if !isDark { - appr, _ := w.getOppositeAppearance(currentAppearance) + appr, _ := getOppositeMacAppearance(currentAppearance) w.setAppearanceByName(appr) } case WinThemeLight: if isDark { - appr, _ := w.getOppositeAppearance(currentAppearance) + appr, _ := getOppositeMacAppearance(currentAppearance) w.setAppearanceByName(appr) } } @@ -103,7 +102,7 @@ func (w *macosWebviewWindow) getTheme() WinTheme { return WinThemeSystem } - if w.isAppearanceDark() { + if isMacAppearanceDark(w.getEffectiveAppearanceName()) { return WinThemeDark } diff --git a/v3/pkg/application/theme_webview_window_windows.go b/v3/pkg/application/theme_webview_window_windows.go index 5fcce9507..30a41a99a 100644 --- a/v3/pkg/application/theme_webview_window_windows.go +++ b/v3/pkg/application/theme_webview_window_windows.go @@ -4,10 +4,10 @@ package application import "github.com/wailsapp/wails/v3/pkg/w32" -// resolveTheme determines the realized Theme for the window by resolving +// resolveWindowsEffectiveTheme determines the realized Theme for the window by resolving // application-level and window-level theme settings. -func (w *windowsWebviewWindow) resolveTheme() Theme { - switch w.parent.options.Windows.Theme { +func resolveWindowsEffectiveTheme(winTheme WinTheme, appTheme AppTheme) Theme { + switch winTheme { case WinThemeDark: return Dark case WinThemeLight: @@ -16,7 +16,7 @@ func (w *windowsWebviewWindow) resolveTheme() Theme { return SystemDefault default: // For WinThemeApplication and/or Unset values we default to following - switch globalApplication.theme { + switch appTheme { case AppDark: return Dark case AppLight: diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 2c169bae6..aafea1680 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -515,7 +515,7 @@ func (w *windowsWebviewWindow) run() { } // System, Dark, Light - Resolved Theme to Apply - w.theme = w.resolveTheme() + w.theme = resolveWindowsEffectiveTheme(options.Windows.Theme, globalApplication.theme) w.syncTheme() // Always listen to OS theme changes but only update the theme if we are following the application theme