wails icon indicating copy to clipboard operation
wails copied to clipboard

Support Tray Menus

Open leaanthony opened this issue 2 years ago • 3 comments

Wails should support Tray Menus for all platforms. It should support the features appropriate to each platform, EG text for Mac, icons for all platforms, etc.

leaanthony avatar Jul 03 '22 01:07 leaanthony

windows Tray(托盘)目前都没支持,非常不便

doc-war avatar Aug 10 '22 02:08 doc-war

Any ideas on what would be the right mode of implementation?

e.g Should we start off with using a stable package or implement it ourselves @leaanthony ?

I mean in terms of contributing to the wails project?

Seeing this as a candidate for the library package dependency. https://github.com/getlantern/systray

ha-sante avatar Aug 24 '22 12:08 ha-sante

Awesome that you'd like to contribute 🙏 Trays are literally the first cab off the rank post v2. There's some preliminary work in the exp branch if you want to have a look. I fear Linux may be a no-go with it as it's likely to need a library installed on the client machine because the Gnome project don't believe it should be there 🙄

leaanthony avatar Aug 24 '22 12:08 leaanthony

We would like to use this project (fantastic work btw) and have tray icon feature for the background workers for our cloud native ETL / data pipeline tool also written in Golang - https://github.com/dataplane-app/dataplane

@leaanthony When do you think this feature will be available?

saul-data avatar Oct 28 '22 18:10 saul-data

Congratulations on releasing dataplane! Looks cool. There are never ETAs on features, however this feature is currently in-progress. There is a PR open with RFC here: https://github.com/wailsapp/wails/pull/1959. Is this time critical for you?

leaanthony avatar Oct 29 '22 01:10 leaanthony

We were hoping to release in two weeks. We need the tray icon for basic open and exit a background process. I also want to show to users that it is running in the background. Is there any icon functionality available? I am not sure I need menus, just the icon to open and close the window. Once the window is open, we can then exit the app. To open the window, we can just click or double click the icon.

saul-data avatar Oct 29 '22 06:10 saul-data

Multi platform tray icons will not be ready in 2 weeks unfortunately.

leaanthony avatar Oct 29 '22 08:10 leaanthony

Will any platforms be available? We are focusing on Windows right now. Mac?

saul-data avatar Oct 29 '22 08:10 saul-data

There's the PR I linked. That's where we are at.

leaanthony avatar Oct 29 '22 08:10 leaanthony

Linux may be a no-go with it as it's likely to need a library installed on the client machine because the Gnome project don't believe it should be there roll_eyes

While it may require a library on Linux, I still think it's worth implementing something or at least giving a bit of boilerplate code to be able to have KStatusNotifierItem/AppIndicator support on Linux.

I understand you're working on Windows and Mac support first, but just wanted to put my vote in for Linux support, since we do have the capability of specifying dependencies, though maybe this is for dev only and not runtime? https://wails.io/docs/guides/linux-distro-support#adding-package-names

Thank you for the excellent project, and you have my sincerest gratitude for your effort!

StephenBrown2 avatar Nov 10 '22 16:11 StephenBrown2

Hi,

I think we could use Dbus with SystemNotifier/AppIndicator as our main implementaion. It seems to me that it could solve the problem on a big portion of the most used distros without depending on any installed C library. For example fyne-io only supports the DBus way.

I tried this on a few distros:

  • fedora latest (not working, default gnome)
  • fedora KDE (works)
  • kubuntu 22.04 (works)
  • kubuntu 20.04 (works)
  • ubuntu 22.04 gnome (works)
  • popOS 22.04 gnome (works)
  • linux mint cinnamon (works)
  • linux mint xfce (works)
  • linux mint mate (not working)

As a second option: If we want (have the time and determination to implement them) we could maybe hide the fallback implementations behind a build flag as an optional dependency?

And if the DBus way is not available fallback to libayatana-appindicator and maybe libappindicator3 if its not available and throw a warning if neither is available. Tauri does the same thing. Electron simply depends on libappindicator1. In the documentation we could inform the developers that the packaging and distribution of the libraries is their job.

lyimmi avatar Nov 11 '22 18:11 lyimmi

I'm happy with this approach. If only linux had some common installer mechanism to make this easy 🤦

leaanthony avatar Nov 11 '22 21:11 leaanthony

https://xkcd.com/927

I don't know if anyone is "assigned" to the linux part of the tray pr #1959, if you'd like @leaanthony I could pick it up in mid November.

lyimmi avatar Nov 11 '22 22:11 lyimmi

That would be amazing @Lyimmi Thank you! 🙏

leaanthony avatar Nov 11 '22 22:11 leaanthony

There's this fork also https://github.com/fyne-io/systray. It claims to remove GTK deps. might be worth looking at. I tried it with a wails app I'm building and no issues on Ubuntu 22.04 (GNOME 42.5) so far. The app is still under development though

Aceix avatar Nov 22 '22 11:11 Aceix

Yes, this is a Dbus implementation as well.

lyimmi avatar Nov 22 '22 12:11 lyimmi

Currently I'm working on a background app, which should mostly sits in the tray. Are there plans, the WebView can actually be closed and re-started, instead of hide and show? To hide the WebView in such a scenario would be a waste of ressources.

TheFranconianCoder avatar Feb 17 '23 13:02 TheFranconianCoder

Will be possible in v3 which has a much better API for such things 👍

leaanthony avatar Feb 17 '23 20:02 leaanthony

I've found a better fork of systray here, which supports left, right click and double (?) click: https://github.com/energye/systray

lthon09 avatar May 30 '23 09:05 lthon09

I've found a better fork of systray here, which supports left, right click and double (?) click: https://github.com/energye/systray

Used that before. Worked pretty well. 👍

TheFranconianCoder avatar May 30 '23 09:05 TheFranconianCoder

I'm currently using it in a Wails project, it provides a much easier to use API and even extra click callbacks. Seamlessly integrates with Wails :)

lthon09 avatar May 30 '23 13:05 lthon09

I'm glad there's a workaround for v2. We will have native support in v3 (already working pretty well for Mac and Windows)

leaanthony avatar Jun 01 '23 09:06 leaanthony

I'm currently using it in a Wails project, it provides a much easier to use API and even extra click callbacks. Seamlessly integrates with Wails :)

@lthon09 Would you mind giving me a glimpse on how you assembled the integration?

I'm glad there's a workaround for v2. We will have native support in v3 (already working pretty well for Mac and Windows)

@leaanthony I just stumbled upon a options.SystemTray and options.SystemTrayIcon with the help of intellisense. Is this fully implemented yet? I'm using v2.5.1.

dami-i avatar Jun 24 '23 02:06 dami-i

@leaanthony I just stumbled upon a options.SystemTray and options.SystemTrayIcon with the help of intellisense. Is this fully implemented yet? I'm using v2.5.1.

They were experiments. Ultimately, the v2 API is written specifically for single windows and that runs deep. I looked at adding it and it wasn't great so we've added it to v3 where the entire guts were built in a way to better support these features. A brave soul has made a project with it (even though it's alpha) and has screenshots here: https://github.com/duolabmeng6/go-qoq

leaanthony avatar Jun 24 '23 02:06 leaanthony

I'm currently using it in a Wails project, it provides a much easier to use API and even extra click callbacks. Seamlessly integrates with Wails :)

@lthon09 Would you mind giving me a glimpse on how you assembled the integration?

It's just using some basic features of the package, create some menu items for showing and quitting the program. Here's some example code:

package main

import (
	"github.com/energye/systray"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/runtime"
)

type _application struct {
	context _context.Context
}
var __application *_application

func systemTray() {
	systray.SetIcon([]byte()) // read the icon from a file

	show := systray.AddMenuItem("Show", "Show The Window")
	systray.AddSeparator()
	exit := systray.AddMenuItem("Exit", "Quit The Program")

	show.Click(func() {wailsRuntime.WindowShow(__application.context)})
	exit.Click(func() {os.Exit(0)})

	systray.SetOnClick(func() {wailsRuntime.WindowShow(__application.context)})
	systray.SetOnRClick(func(menu systray.IMenu) {menu.ShowMenu()})
}

func main() {
	__application = &_application{}
	wails.Run(&options.App{
		// ...

		OnStartup: __application.startUp,

		Bind: []interface{}{__application},
	})
}

func (application *_application) startUp(context _context.Context) {
	application.context = context
	systray.Run(systemTray, func() {})
}

It integrates with Wails really well. Sorry if my code looks unclean!

lthon09 avatar Jun 24 '23 04:06 lthon09

Closing this as it's intended for v3 and there's no more work to be done on it.

leaanthony avatar Aug 03 '23 22:08 leaanthony