mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[V3] feat: add Windows getAccentColor implementation (#4427)
* [V3] feat: add Windows getAccentColor implementation --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com>
This commit is contained in:
parent
9d6e6232d6
commit
33a9c05213
5 changed files with 35 additions and 22 deletions
|
|
@ -31,7 +31,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Windows dark theme menus + menubar. By @leaanthony in [a29b4f0861b1d0a700e9eb213c6f1076ec40efd5](https://github.com/wailsapp/wails/commit/a29b4f0861b1d0a700e9eb213c6f1076ec40efd5)
|
||||
- Rename built-in services for clearer JS/TS bindings by @popaprozac in [PR](https://github.com/wailsapp/wails/pull/4405)
|
||||
|
||||
|
||||
## v3.0.0-alpha.12 - 2025-07-15
|
||||
|
||||
### Added
|
||||
|
|
@ -482,9 +481,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- 🐧 add task `run:linux` by
|
||||
[@marcus-crane](https://github.com/marcus-crane) in
|
||||
[#3146](https://github.com/wailsapp/wails/pull/3146)
|
||||
- Export `SetIcon` method by @almas1992 in
|
||||
- Export `SetIcon` method by [@almas-x](https://github.com/almas-x) in
|
||||
[PR](https://github.com/wailsapp/wails/pull/3147)
|
||||
- Improve `OnShutdown` by @almas1992 in
|
||||
- Improve `OnShutdown` by [@almas-x](https://github.com/almas-x) in
|
||||
[PR](https://github.com/wailsapp/wails/pull/3189)
|
||||
- Restore `ToggleMaximise` method in `Window` interface by
|
||||
[@fbbdev](https://github.com/fbbdev) in
|
||||
|
|
@ -555,7 +554,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Fixed bug for linux in doctor in the event user doesn't have proper drivers
|
||||
installed. Added by [@pylotlight](https://github.com/pylotlight) in
|
||||
[PR](https://github.com/wailsapp/wails/pull/3032)
|
||||
- Fix dpi scaling on start up (windows). Changed by @almas1992 in
|
||||
- Fix dpi scaling on start up (windows). Changed by [@almas-x](https://github.com/almas-x) in
|
||||
[PR](https://github.com/wailsapp/wails/pull/3145)
|
||||
- Fix replace line in `go.mod` to use relative paths. Fixes Windows paths with
|
||||
spaces - @leaanthony.
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- [darwin] add option for showing the toolbar in fullscreen mode on macOS by [@fbbdev](https://github.com/fbbdev) in [#3282](https://github.com/wailsapp/wails/pull/3282)
|
||||
- [linux] add onKeyPress logic to convert linux keypress into an accelerator @[Atterpac](https://github.com/Atterpac) in[#3022](https://github.com/wailsapp/wails/pull/3022])
|
||||
- [linux] add task `run:linux` by [@marcus-crane](https://github.com/marcus-crane) in [#3146](https://github.com/wailsapp/wails/pull/3146)
|
||||
- Export `SetIcon` method by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3147)
|
||||
- Improve `OnShutdown` by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3189)
|
||||
- Export `SetIcon` method by [@almas-x](https://github.com/almas-x) in [PR](https://github.com/wailsapp/wails/pull/3147)
|
||||
- Improve `OnShutdown` by [@almas-x](https://github.com/almas-x) in [PR](https://github.com/wailsapp/wails/pull/3189)
|
||||
- Restore `ToggleMaximise` method in `Window` interface by [@fbbdev](https://github.com/fbbdev) in [#3281](https://github.com/wailsapp/wails/pull/3281)
|
||||
- Added more information to `Environment()`. By @leaanthony in [aba82cc](https://github.com/wailsapp/wails/commit/aba82cc52787c97fb99afa58b8b63a0004b7ff6c) based on [PR](https://github.com/wailsapp/wails/pull/2044) by @Mai-Lapyst
|
||||
- Expose the `WebviewWindow.IsFocused` method on the `Window` interface by [@fbbdev](https://github.com/fbbdev) in [#3295](https://github.com/wailsapp/wails/pull/3295)
|
||||
|
|
@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Fixed hex values for arrow keys on Darwin by [jaybeecave](https://github.com/jaybeecave) in [#3052](https://github.com/wailsapp/wails/pull/3052).
|
||||
- Set drag-n-drop for windows to working. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/3039)
|
||||
- Fixed bug for linux in doctor in the event user doesn't have proper drivers installed. Added by [@pylotlight](https://github.com/pylotlight) in [PR](https://github.com/wailsapp/wails/pull/3032)
|
||||
- Fix dpi scaling on start up (windows). Changed by @almas1992 in [PR](https://github.com/wailsapp/wails/pull/3145)
|
||||
- Fix dpi scaling on start up (windows). Changed by [@almas-x](https://github.com/almas-x) in [PR](https://github.com/wailsapp/wails/pull/3145)
|
||||
- Fix replace line in `go.mod` to use relative paths. Fixes Windows paths with spaces - @leaanthony.
|
||||
- Fix MacOS systray click handling when no attached window by [thomas-senechal](https://github.com/thomas-senechal) in PR [#3207](https://github.com/wailsapp/wails/pull/3207)
|
||||
- Fix failing Windows build due to unknown option by [thomas-senechal](https://github.com/thomas-senechal) in PR [#3208](https://github.com/wailsapp/wails/pull/3208)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ After processing, the content will be moved to the main changelog and this file
|
|||
|
||||
## Added
|
||||
<!-- New features, capabilities, or enhancements -->
|
||||
- Add Windows `getAccentColor` implementation by [@almas-x](https://github.com/almas-x) in [PR](https://github.com/wailsapp/wails/pull/4427)
|
||||
|
||||
## Changed
|
||||
<!-- Changes in existing functionality -->
|
||||
|
|
|
|||
|
|
@ -57,9 +57,13 @@ func (m *windowsApp) isDarkMode() bool {
|
|||
}
|
||||
|
||||
func (m *windowsApp) getAccentColor() string {
|
||||
// Windows doesn't have a simple accent color API in the current w32 package
|
||||
// Return a default blue color
|
||||
return "rgb(0,122,255)"
|
||||
accentColor, err := w32.GetAccentColor()
|
||||
if err != nil {
|
||||
m.parent.error("failed to get accent color: %w", err)
|
||||
return "rgb(0,122,255)"
|
||||
}
|
||||
|
||||
return accentColor
|
||||
}
|
||||
|
||||
func (m *windowsApp) isOnMainThread() bool {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
package w32
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
|
|
@ -145,18 +146,6 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
//procAllowDarkModeForApp, err := windows.GetProcAddressByOrdinal(localUXTheme, uintptr(137))
|
||||
//if err == nil {
|
||||
// procAllowDarkModeForApplication = func(hwnd HWND, allow bool) uintptr {
|
||||
// var allowInt int32
|
||||
// if allow {
|
||||
// allowInt = 1
|
||||
// }
|
||||
// ret, _, _ := syscall.SyscallN(procAllowDarkModeForApp, uintptr(allowInt))
|
||||
// return ret
|
||||
// }
|
||||
//}
|
||||
|
||||
// Initialize dark mode
|
||||
if SetPreferredAppMode != nil {
|
||||
SetPreferredAppMode(PreferredAppModeAllowDark)
|
||||
|
|
@ -300,6 +289,26 @@ func IsCurrentlyHighContrastMode() bool {
|
|||
return r
|
||||
}
|
||||
|
||||
func GetAccentColor() (string, error) {
|
||||
key, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\DWM`, registry.QUERY_VALUE)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
accentColor, _, err := key.GetIntegerValue("AccentColor")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Extract RGB components from ABGR format (Alpha, Blue, Green, Red)
|
||||
red := uint8(accentColor & 0xFF)
|
||||
green := uint8((accentColor >> 8) & 0xFF)
|
||||
blue := uint8((accentColor >> 16) & 0xFF)
|
||||
|
||||
return fmt.Sprintf("rgb(%d,%d,%d)", red, green, blue), nil
|
||||
}
|
||||
|
||||
// OpenThemeData opens theme data for a window and its class
|
||||
func OpenThemeData(hwnd HWND, pszClassList string) HTHEME {
|
||||
ret, _, _ := procOpenThemeData.Call(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue