5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 19:31:20 +08:00
wails/v2/internal/frontend/desktop/windows/theme.go
Misite Bao f70d9de366
fix: fix go test errors (#2169)
* fix: fix go test errors

* Add flags to mac test

* Run on all branches

* Update PR workflow

Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
2022-12-06 06:45:06 +11:00

68 lines
1.8 KiB
Go

//go:build windows
package windows
import (
"github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/win32"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
func (w *Window) UpdateTheme() {
// Don't redraw theme if nothing has changed
if !w.themeChanged {
return
}
w.themeChanged = false
if win32.IsCurrentlyHighContrastMode() {
return
}
if !win32.SupportsThemes() {
return
}
var isDarkMode bool
switch w.theme {
case windows.SystemDefault:
isDarkMode = win32.IsCurrentlyDarkMode()
case windows.Dark:
isDarkMode = true
case windows.Light:
isDarkMode = false
}
win32.SetTheme(w.Handle(), isDarkMode)
// Custom theme processing
winOptions := w.frontendOptions.Windows
var customTheme *windows.ThemeSettings
if winOptions != nil {
customTheme = winOptions.CustomTheme
}
// Custom theme
if win32.SupportsCustomThemes() && customTheme != nil {
if w.isActive {
if isDarkMode {
win32.SetTitleBarColour(w.Handle(), customTheme.DarkModeTitleBar)
win32.SetTitleTextColour(w.Handle(), customTheme.DarkModeTitleText)
win32.SetBorderColour(w.Handle(), customTheme.DarkModeBorder)
} else {
win32.SetTitleBarColour(w.Handle(), customTheme.LightModeTitleBar)
win32.SetTitleTextColour(w.Handle(), customTheme.LightModeTitleText)
win32.SetBorderColour(w.Handle(), customTheme.LightModeBorder)
}
} else {
if isDarkMode {
win32.SetTitleBarColour(w.Handle(), customTheme.DarkModeTitleBarInactive)
win32.SetTitleTextColour(w.Handle(), customTheme.DarkModeTitleTextInactive)
win32.SetBorderColour(w.Handle(), customTheme.DarkModeBorderInactive)
} else {
win32.SetTitleBarColour(w.Handle(), customTheme.LightModeTitleBarInactive)
win32.SetTitleTextColour(w.Handle(), customTheme.LightModeTitleTextInactive)
win32.SetBorderColour(w.Handle(), customTheme.LightModeBorderInactive)
}
}
}
}