-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an event so that users can detect when an Application icon is cli…
…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
- Loading branch information
1 parent
6b5a9a7
commit 8bd4941
Showing
26 changed files
with
438 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
|
||
namespace Avalonia.Android | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
|
||
namespace Avalonia.Android; | ||
|
||
public interface IAvaloniaActivity : IActivityResultHandler, IActivityNavigationService | ||
{ | ||
event EventHandler<ActivatedEventArgs> Activated; | ||
event EventHandler<ActivatedEventArgs> Deactivated; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Avalonia.Controls/ApplicationLifetimes/ActivatedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
|
||
namespace Avalonia.Controls.ApplicationLifetimes; | ||
|
||
/// <summary> | ||
/// Event args for an Application Lifetime Activated or Deactivated events. | ||
/// </summary> | ||
public class ActivatedEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// Ctor for ActivatedEventArgs | ||
/// </summary> | ||
/// <param name="kind">The <see cref="ActivationKind"/> that this event represents</param> | ||
public ActivatedEventArgs(ActivationKind kind) | ||
{ | ||
Kind = kind; | ||
} | ||
|
||
/// <summary> | ||
/// The <see cref="ActivationKind"/> that this event represents. | ||
/// </summary> | ||
public ActivationKind Kind { get; } | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Avalonia.Controls/ApplicationLifetimes/ActivationKind.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Avalonia.Controls.ApplicationLifetimes; | ||
|
||
public enum ActivationKind | ||
{ | ||
/// <summary> | ||
/// When the application is passed a URI to open. | ||
/// </summary> | ||
OpenUri = 20, | ||
|
||
/// <summary> | ||
/// When the application is asked to reopen. | ||
/// An example of this is on MacOS when all the windows are closed, | ||
/// application continues to run in the background and the user clicks | ||
/// the application's dock icon. | ||
/// </summary> | ||
Reopen = 30, | ||
|
||
/// <summary> | ||
/// When the application enters or leaves a background state. | ||
/// An example is when on MacOS the user hides or shows and application (not window), | ||
/// or when a browser application switchs tabs or when a mobile applications goes into | ||
/// the background. | ||
/// </summary> | ||
Background = 40 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Avalonia.Controls/ApplicationLifetimes/IActivatableApplicationLifetime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
|
||
namespace Avalonia.Controls.ApplicationLifetimes; | ||
|
||
/// <summary> | ||
/// An interface for ApplicationLifetimes where the application can be Activated and Deactivated. | ||
/// </summary> | ||
public interface IActivatableApplicationLifetime | ||
{ | ||
/// <summary> | ||
/// An event that is raised when the application is Activated for various reasons | ||
/// as described by the <see cref="ActivationKind"/> enumeration. | ||
/// </summary> | ||
event EventHandler<ActivatedEventArgs> Activated; | ||
|
||
/// <summary> | ||
/// An event that is raised when the application is Deactivated for various reasons | ||
/// as described by the <see cref="ActivationKind"/> enumeration. | ||
/// </summary> | ||
event EventHandler<ActivatedEventArgs> Deactivated; | ||
|
||
/// <summary> | ||
/// Tells the application that it should attempt to leave its background state. | ||
/// For example on OSX this would be [NSApp unhide] | ||
/// </summary> | ||
/// <returns>true if it was possible and the platform supports this. false otherwise</returns> | ||
public bool TryLeaveBackground(); | ||
|
||
/// <summary> | ||
/// Tells the application that it should attempt to enter its background state. | ||
/// For example on OSX this would be [NSApp hide] | ||
/// </summary> | ||
/// <returns>true if it was possible and the platform supports this. false otherwise</returns> | ||
public bool TryEnterBackground(); | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Avalonia.Controls/ApplicationLifetimes/ProtocolActivatedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Avalonia.Controls.ApplicationLifetimes; | ||
|
||
public class ProtocolActivatedEventArgs : ActivatedEventArgs | ||
{ | ||
public ProtocolActivatedEventArgs(ActivationKind kind, Uri uri) : base(kind) | ||
{ | ||
Uri = uri; | ||
} | ||
|
||
public Uri Uri { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.