-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add an event so that users can detect when an Application icon is clicked #14106
Add an event so that users can detect when an Application icon is clicked #14106
Conversation
Should it be called something else so it's consistent with the rest of the Avalonia events? EG |
I think we are good with one of two possible APIs:
|
I think it's the best choice, I think we should also migrate IApplicationPlatformEvents. |
@workgroupengineering yes, it would make sense there too |
@maxkatz6 @workgroupengineering, had an offline discussion with @maxkatz6, will implement the above suggestion, but making it part of the application lifetime interface. |
Refactored using lifetimes and updated the description to show api usage. |
{ | ||
event EventHandler<ActivatedEventArgs> Activated; | ||
|
||
event EventHandler<ActivatedEventArgs> Deactivated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should split these args, and add DeactivatedEventArgs instead of reusing. Maybe even with DeactivationKind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I interpreted correctly what @danwalmsley meant if ActivationKind.Background
occurs in the Activated event, it indicates that the app has been reactivated from suspension, otherwise in Deactivated it indicates that the app has been suspended. So for each of the elements of the enum.
If so I would suggest renaming:
ActivatedEventArgs in ApplicationStateEventArgs
ActivationKind in ApplicationStateKind
and create
ApplicationStateActivatedEventArgs: ApplicationStateEventArgs
ApplicationStateDeactivatedEventArgs: ApplicationStateEventArgs
cc @robloo
You can test this PR using the following package version. |
You can test this PR using the following package version. |
This allows the dock icon to be kept in sync so its menu options there say "Hide" / "Show" correctly.
You can test this PR using the following package version. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
…cked (#14106) * Add an event so that users can detect when an Application icon is clicked. * refactor to use Lifetime apis. * use ActivationKind instead of reason to be consistent with other xaml platforms * implement macos raise url events. * add docs. * add apis to programatically Activate and Deactivate the application. This allows the dock icon to be kept in sync so its menu options there say "Hide" / "Show" correctly. * fix api naming. * Add Browser IActivatableApplicationLifetime impl * Implement IActivatableApplicationLifetime on Android * Add IActivatableApplicationLifetime iOS implementation * Adjust android impl a little --------- Co-authored-by: Max Katz <maxkatz6@outlook.com> #Conflicts: # src/Browser/Avalonia.Browser/Interop/InputHelper.cs # src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts
On OSX when using
ShutdownMode.OnExplicitShutdown
, and the application has all its windows closed, the application icon remains in the Dock.Most end-users expect that clicking the Dock icon will re-open the main window of the application. (See safari and other similar apps on MacOS).
However since there is no way for an Avalonia application to detect or handle this event, Avalonia applications can not implement this behaviour.
Applications can also not detect when the Dock icon is right clicked-> Hide or right clicked and Show... where the application is placed into a background state on macOS.
This PR adds anApplication.Clicked
event which only gets triggered on MacOS when the Dock icon (which represents theApplication
and not aWindow
) is clicked.This PR adds an
IActivatableLifetime
that providesActivated
andDeactivated
events with event args providing the reason.This api covers all bases for the specified scenarios on OSX and the api can be used as follows:
This allows the developer to handle this in any way and implement the behaviour they wish for their application.