lindexi
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
28 additions and
8 deletions
src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs
src/Avalonia.Controls/ApplicationLifetimes/ShutdownRequestedEventArgs.cs
src/Avalonia.X11/X11PlatformLifetimeEvents.cs
src/Windows/Avalonia.Win32/Win32Platform.cs
@ -1,4 +1,4 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Runtime.CompilerServices ;
using System.Threading ;
@ -188,7 +188,10 @@ namespace Avalonia.Controls.ApplicationLifetimes
if ( w . Owner is null )
{
var ignoreCancel = force | | ( ShutdownMode = = ShutdownMode . OnMainWindowClose & & w ! = MainWindow ) ;
w . CloseCore ( WindowCloseReason . ApplicationShutdown , isProgrammatic , ignoreCancel ) ;
var reason = e . IsOSShutdown ?
WindowCloseReason . OSShutdown :
WindowCloseReason . ApplicationShutdown ;
w . CloseCore ( reason , isProgrammatic , ignoreCancel ) ;
}
}
@ -4,6 +4,9 @@ namespace Avalonia.Controls.ApplicationLifetimes
{
public class ShutdownRequestedEventArgs : CancelEventArgs
{
/// <summary>
/// Is the operating system shutting down
/// </summary>
internal bool IsOSShutdown { get ; init ; }
}
}
@ -1,4 +1,4 @@
using System ;
using System ;
using System.Text ;
using System.Collections.Concurrent ;
using System.Runtime.InteropServices ;
@ -229,7 +229,10 @@ namespace Avalonia.X11
{
if ( state is IntPtr smcConn )
{
var e = new ShutdownRequestedEventArgs ( ) ;
var e = new ShutdownRequestedEventArgs ( )
{
IsOSShutdown = true ,
} ;
if ( _ platform . Options . EnableSessionManagement )
{
@ -1,4 +1,4 @@
using System ;
using System ;
using System.ComponentModel ;
using System.Diagnostics.CodeAnalysis ;
using System.IO ;
@ -148,11 +148,22 @@ namespace Avalonia.Win32
{
if ( ShutdownRequested ! = null )
{
var e = new ShutdownRequestedEventArgs ( ) ;
// https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession
// > LPARAM lParam // logoff option
// >
// > This parameter can be one or more of the following values. If this parameter is 0, the system is shutting down or restarting (it is not possible to determine which event is occurring).
// >
// > - ENDSESSION_CLOSEAPP 0x00000001 The application is using a file that must be replaced, the system is being serviced, or system resources are exhausted. For more information, see Guidelines for Applications.
// > - ENDSESSION_CRITICAL 0x40000000 The application is forced to shut down.
// > - ENDSESSION_LOGOFF 0x80000000 The user is logging off.
var e = new ShutdownRequestedEventArgs ( )
{
IsOSShutdown = lParam = = IntPtr . Zero ,
} ;
ShutdownRequested ( this , e ) ;
if ( e . Cancel )
if ( e . Cancel )
{
return IntPtr . Zero ;
}