jsakamoto / Toolbelt.Blazor.PWA.Updater

Provide "Update Now" UI and feature to your Blazor PWA that appears when the next version of one is available.
Mozilla Public License 2.0
135 stars 7 forks source link

NextVersionIsWaiting is not firing. #9

Open Laftek opened 1 year ago

Laftek commented 1 year ago

Hey Jsakamoto,

Great job with this package!!!

Unfortunately I couldnt get it run with my own UI. Below you can see code snippet for subscribing to NextVersionIsWaiting. I am pretty sure its me doing something wrong :/

here is github to repo (Component.razor has all the logic and its used in Index.razor) https://github.com/Laftek/BlazorAppWasmPWALottieRive

@code {
    public bool isUpdateReady { get; set; } = false;

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            this.PWAUpdaterService.NextVersionIsWaiting += PWAUpdaterService_NextVersionIsWaiting;
        }
    }
    private void PWAUpdaterService_NextVersionIsWaiting(object sender, EventArgs e)
    {
       isUpdateReady = true;
    }

    private async Task OnClickUpdateNowAsync()
    {
        await this.PWAUpdaterService.SkipWaitingAsync();
    }

    void IDisposable.Dispose()
    {
        this.PWAUpdaterService.NextVersionIsWaiting -= PWAUpdaterService_NextVersionIsWaiting;

    }
}

Thank you.

jsakamoto commented 1 year ago

@Laftek Could you confirm whether the NextVersionIsWaiting event really won't be happened or not? For example, insert Console.WriteLine(...) in the event handler method like below, run it, and watch the developer console of the web browser.

private void PWAUpdaterService_NextVersionIsWaiting(object sender, EventArgs e)
{
    Console.WriteLine("NextVersionIsWaiting was fired."); // 👈 Add this line.
    this.isUpdateReady = true;
}

And if the NextVersionIsWaiting event was fired, but the UI was not updated, please add invoking the StateHasChanged() method. The firing NextVersionIsWaiting event will never be aware from Blazor runtime, so UI updating never occurs automatically.

private void PWAUpdaterService_NextVersionIsWaiting(object sender, EventArgs e)
{
    this.isUpdateReady = true;
    this.StateHasChanged(); // 👈 Add this line.
}