From b91468b6f27c6fb282eaf09b425a557fdc2d6852 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 9 May 2023 21:38:38 +1000 Subject: [PATCH] [v3 mac] Update api. New template icon. --- v3/examples/systray/main.go | 2 +- v3/internal/commands/icons.go | 38 ++++++++++++++++++++ v3/pkg/application/systemtray_darwin.go | 4 +++ v3/pkg/application/webview_window_darwin.go | 4 +++ v3/pkg/icons/DefaultMacTemplateIcon.png | Bin 1142 -> 669 bytes 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/v3/examples/systray/main.go b/v3/examples/systray/main.go index c6e8d282..a8a27f87 100644 --- a/v3/examples/systray/main.go +++ b/v3/examples/systray/main.go @@ -30,7 +30,7 @@ func main() { systemTray := app.NewSystemTray() if runtime.GOOS == "darwin" { - systemTray.SetIcon(icons.SystrayMacTemplate) + systemTray.SetTemplateIcon(icons.SystrayMacTemplate) } myMenu := app.NewMenu() diff --git a/v3/internal/commands/icons.go b/v3/internal/commands/icons.go index 4eee8734..f4fcf7a7 100644 --- a/v3/internal/commands/icons.go +++ b/v3/internal/commands/icons.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" "image" + "image/color" + "image/png" "os" "strconv" "strings" @@ -124,3 +126,39 @@ func generateWindowsIcon(iconData []byte, sizes []int, options *IconsOptions) er } 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 +} diff --git a/v3/pkg/application/systemtray_darwin.go b/v3/pkg/application/systemtray_darwin.go index f5a46434..1c675018 100644 --- a/v3/pkg/application/systemtray_darwin.go +++ b/v3/pkg/application/systemtray_darwin.go @@ -91,6 +91,10 @@ type macosSystemTray struct { isTemplateIcon bool } +func (s *macosSystemTray) setDarkModeIcon(icon []byte) { + // Is this even possible? +} + func (s *macosSystemTray) setIconPosition(position int) { s.iconPosition = position } diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 60305c49..ed39aa92 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -808,6 +808,10 @@ type macosWebviewWindow struct { parent *WebviewWindow } +func (w *macosWebviewWindow) focus() { + //TODO implement me +} + func (w *macosWebviewWindow) openContextMenu(menu *Menu, data *ContextMenuData) { // Create the menu thisMenu := newMenuImpl(menu) diff --git a/v3/pkg/icons/DefaultMacTemplateIcon.png b/v3/pkg/icons/DefaultMacTemplateIcon.png index 2c3fb9f86e2a3a37d0632e51dc933eadda8328ee..ee8ad23524f32e67189acdc3fa1e014f7cb70b13 100644 GIT binary patch delta 552 zcmeyyF_(3M3Tr}uPl)S8!-V=@{x5nN7#I{vg8YIR9`XpVOZki5iFHc#YTICTYHyj+ z<*9kg7uJU99-Gy#S*BG~&cMKU#?!?yB;xSfYqyJ<3LDCy8SSdy_#_V9)9`*OYSLC;aD(6F z;cTX-6OGnqdmpXZ@zi-G?+d0=sVjxF`n(IDJMUzj5Oy|*HzdV7@Z-WuY)|gI+7jcq zhLPW{XzRIyt+Q3{A2qztFuCU}o5`J=N1TZXPaY+*R;~3fxyHS3&aGWNMi)dBcuf{O zxxZJ|W6R2OtQXe3O<-5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