tauri-apps / tao

The TAO of cross-platform windowing. A library in Rust built for Tauri.
Apache License 2.0
1.63k stars 191 forks source link

feat: add app activated event for macos #911

Closed thewh1teagle closed 6 months ago

thewh1teagle commented 6 months ago

This PR adds Activated event for macOS, resolving #218.

Useful in two cases:

  1. When the app is open but no windows are visible, clicking its icon in the dock will emit the Activated event.
  2. When the app is running in the background with no windows, and you try to open it again, macOS usually brings the already open instance to the front (without activating windows, so nothing happens). With this change, the Activated event will be emitted in such cases.
FabianLars commented 6 months ago

Thanks for contributing! I am not one of the main maintainers so take this with a grain of salt, but i've worked with events a while back and i think that this feature should use the NSApplicationDelegate's shouldHandleReopen method instead. The problem with that is that we'd need to figure out how to return a bool dynamically (or always false since the default behavior doesn't seem to apply to tauri apps anyway).

FabianLars commented 6 months ago

Ahh, i forgot. We already have a PR for what i just said: https://github.com/tauri-apps/tao/pull/517

thewh1teagle commented 6 months ago

Oh I didn't knew about this event, that looks better because we can control the default behavior too. Does tao / tauri already use winit? (Like mentioned there) So we can merge it?

FabianLars commented 6 months ago

No, and winit still doesn't support this. But we've changed the approach since then and started merging PRs that use platform specific apis even if winit doesn't support them yet.

pronebird commented 6 months ago

applicationShouldHandleReopen sounds like a thing used for document based apps.

I found it simpler to rely on applicationDidBecomeActive which fires every time the app activates.

BillGoldenWater commented 6 months ago

I think this event isn't a solution for #218, it's not emitted for the click on dock icon, and it's emitted every time the app gains focus

I think it's usage would be pair with applicationDidResignActive and their "will" variant for handle lose/gain focus of entire app

pronebird commented 6 months ago

@BillGoldenWater I think you're right, it doesn't trigger if the app is in focus but doesn't have any windows open.