Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support template images on MacOS for menubar icons. #4549

Closed
2 tasks done
flowchartsman opened this issue Jan 21, 2024 · 4 comments
Closed
2 tasks done

Support template images on MacOS for menubar icons. #4549

flowchartsman opened this issue Jan 21, 2024 · 4 comments

Comments

@flowchartsman
Copy link

flowchartsman commented Jan 21, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

As mentioned in #4548, fyne.io/v2/app does not support template images which are the recommended format for system tray and menubar icons. This leads to an app that uses out-of-place colored icons or monochromatic icons which do not change in response to the system theme or to accessibility settings that call for high contrast. The only way to partially get this functionality is to import fyne.io/systray directly and call SetTemplateIcon, which allows at least the systray icon to be templated, however this does not extend to MenuItems.

Is it possible to construct a solution with the existing API?

Only partially (see above).

Describe the solution you'd like to see.

This is a toughie, since icons are only available as fyne.Resource values. A medium-lift solution could involve adding a TemplatedResource interface that these images could implement:

package fyne

type TemplatedResource interface {
    Resource
    Templated() bool
}

Which would require changes to fyne bundle to accept a flag or a naming convention to embed certain resources with a type conforming to this interface; however a better solution would probably involve deeper changes to fyne bundle (and resources overall) allowing bundle to detect file types and even embed platform-specific assets following a similar convention to Go build flag suffixes for filenames, such that:

embeds/
  myIcon.png
  myIcon_mac.png
  mySecondIcon.png
  mySecondIcon_windows.png
  mySecondIcon_mac_templated.png

would result in two resources: resourceMyIcon, which would be tagged as an image with mac and !mac variants and resourceMySecondIcon, which would be tagged as an image with windows and templated mac variants and a fallback to be used on other platforms.

This is likely getting into v3 territory, however.

@andydotxyz
Copy link
Member

There's a lot of interesting thoughts here, but I don't follow how having a version of an icon called "_templated" helps to use template icons in systray?
More simply we could either add SetTemplateSystrayIcon or just make use of the existing ThemedResource to be used as a template image in the systray context?
i.e. SetSystemTrayIcon(theme.NewThemedResource(iconData))?
seems much simpler and uses existing APIs.

@flowchartsman
Copy link
Author

Simply exposing SetTemplateSystrayIcon is probably a good start, though given the general guidance to prefer templated images on macOS, it's probably worth considering how it might be handled in a default way. I like the idea of using ThemedResource for that, since, as you say, it already exists. It wasn't clear on how themed resources worked when I first submitted the issue, but after digging around in the code, it looks as if they require an SVG and then just swap out the fill color? If that's the case, SetSystemTrayIcon could then just conditionally rasterize themed resources to black on macOS, which would solve the issue neatly!

@andydotxyz
Copy link
Member

Exposing a call particularly useful for macOS kinda goes against platform-agnostic design. Passing in a ThemedResource allows us to do the right thing per-platform under the hood.

@andydotxyz
Copy link
Member

Fixed on the develop branch as proposed (passing theme.ThemedResource) will be available in v2.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants