Browse Source
Added some new plumbing to facilitate this: - A managed event is raised `IPlatformLifetimeEventsImpl.ShutdownRequested` - This event is subscribed from `ClassicDesktopStyleApplicationLifetime` - Which tries to close all windows - And returns false to cancel the OS-level close if not all windows could be closedpull/6174/head
6 changed files with 58 additions and 3 deletions
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.ComponentModel; |
|||
|
|||
namespace Avalonia.Platform |
|||
{ |
|||
public interface IPlatformLifetimeEventsImpl |
|||
{ |
|||
/// <summary>
|
|||
/// Raised by the platform when a shutdown is requested.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Raised on on OSX via the Quit menu or right-clicking on the application icon and selecting Quit.
|
|||
/// </remarks>
|
|||
event EventHandler<CancelEventArgs> ShutdownRequested; |
|||
} |
|||
} |
|||
@ -1,14 +1,25 @@ |
|||
using System; |
|||
using System.ComponentModel; |
|||
using Avalonia.Native.Interop; |
|||
using Avalonia.Platform; |
|||
|
|||
namespace Avalonia.Native |
|||
{ |
|||
internal class AvaloniaNativeApplicationPlatform : CallbackBase, IAvnApplicationEvents |
|||
internal class AvaloniaNativeApplicationPlatform : CallbackBase, IAvnApplicationEvents, IPlatformLifetimeEventsImpl |
|||
{ |
|||
public event EventHandler<CancelEventArgs> ShutdownRequested; |
|||
|
|||
void IAvnApplicationEvents.FilesOpened(IAvnStringArray urls) |
|||
{ |
|||
((IApplicationPlatformEvents)Application.Current).RaiseUrlsOpened(urls.ToStringArray()); |
|||
} |
|||
|
|||
public int TryShutdown() |
|||
{ |
|||
if (ShutdownRequested is null) return 1; |
|||
var e = new CancelEventArgs(); |
|||
ShutdownRequested(this, e); |
|||
return (!e.Cancel).AsComBool(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue