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 activate event on macOS #218

Closed
1 of 2 tasks
JonasKruckenberg opened this issue Oct 11, 2021 · 22 comments
Closed
1 of 2 tasks

Support activate event on macOS #218

JonasKruckenberg opened this issue Oct 11, 2021 · 22 comments

Comments

@JonasKruckenberg
Copy link
Member

Is your feature request related to a problem? Please describe.
On macOS clicking the applications dock icon does a few things depending on the context:

  • launch the application
  • focus windows
  • if all windows are closed create a new one
    Afaik all these events are communicated through the appkit::NSEventSubtype::NSApplicationActivatedEventType event. Can we expose this even to consumers somehow?

Describe the solution you'd like
Add an ActivationEvent member to the tao::event::Event enum. This would mirror the appkit::NSEventSubtype::NSApplicationActivatedEventType event.

Describe alternatives you've considered
Some of this can be implemented through the use of WindowEvent::Focus, but that will only be fired on a per-window basis, not when all windows are closed.

Would you assign yourself to implement this feature?

  • Yes
  • No

Additional context
Add any other context or screenshots about the feature request here.

@xuchaoqian
Copy link

Sound great!
May I ask what's the status of this feature?

@0rvar
Copy link

0rvar commented Jan 12, 2023

I am very interested in this feature as well

@BB-fat
Copy link

BB-fat commented Apr 28, 2024

Three years have passed and this feature has not been implemented yet?

@martpie
Copy link

martpie commented Apr 28, 2024

See here for a working example, the feature exists, it's just not very explicit

https://github.com/martpie/museeks/blob/tauri/src-tauri/src/plugins/app_close.rs

Or there reply to the main Tauri issue: tauri-apps/tauri#3084 (comment)

@BillGoldenWater
Copy link
Contributor

See here for a working example, the feature exists, it's just not very explicit

https://github.com/martpie/museeks/blob/tauri/src-tauri/src/plugins/app_close.rs

it's actually not the same thing,

the activate event is a event that you can handle when user click the dock icon,

the plugin just mimic the effect of show the window on the event, and if you use the plugin, the window will not actually close when user click the close button

@BB-fat
Copy link

BB-fat commented Apr 28, 2024

See here for a working example, the feature exists, it's just not very explicit

https://github.com/martpie/museeks/blob/tauri/src-tauri/src/plugins/app_close.rs

Or there reply to the main Tauri issue: tauri-apps/tauri#3084 (comment)

This solution is useless when the business has multiple windows.

@thewh1teagle
Copy link

thewh1teagle commented Apr 28, 2024

I'm also interested in active event on macOS. I use single-instance plugin in v2 project, and I keep the app running even when the main window is closed, but when the user try to launch another instance, macOS focus the current running instance by default but it doesn't trigger events on the app so it focus nothing.

@pronebird
Copy link

I can't believe it takes that long to send an event in response to applicationDidBecomeActive. What can be done to push this forward?

@BillGoldenWater
Copy link
Contributor

since tao is a fork of winit and it's planned to keep features sync with it(#470) for switch back to it in the feature, so probably need this issue(rust-windowing/winit#2120) be completed

@amrbashir
Copy link
Member

amrbashir commented Apr 30, 2024

the switch back to winit has been delayed indefinitely for now, let's move forward and worry about the switch later.

@FabianLars
Copy link
Member

We've broken compatibility with 2120 a few times already anyway ^^

@pronebird
Copy link

As @BillGoldenWater mentioned and I had verified that NSApplicationActivatedEventType is not a solution. For example when user closes the last visible window, the app stays focused, i.e the menu is still visible in the top left corner in the menubar and the click on dock does not fire NSApplicationActivatedEventType. Instead applicationShouldHandleReopen is called on AppDelegate.

@thewh1teagle
Copy link

@pronebird It's not intended to do that. It's a "focus" event in the app (not on windows). It's useful if you click the icon when the app isn't in focus, or when the app is closed to the tray and you try to open it from applications or from the dock. It will focus the app, and the activated event will emit. Could you clarify why you need the event when the user clicks the icon while the app is already in focus?

@BillGoldenWater
Copy link
Contributor

BillGoldenWater commented May 1, 2024

This issue by my understand is about emit an event when click on the dock icon regardless the state of focus

@BillGoldenWater
Copy link
Contributor

and a side note, the appkit::NSEventSubtype::NSApplicationActivatedEventType is deprecated

@pronebird
Copy link

pronebird commented May 1, 2024

@pronebird It's not intended to do that. It's a "focus" event in the app (not on windows). It's useful if you click the icon when the app isn't in focus, or when the app is closed to the tray and you try to open it from applications or from the dock. It will focus the app, and the activated event will emit. Could you clarify why you need the event when the user clicks the icon while the app is already in focus?

The problem is that when the user closes the last visible window, the app stays in focus. To my understanding, the click on dock tile would typically open a new "untitled document" window, in a typical document based native app. But there is no hook for that in tauri.

As a side note, I already capture NSApplicationDidBecomeActiveNotification via CFNotificationCenter and that works but doesn't cut it because it's only triggered when the app regains focus but not when all windows are closed and the user clicks on dock tile while the app is still focused.

I would actually like to show the new window if user clicks on dock tile when there are no visible windows left. This is what applicationShouldHandleReopen:hasVisibleWindows: is for.

@thewh1teagle
Copy link

thewh1teagle commented May 1, 2024

Thanks, so I tested shouldHandleReopen from #517 and it works great on macOS 14.4.1 aarch64
It worked when:

  • User click the app icon in the dock (always emit)
  • User click the app icon in Applications folder / launcher when app already running (Useful for single instance plugin)

I hope that it will be merged soon, added to Wry, and make its way into Tauri finally

Update: merged to tao and soon to tauri

@pronebird
Copy link

Thanks, so I tested shouldHandleReopen from #517 and it works great on macOS 14.4.1 aarch64 It worked when:

  • User click the app icon in the dock (always emit)
  • User click the app icon in Applications folder / launcher when app already running (Useful for single instance plugin)

I hope that it will be merged soon, added to Wry, and make its way into Tauri finally

yeah totally that should also work for single instance plugin and eliminate the need for flock-based mutex or whatever is used there.

@FabianLars
Copy link
Member

It won't work for the single instance plugin, or at least can't replace the current logic. The single instance plugin on MacOS really only handles when the app is opened from the console which doesn't emit this event (otherwise the MacOS native single instance mechanism would trigger already)

@pronebird
Copy link

It won't work for the single instance plugin, or at least can't replace the current logic. The single instance plugin on MacOS really only handles when the app is opened from the console which doesn't emit this event (otherwise the MacOS native single instance mechanism would trigger already)

Any console or just npm run tauri dev? If dev mode is a concern then perhaps it doesn't matter all that much as it should work fine in production.

@FabianLars
Copy link
Member

any console. the contributor(s) iirc had a cli interface for their app in build mode too and that didn't trigger the macos single instance mechanism.

@ayangweb
Copy link

See here for a working example, the feature exists, it's just not very explicit
https://github.com/martpie/museeks/blob/tauri/src-tauri/src/plugins/app_close.rs
Or there reply to the main Tauri issue: tauri-apps/tauri#3084 (comment)

This solution is useless when the business has multiple windows.

Hey 👋, excuse me! Did you implement the applicationShouldHandleReopen method for multi-window triggering?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📬Proposal
Development

No branches or pull requests