fyne
fyne copied to clipboard
Hide the icon in taskbar on Windows or hide the icon in Dockbar on Mac
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.
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.
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.
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()
}
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 .

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.
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 .
![]()
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?
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?
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
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.
mac Info.plist add
<key>LSUIElement</key><string>true</string>
docs https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement
@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