mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 20:03:01 +08:00

* Add Windows version helper * Initial theme support * Support custom themes * Update docs * Honour HighContrast theme. Remove import "C". Refactor * Small refactor * Support inactive theme * Update Docs
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
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() {
|
|
|
|
if win32.IsCurrentlyHighContrastMode() {
|
|
return
|
|
}
|
|
|
|
if !win32.SupportsThemes() {
|
|
return
|
|
}
|
|
// Only process if there's a theme change
|
|
isDarkMode := win32.IsCurrentlyDarkMode()
|
|
w.isDarkMode = isDarkMode
|
|
|
|
// Default use system theme
|
|
winOptions := w.frontendOptions.Windows
|
|
var customTheme *windows.ThemeSettings
|
|
if winOptions != nil {
|
|
customTheme = winOptions.CustomTheme
|
|
if winOptions.Theme == windows.Dark {
|
|
isDarkMode = true
|
|
}
|
|
if winOptions.Theme == windows.Light {
|
|
isDarkMode = false
|
|
}
|
|
}
|
|
|
|
win32.SetTheme(w.Handle(), isDarkMode)
|
|
|
|
// Custom theme
|
|
if win32.SupportsCustomThemes() && customTheme != nil {
|
|
if w.isActive {
|
|
if isDarkMode {
|
|
println("1")
|
|
win32.SetTitleBarColour(w.Handle(), customTheme.DarkModeTitleBar)
|
|
win32.SetTitleTextColour(w.Handle(), customTheme.DarkModeTitleText)
|
|
win32.SetBorderColour(w.Handle(), customTheme.DarkModeBorder)
|
|
} else {
|
|
println("2")
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|