fyne icon indicating copy to clipboard operation
fyne copied to clipboard

Hide the icon in taskbar on Windows or hide the icon in Dockbar on Mac

Open fanmmy opened this issue 2 years ago • 12 comments

Checklist

  • [X] I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • [X] 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?

My app only has a SystemTrayMenu, and I want hide the icon in taskbar.

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

no exisiting API

Describe the solution you'd like to see.

provide an API to do it.

fanmmy avatar Jul 22 '22 08:07 fanmmy

It seems like there is more to a "sys tray app" than just not closing when there are no windows... Though each of these small behaviours seems to be desired or not so much in different workflows. The right API may be tough here.

andydotxyz avatar Jul 23 '22 14:07 andydotxyz

I second this requirement. At least on macOS it is quite usual that users want to have a systray entry, but only if they can as well decide to hide the app from the dock. Thank you for consideration.

jeannot-muller avatar Jul 29 '22 11:07 jeannot-muller

Perhaps I have misunderstood, but you can create a windowless app with just a sysTray like this:

func main() {
	a := app.New()

	if desk, ok := a.(desktop.App); ok {
		m := fyne.NewMenu("MyApp",
			fyne.NewMenuItem("Hello", func() {
				log.Println("Hello")
			}))
		desk.SetSystemTrayMenu(m)
	}

	fyne.CurrentApp().Driver().Run()
}

itsjustdel avatar Aug 16 '22 12:08 itsjustdel

Perhaps I have misunderstood, but you can create a windowless app with just a sysTray like this:

func main() {
	a := app.New()

	if desk, ok := a.(desktop.App); ok {
		m := fyne.NewMenu("MyApp",
			fyne.NewMenuItem("Hello", func() {
				log.Println("Hello")
			}))
		desk.SetSystemTrayMenu(m)
	}

	fyne.CurrentApp().Driver().Run()
}

these code make the app has none-window, but has icon on dockbar .

image

fanmmy avatar Aug 20 '22 10:08 fanmmy

I see, on Windows, I do not see an icon in the taskbar, only in the sysTray. Sorry I can't be of more help.

itsjustdel avatar Aug 22 '22 10:08 itsjustdel

Perhaps I have misunderstood, but you can create a windowless app with just a sysTray like this:

func main() {
	a := app.New()

	if desk, ok := a.(desktop.App); ok {
		m := fyne.NewMenu("MyApp",
			fyne.NewMenuItem("Hello", func() {
				log.Println("Hello")
			}))
		desk.SetSystemTrayMenu(m)
	}

	fyne.CurrentApp().Driver().Run()
}

these code make the app has none-window, but has icon on dockbar .

image

I want to hide the Dockicon too, I want only remain the trayicon in menu bar and no icon in dockrbar on macOS, anyone who knows how to do it?

xiebruce avatar Oct 18 '22 14:10 xiebruce

Marking this as specific to macOS and Linux (some Linux) as it is an OS specific item we would need to add support for. Not sure what the parameter/API would look like here, possibly the icon is removed from the doc when systray is on and no windows are visible?

andydotxyz avatar Oct 21 '22 07:10 andydotxyz

Marking this as specific to macOS and Linux (some Linux) as it is an OS specific item we would need to add support for. Not sure what the parameter/API would look like here, possibly the icon is removed from the doc when systray is on and no windows are visible?

maybe something like this https://github.com/fyne-io/fyne/discussions/3344

aj3423 avatar Oct 21 '22 07:10 aj3423

I actually had this use case myself and considered putting in a PR for it. I don't know how to do this cross-platform (why I didn't submit a PR or patch fyne), but this is how I accomplished it on Mac. Note you don't need to patch Fyne to use this. You can use this as a workaround, or use some of this to accomplish this in fyne when building a real solution. For a real solution I think you may also want to provide a method set this value in the info.plist.

activationpolicy.go

package main

/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>

int
SetActivationPolicy(void) {
    [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
    return 0;
}
*/
import "C"
import "fmt"

func setActivationPolicy() {
	fmt.Println("Setting ActivationPolicy")
	C.SetActivationPolicy()
}

usage:

	a.Lifecycle().SetOnStarted(func() {
		go func() {
			time.Sleep(200 * time.Millisecond)
			setActivationPolicy()
		}()
	})

Note the 200ms sleep, I forgot why I had to do this. But I think it had something to do with either what thread I ran on, or (more likely) glfw hardcoding it and me having to wait until after that code ran.

WetDesertRock avatar Oct 29 '22 04:10 WetDesertRock

mac Info.plist add

<key>LSUIElement</key><string>true</string>

docs https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement

zangdale avatar Dec 14 '22 10:12 zangdale

@zangdale I believe that would work if this line didn't exist: https://github.com/fyne-io/fyne/blob/6e90820ea9ca4df836db5a99384c51073415571e/internal/driver/mobile/app/darwin_desktop.m#L190

WetDesertRock avatar Dec 14 '22 23:12 WetDesertRock