From 62fcb602797903479ecd9fe95b8a229a44f03ba0 Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 2 Oct 2020 17:57:17 -0700 Subject: [PATCH] Handle Avalonia app lifetime differently so app doesn't exit when main window closes. --- Desktop.Linux/Program.cs | 8 +++++++- .../Services/RemoteControlAccessServiceLinux.cs | 17 +++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Desktop.Linux/Program.cs b/Desktop.Linux/Program.cs index 57fe93e1..6872d833 100644 --- a/Desktop.Linux/Program.cs +++ b/Desktop.Linux/Program.cs @@ -45,7 +45,7 @@ namespace Remotely.Desktop.Linux _ = Task.Run(() => { - BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + BuildAvaloniaApp().Start(AppMain, args); }); while (App.Current is null) @@ -85,6 +85,12 @@ namespace Remotely.Desktop.Linux } } + private static void AppMain(Application app, string[] args) + { + var cts = new CancellationTokenSource(); + app.Run(cts.Token); + } + private static void BuildServices() { var serviceCollection = new ServiceCollection(); diff --git a/Desktop.Linux/Services/RemoteControlAccessServiceLinux.cs b/Desktop.Linux/Services/RemoteControlAccessServiceLinux.cs index 8885d9ef..01efe722 100644 --- a/Desktop.Linux/Services/RemoteControlAccessServiceLinux.cs +++ b/Desktop.Linux/Services/RemoteControlAccessServiceLinux.cs @@ -15,7 +15,7 @@ namespace Remotely.Desktop.Linux.Services { public async Task PromptForAccess(string requesterName, string organizationName) { - var result = await Dispatcher.UIThread.InvokeAsync(async () => + return await Dispatcher.UIThread.InvokeAsync(async () => { var promptWindow = new PromptForAccessWindow(); var viewModel = promptWindow.DataContext as PromptForAccessWindowViewModel; @@ -28,14 +28,19 @@ namespace Remotely.Desktop.Linux.Services viewModel.OrganizationName = organizationName; } + var isOpen = true; + promptWindow.Closed += (sender, arg) => + { + isOpen = false; + }; promptWindow.Show(); - await TaskHelper.DelayUntilAsync(() => !promptWindow.IsVisible, TimeSpan.MaxValue); - + while (isOpen) + { + await Task.Delay(100); + } + return viewModel.PromptResult; }); - - - return result; } } }