mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[v3 windows] Fix systray icon size
This commit is contained in:
parent
58138ac09b
commit
2eaf724710
4 changed files with 46 additions and 19 deletions
File diff suppressed because one or more lines are too long
|
|
@ -22,12 +22,14 @@ type systemTrayImpl interface {
|
|||
setIconPosition(position int)
|
||||
setTemplateIcon(icon []byte)
|
||||
destroy()
|
||||
setDarkModeIcon(icon []byte)
|
||||
}
|
||||
|
||||
type SystemTray struct {
|
||||
id uint
|
||||
label string
|
||||
icon []byte
|
||||
darkModeIcon []byte
|
||||
iconPosition int
|
||||
|
||||
leftButtonClickHandler func()
|
||||
|
|
@ -80,6 +82,17 @@ func (s *SystemTray) SetIcon(icon []byte) *SystemTray {
|
|||
return s
|
||||
}
|
||||
|
||||
func (s *SystemTray) SetDarkModeIcon(icon []byte) *SystemTray {
|
||||
if s.impl == nil {
|
||||
s.darkModeIcon = icon
|
||||
} else {
|
||||
invokeSync(func() {
|
||||
s.impl.setDarkModeIcon(icon)
|
||||
})
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SystemTray) SetMenu(menu *Menu) *SystemTray {
|
||||
if s.impl == nil {
|
||||
s.menu = menu
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
package application
|
||||
|
||||
import (
|
||||
"github.com/samber/lo"
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
"github.com/wailsapp/wails/v3/pkg/w32"
|
||||
"syscall"
|
||||
|
|
@ -75,12 +76,16 @@ func (s *windowsSystemTray) run() {
|
|||
panic(syscall.GetLastError())
|
||||
}
|
||||
|
||||
defaultIcon, err := w32.CreateHIconFromPNG(s.parent.icon)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if s.parent.icon != nil {
|
||||
s.lightModeIcon = lo.Must(w32.CreateHIconFromPNG(s.parent.icon))
|
||||
} else {
|
||||
s.lightModeIcon = lo.Must(w32.CreateHIconFromPNG(DefaultApplicationIcon))
|
||||
}
|
||||
if s.parent.darkModeIcon != nil {
|
||||
s.darkModeIcon = lo.Must(w32.CreateHIconFromPNG(s.parent.darkModeIcon))
|
||||
} else {
|
||||
s.darkModeIcon = s.lightModeIcon
|
||||
}
|
||||
s.lightModeIcon = defaultIcon
|
||||
s.darkModeIcon = defaultIcon
|
||||
s.uid = nid.UID
|
||||
|
||||
// TODO: Set Menu
|
||||
|
|
@ -133,18 +138,25 @@ func (s *windowsSystemTray) newNotifyIconData() w32.NOTIFYICONDATA {
|
|||
}
|
||||
|
||||
func (s *windowsSystemTray) setIcon(icon []byte) {
|
||||
// TODO:
|
||||
var err error
|
||||
if w32.IsCurrentlyDarkMode() {
|
||||
s.darkModeIcon, err = w32.CreateHIconFromPNG(icon)
|
||||
if err != nil {
|
||||
panic(syscall.GetLastError())
|
||||
}
|
||||
} else {
|
||||
s.lightModeIcon, err = w32.CreateHIconFromPNG(icon)
|
||||
if err != nil {
|
||||
panic(syscall.GetLastError())
|
||||
}
|
||||
s.lightModeIcon, err = w32.CreateHIconFromPNG(icon)
|
||||
if err != nil {
|
||||
panic(syscall.GetLastError())
|
||||
}
|
||||
if s.darkModeIcon == 0 {
|
||||
s.darkModeIcon = s.lightModeIcon
|
||||
}
|
||||
// Update the icon
|
||||
s.updateIcon()
|
||||
}
|
||||
func (s *windowsSystemTray) setDarkModeIcon(icon []byte) {
|
||||
var err error
|
||||
s.darkModeIcon, err = w32.CreateHIconFromPNG(icon)
|
||||
if err != nil {
|
||||
panic(syscall.GetLastError())
|
||||
}
|
||||
if s.lightModeIcon == 0 {
|
||||
s.lightModeIcon = s.darkModeIcon
|
||||
}
|
||||
// Update the icon
|
||||
s.updateIcon()
|
||||
|
|
|
|||
|
|
@ -29,13 +29,15 @@ func CreateIconFromResourceEx(presbits uintptr, dwResSize uint32, isIcon bool, v
|
|||
|
||||
// CreateHIconFromPNG creates a HICON from a PNG file
|
||||
func CreateHIconFromPNG(pngData []byte) (HICON, error) {
|
||||
iconWidth := GetSystemMetrics(SM_CXSMICON)
|
||||
iconHeight := GetSystemMetrics(SM_CYSMICON)
|
||||
icon, err := CreateIconFromResourceEx(
|
||||
uintptr(unsafe.Pointer(&pngData[0])),
|
||||
uint32(len(pngData)),
|
||||
true,
|
||||
0x00030000,
|
||||
0,
|
||||
0,
|
||||
iconWidth,
|
||||
iconHeight,
|
||||
LR_DEFAULTSIZE)
|
||||
return HICON(icon), err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue