5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 21:43:19 +08:00

[windows] Use application icon as default systray icon if available.

This commit is contained in:
Lea Anthony 2024-12-03 21:12:01 +11:00
parent b37cdf5ba9
commit f2040797d7
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
3 changed files with 36 additions and 6 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed service name determination by [windom](https://github.com/windom/) in [#3827](https://github.com/wailsapp/wails/pull/3827)
- mkdocs serve now uses docker by [leaanthony](https://github.com/leaanthony)
- Consolidated dev config into `config.yml` by [leaanthony](https://github.com/leaanthony)
- Systray dialog now defaults to the application icon if available (Windows) by [@leaanthony](https://github.com/leaanthony)
### Fixed
- Fixed cross-platform cleanup for .syso files during Windows build by [ansxuman](https://github.com/ansxuman) in [#3924](https://github.com/wailsapp/wails/pull/3924)

View File

@ -4,12 +4,11 @@ package application
import (
"fmt"
"github.com/wailsapp/wails/v3/pkg/icons"
"syscall"
"time"
"unsafe"
"github.com/wailsapp/wails/v3/pkg/icons"
"github.com/samber/lo"
"github.com/wailsapp/wails/v3/pkg/events"
@ -202,15 +201,21 @@ func (s *windowsSystemTray) run() {
panic(syscall.GetLastError())
}
if s.parent.icon != nil {
s.lightModeIcon = lo.Must(w32.CreateSmallHIconFromImage(s.parent.icon))
// Get the application icon if available
defaultIcon := w32.LoadIconWithResourceID(w32.GetModuleHandle(""), w32.RT_ICON)
if defaultIcon != 0 {
s.lightModeIcon = defaultIcon
s.darkModeIcon = defaultIcon
} else {
s.lightModeIcon = lo.Must(w32.CreateSmallHIconFromImage(icons.SystrayLight))
s.darkModeIcon = lo.Must(w32.CreateSmallHIconFromImage(icons.SystrayDark))
}
if s.parent.icon != nil {
s.lightModeIcon = lo.Must(w32.CreateSmallHIconFromImage(s.parent.icon))
}
if s.parent.darkModeIcon != nil {
s.darkModeIcon = lo.Must(w32.CreateSmallHIconFromImage(s.parent.darkModeIcon))
} else {
s.darkModeIcon = lo.Must(w32.CreateSmallHIconFromImage(icons.SystrayDark))
}
s.uid = nid.UID

View File

@ -159,6 +159,30 @@ const (
IDI_INFORMATION = IDI_ASTERISK
)
const (
RT_CURSOR = 1 // win32.MAKEINTRESOURCE(1)
RT_BITMAP = 2
RT_ICON = 3
RT_MENU = 4
RT_DIALOG = 5
RT_STRING = 6
RT_FONTDIR = 7
RT_FONT = 8
RT_ACCELERATOR = 9
RT_RCDATA = 10
RT_MESSAGETABLE = 11
RT_GROUP_CURSOR = 12
RT_GROUP_ICON = 14
RT_VERSION = 16
RT_DLGINCLUDE = 17
RT_PLUGPLAY = 19
RT_VXD = 20
RT_ANICURSOR = 21
RT_ANIICON = 22
RT_HTML = 23
RT_MANIFEST = 24
)
// Button style constants
const (
BS_3STATE = 5