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 2c3fb9f86..ee8ad2352 100644 Binary files a/v3/pkg/icons/DefaultMacTemplateIcon.png and b/v3/pkg/icons/DefaultMacTemplateIcon.png differ