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 c6e8d282a..a8a27f878 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 4eee8734f..f4fcf7a7c 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 f5a464341..1c6750185 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 60305c49a..ed39aa927 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 zcmV+@0@wZa2%QCxBn4nlOjJdYF<^iCPw0&R001C#QchC<;S3N58c!A6T|#9_hOjou zy>=qgm2Rh@eO4{TnvW@VDsp!K00GQNL_t(o!|m4Fa)K}r2H<5u1IQUU2p-=5En8rB zHnE)~j2Cq}{x`Uge1rrL_~f4jcO?4RJyaq3CsYV#Xon^C4j97TC`;uPG=_h0*bhYE zn*!yLGOue(#d^5qL#Yku0?K8n5-N^Mapyz11&~(FQVmpOOHuKm(gx(*>a<)ztN{-` za<$IEg_|Yc#WB!;lZ?#7TWf-eB= zx~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