mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-11 14:39:30 +08:00
[v3 windows] Fix systray icon size
This commit is contained in:
parent
19a654a2b1
commit
1ed270fe05
File diff suppressed because one or more lines are too long
@ -22,12 +22,14 @@ type systemTrayImpl interface {
|
|||||||
setIconPosition(position int)
|
setIconPosition(position int)
|
||||||
setTemplateIcon(icon []byte)
|
setTemplateIcon(icon []byte)
|
||||||
destroy()
|
destroy()
|
||||||
|
setDarkModeIcon(icon []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemTray struct {
|
type SystemTray struct {
|
||||||
id uint
|
id uint
|
||||||
label string
|
label string
|
||||||
icon []byte
|
icon []byte
|
||||||
|
darkModeIcon []byte
|
||||||
iconPosition int
|
iconPosition int
|
||||||
|
|
||||||
leftButtonClickHandler func()
|
leftButtonClickHandler func()
|
||||||
@ -80,6 +82,17 @@ func (s *SystemTray) SetIcon(icon []byte) *SystemTray {
|
|||||||
return s
|
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 {
|
func (s *SystemTray) SetMenu(menu *Menu) *SystemTray {
|
||||||
if s.impl == nil {
|
if s.impl == nil {
|
||||||
s.menu = menu
|
s.menu = menu
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
package application
|
package application
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/samber/lo"
|
||||||
"github.com/wailsapp/wails/v3/pkg/events"
|
"github.com/wailsapp/wails/v3/pkg/events"
|
||||||
"github.com/wailsapp/wails/v3/pkg/w32"
|
"github.com/wailsapp/wails/v3/pkg/w32"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -75,12 +76,16 @@ func (s *windowsSystemTray) run() {
|
|||||||
panic(syscall.GetLastError())
|
panic(syscall.GetLastError())
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultIcon, err := w32.CreateHIconFromPNG(s.parent.icon)
|
if s.parent.icon != nil {
|
||||||
if err != nil {
|
s.lightModeIcon = lo.Must(w32.CreateHIconFromPNG(s.parent.icon))
|
||||||
panic(err)
|
} 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
|
s.uid = nid.UID
|
||||||
|
|
||||||
// TODO: Set Menu
|
// TODO: Set Menu
|
||||||
@ -133,18 +138,25 @@ func (s *windowsSystemTray) newNotifyIconData() w32.NOTIFYICONDATA {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *windowsSystemTray) setIcon(icon []byte) {
|
func (s *windowsSystemTray) setIcon(icon []byte) {
|
||||||
// TODO:
|
|
||||||
var err error
|
var err error
|
||||||
if w32.IsCurrentlyDarkMode() {
|
s.lightModeIcon, err = w32.CreateHIconFromPNG(icon)
|
||||||
s.darkModeIcon, err = w32.CreateHIconFromPNG(icon)
|
if err != nil {
|
||||||
if err != nil {
|
panic(syscall.GetLastError())
|
||||||
panic(syscall.GetLastError())
|
}
|
||||||
}
|
if s.darkModeIcon == 0 {
|
||||||
} else {
|
s.darkModeIcon = s.lightModeIcon
|
||||||
s.lightModeIcon, err = w32.CreateHIconFromPNG(icon)
|
}
|
||||||
if err != nil {
|
// Update the icon
|
||||||
panic(syscall.GetLastError())
|
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
|
// Update the icon
|
||||||
s.updateIcon()
|
s.updateIcon()
|
||||||
|
@ -29,13 +29,15 @@ func CreateIconFromResourceEx(presbits uintptr, dwResSize uint32, isIcon bool, v
|
|||||||
|
|
||||||
// CreateHIconFromPNG creates a HICON from a PNG file
|
// CreateHIconFromPNG creates a HICON from a PNG file
|
||||||
func CreateHIconFromPNG(pngData []byte) (HICON, error) {
|
func CreateHIconFromPNG(pngData []byte) (HICON, error) {
|
||||||
|
iconWidth := GetSystemMetrics(SM_CXSMICON)
|
||||||
|
iconHeight := GetSystemMetrics(SM_CYSMICON)
|
||||||
icon, err := CreateIconFromResourceEx(
|
icon, err := CreateIconFromResourceEx(
|
||||||
uintptr(unsafe.Pointer(&pngData[0])),
|
uintptr(unsafe.Pointer(&pngData[0])),
|
||||||
uint32(len(pngData)),
|
uint32(len(pngData)),
|
||||||
true,
|
true,
|
||||||
0x00030000,
|
0x00030000,
|
||||||
0,
|
iconWidth,
|
||||||
0,
|
iconHeight,
|
||||||
LR_DEFAULTSIZE)
|
LR_DEFAULTSIZE)
|
||||||
return HICON(icon), err
|
return HICON(icon), err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user