unoplatform / uno.extensions

Libraries to ease common developer tasks associated with building multi-platform mobile, desktop and web applications using Uno Platform or WinAppSDK.
https://platform.uno/
Other
72 stars 46 forks source link

`IHostApplicationLifetime.StopApplication()` does not quit the app and an empty page appears #2379

Open xperiandri opened 3 months ago

xperiandri commented 3 months ago

Current behavior

Expected behavior

As Uno Platform uses generic host it is expected to respect its lifetime management. However IHostApplicationLifetime.StopApplication() does not quit the app but opens and empty page.

How to reproduce it (as minimally and precisely as possible)

Create a hosted service Inject IHostApplicationLifetime Call StopApplication() in the StartAsync method See a blank window

Environment

Nuget Package (s): Uno.Extentions.Navigation.UI

Package Version(s): 4.1.24

Affected platform(s):

Visual Studio:

Anything else we need to know?

See https://github.com/kevinchalet/openiddict-core/blob/maui_winui_sample/sandbox/OpenIddict.Sandbox.Maui.Client/MauiHostApplicationLifetime.cs#L18 and https://github.com/kevinchalet/openiddict-core/blob/8a9bb17553f587f3b63002f9e40873f95c203f8a/sandbox/OpenIddict.Sandbox.Maui.Client/MauiProgram.cs#L110

xperiandri commented 3 months ago

So after I implemented it like this

public class UnoHostApplicationLifetime : ApplicationLifetime, IHostApplicationLifetime
{
    public UnoHostApplicationLifetime(ILogger<ApplicationLifetime> logger) : base(logger) { }

    CancellationToken IHostApplicationLifetime.ApplicationStarted => this.ApplicationStarted;

    CancellationToken IHostApplicationLifetime.ApplicationStopping => this.ApplicationStopping;

    CancellationToken IHostApplicationLifetime.ApplicationStopped => this.ApplicationStopped;

    void IHostApplicationLifetime.StopApplication()
    {
        this.StopApplication();
        Environment.Exit(0);
    }
}

the app closes, however after the main screen opens even though the hosted service calling StopApplication is the first one in the list