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

[v3 mac] Update api. New template icon.

This commit is contained in:
Lea Anthony 2023-05-09 21:38:38 +10:00
parent 0b9cd4be5d
commit b91468b6f2
5 changed files with 47 additions and 1 deletions

View File

@ -30,7 +30,7 @@ func main() {
systemTray := app.NewSystemTray() systemTray := app.NewSystemTray()
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
systemTray.SetIcon(icons.SystrayMacTemplate) systemTray.SetTemplateIcon(icons.SystrayMacTemplate)
} }
myMenu := app.NewMenu() myMenu := app.NewMenu()

View File

@ -4,6 +4,8 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"image" "image"
"image/color"
"image/png"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -124,3 +126,39 @@ func generateWindowsIcon(iconData []byte, sizes []int, options *IconsOptions) er
} }
return nil return nil
} }
func GenerateTemplateIcon(data []byte, outputFilename string) error {
// Decode the input file as a PNG
buffer := bytes.NewBuffer(data)
img, err := png.Decode(buffer)
if err != nil {
return fmt.Errorf("failed to decode input file as PNG: %w", err)
}
// Create a new image with the same dimensions and RGBA color model
bounds := img.Bounds()
iconImg := image.NewRGBA(bounds)
// Iterate over each pixel of the input image
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
// Get the alpha of the pixel
_, _, _, a := img.At(x, y).RGBA()
iconImg.SetRGBA(x, y, color.RGBA{R: 0, G: 0, B: 0, A: uint8(a)})
}
}
// Create the output file
outFile, err := os.Create(outputFilename)
if err != nil {
return fmt.Errorf("failed to create output file: %w", err)
}
defer outFile.Close()
// Encode the template icon image as a PNG and write it to the output file
if err := png.Encode(outFile, iconImg); err != nil {
return fmt.Errorf("failed to encode output image as PNG: %w", err)
}
return nil
}

View File

@ -91,6 +91,10 @@ type macosSystemTray struct {
isTemplateIcon bool isTemplateIcon bool
} }
func (s *macosSystemTray) setDarkModeIcon(icon []byte) {
// Is this even possible?
}
func (s *macosSystemTray) setIconPosition(position int) { func (s *macosSystemTray) setIconPosition(position int) {
s.iconPosition = position s.iconPosition = position
} }

View File

@ -808,6 +808,10 @@ type macosWebviewWindow struct {
parent *WebviewWindow parent *WebviewWindow
} }
func (w *macosWebviewWindow) focus() {
//TODO implement me
}
func (w *macosWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData) { func (w *macosWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData) {
// Create the menu // Create the menu
thisMenu := newMenuImpl(menu) thisMenu := newMenuImpl(menu)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 669 B