tao icon indicating copy to clipboard operation
tao copied to clipboard

feat: add app activated event for macos

Open thewh1teagle opened this issue 9 months ago • 4 comments

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.

thewh1teagle avatar Apr 28 '24 23:04 thewh1teagle

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 avatar Apr 29 '24 08:04 FabianLars

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

FabianLars avatar Apr 29 '24 08:04 FabianLars

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?

thewh1teagle avatar Apr 29 '24 12:04 thewh1teagle

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.

FabianLars avatar Apr 29 '24 12:04 FabianLars

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.

pronebird avatar May 01 '24 07:05 pronebird

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

BillGoldenWater avatar May 01 '24 08:05 BillGoldenWater

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

pronebird avatar May 01 '24 14:05 pronebird