UIMessage communication. Single instancing for server and re-connection mechanism on suspension.

This commit is contained in:
Burak Kaan Köse
2024-07-17 22:36:10 +02:00
parent ad1c7e1fd3
commit 329eae3a25
87 changed files with 412 additions and 321 deletions

View File

@@ -66,6 +66,8 @@ namespace Wino
UnhandledException += OnAppUnhandledException;
EnteredBackground += OnEnteredBackground;
LeavingBackground += OnLeavingBackground;
Resuming += OnResuming;
Suspending += OnSuspending;
Services = ConfigureServices();
@@ -87,6 +89,15 @@ namespace Wino
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
private async void OnResuming(object sender, object e)
{
// App Service connection was lost on suspension.
// We must restore it.
// Server might be running already, but re-launching it will trigger a new connection attempt.
await _appServiceConnectionManager.ConnectAsync();
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
@@ -328,10 +339,12 @@ namespace Wino
yield return Services.GetService<FileActivationHandler>();
}
public void OnBackgroundTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
public async void OnBackgroundTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
Log.Information($"Background task {sender.Task.Name} was canceled. Reason: {reason}");
await _appServiceConnectionManager.DisconnectAsync();
backgroundTaskDeferral?.Complete();
backgroundTaskDeferral = null;