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

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

Open
2 tasks done
fanmmy opened this issue Jul 22, 2022 · 12 comments
Open
2 tasks done

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

fanmmy opened this issue Jul 22, 2022 · 12 comments
Labels
enhancement New feature or request OS:Linux Tickets affecting only Linux OS:macOS Tickets affecting only macOS

Comments

@fanmmy
Copy link

fanmmy commented Jul 22, 2022

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?

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.

@andydotxyz andydotxyz changed the title How to hide the icon in taskbar on Windows or hide the icon in Dockbar on Mac? Hide the icon in taskbar on Windows or hide the icon in Dockbar on Mac Jul 23, 2022
@andydotxyz andydotxyz added the enhancement New feature or request label Jul 23, 2022
@andydotxyz
Copy link
Member

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.

@jeannot-muller
Copy link

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.

@itsjustdel
Copy link
Contributor

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()
}

@fanmmy
Copy link
Author

fanmmy commented Aug 20, 2022

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

@itsjustdel
Copy link
Contributor

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.

@xiebruce
Copy link

xiebruce commented Oct 18, 2022

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?

@andydotxyz andydotxyz added OS:macOS Tickets affecting only macOS OS:Linux Tickets affecting only Linux labels Oct 21, 2022
@andydotxyz
Copy link
Member

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?

@aj3423
Copy link

aj3423 commented Oct 21, 2022

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
#3344

@WetDesertRock
Copy link
Contributor

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.

@zangdale
Copy link

mac Info.plist add

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

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

@WetDesertRock
Copy link
Contributor

WetDesertRock commented Dec 14, 2022

@zangdale I believe that would work if this line didn't exist:

[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

charlesmmarshall added a commit to ministryofjustice/opg-aws-key-rotation-scheduler-app that referenced this issue Feb 8, 2023
based on fyne issue - fyne-io/fyne#3156 (comment) - this seems to be needed as well as the plist change to ensure the app starts in the background
swapped NewWithID to New as the id is set within the FyneApp toml config
@xiebruce
Copy link

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.

It works 👍, the Dock icon will show then vanish, I tried comment time.Sleep(100 * time.Millisecond) out, it still works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OS:Linux Tickets affecting only Linux OS:macOS Tickets affecting only macOS
Projects
None yet
Development

No branches or pull requests

8 participants