Handle Avalonia app lifetime differently so app doesn't exit when main window closes.

This commit is contained in:
Jared 2020-10-02 17:57:17 -07:00 committed by Jared Goodwin
parent 702d7402a1
commit 62fcb60279
2 changed files with 18 additions and 7 deletions

View File

@ -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();

View File

@ -15,7 +15,7 @@ namespace Remotely.Desktop.Linux.Services
{
public async Task<bool> 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;
}
}
}