@nativescript/windows-hermes 1.0.0-beta.11 → 1.0.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Runtime.InteropServices;
|
|
2
3
|
using System.Text.Json;
|
|
3
4
|
using Windows.ApplicationModel;
|
|
4
5
|
using Microsoft.UI.Dispatching;
|
|
@@ -31,7 +32,8 @@ namespace __PROJECT_NAME__
|
|
|
31
32
|
Shown = 3,
|
|
32
33
|
Hidden = 4,
|
|
33
34
|
UncaughtError = 5,
|
|
34
|
-
Exit = 6
|
|
35
|
+
Exit = 6,
|
|
36
|
+
ExitSupported = 7
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
public App()
|
|
@@ -72,6 +74,8 @@ namespace __PROJECT_NAME__
|
|
|
72
74
|
try
|
|
73
75
|
{
|
|
74
76
|
_runtimeHost.RunMainScript();
|
|
77
|
+
// Tells the app it may end itself (Application.Exit()) once its last window closes.
|
|
78
|
+
_runtimeHost.NotifyAppEvent((int)AppEventKind.ExitSupported, null);
|
|
75
79
|
jsError = _runtimeHost.GetLastJsError();
|
|
76
80
|
if (!string.IsNullOrEmpty(jsError))
|
|
77
81
|
{
|
|
@@ -117,13 +121,35 @@ namespace __PROJECT_NAME__
|
|
|
117
121
|
}
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
// This window is never shown, so it only closes when the app exits. JavaScript ends the app
|
|
125
|
+
// itself (Application.Exit()) once its last window closes, from inside a callback: the
|
|
126
|
+
// runtime is still on the stack then, so it is disposed after the current dispatcher work
|
|
127
|
+
// item has unwound.
|
|
120
128
|
private void OnWindowClosed(object sender, WindowEventArgs e)
|
|
121
129
|
{
|
|
122
130
|
StopPump();
|
|
123
131
|
_runtimeHost.NotifyAppEvent((int)AppEventKind.Exit, null);
|
|
124
132
|
try { ApplicationData.Current.LocalSettings.Values[LastLaunchArgsKey] = string.Empty; }
|
|
125
133
|
catch (InvalidOperationException) { } // unpackaged: no ApplicationData
|
|
134
|
+
|
|
135
|
+
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
|
136
|
+
if (dispatcherQueue == null || !dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, Shutdown))
|
|
137
|
+
{
|
|
138
|
+
Shutdown();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
[DllImport("user32.dll")]
|
|
143
|
+
private static extern void PostQuitMessage(int exitCode);
|
|
144
|
+
|
|
145
|
+
private void Shutdown()
|
|
146
|
+
{
|
|
126
147
|
_runtimeHost.Dispose();
|
|
148
|
+
|
|
149
|
+
// WinUI ignores Application.Exit() while no activated window is open
|
|
150
|
+
// (microsoft-ui-xaml#5931), which is the case once the app's windows have all closed,
|
|
151
|
+
// so the message loop is ended directly.
|
|
152
|
+
PostQuitMessage(0);
|
|
127
153
|
}
|
|
128
154
|
|
|
129
155
|
private void OnWindowActivated(object sender, WindowActivatedEventArgs e)
|
|
Binary file
|