diff options
author | Rory& <root@rory.gay> | 2024-01-29 10:15:27 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-29 10:15:27 +0100 |
commit | 3e6a73599bb58161c08d8675ea23ee6c82c6675c (patch) | |
tree | f3c0d1e797a77ed5993478d742751d386e004fb7 /MatrixUtils.Web/Shared/UpdateAvailableDetector.razor | |
parent | Room member migrations (diff) | |
download | MatrixUtils-3e6a73599bb58161c08d8675ea23ee6c82c6675c.tar.xz |
Room list fixes, migration fix, update available handler
Diffstat (limited to 'MatrixUtils.Web/Shared/UpdateAvailableDetector.razor')
-rw-r--r-- | MatrixUtils.Web/Shared/UpdateAvailableDetector.razor | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/MatrixUtils.Web/Shared/UpdateAvailableDetector.razor b/MatrixUtils.Web/Shared/UpdateAvailableDetector.razor new file mode 100644 index 0000000..5197a6f --- /dev/null +++ b/MatrixUtils.Web/Shared/UpdateAvailableDetector.razor @@ -0,0 +1,38 @@ +@* Source: https://whuysentruit.medium.com/blazor-wasm-pwa-adding-a-new-update-available-notification-d9f65c4ad13 *@ +@inject IJSRuntime _jsRuntime + +@if (_newVersionAvailable) +{ + <button type="button" class="btn btn-warning shadow floating-update-button" onclick="window.location.reload()"> + A new version of the application is available. Click here to reload. + </button> +} + +@code { + + private bool _newVersionAvailable = false; + + protected override async Task OnInitializedAsync() + { + await RegisterForUpdateAvailableNotification(); + } + + private async Task RegisterForUpdateAvailableNotification() + { + await _jsRuntime.InvokeAsync<object>( + identifier: "registerForUpdateAvailableNotification", + DotNetObjectReference.Create(this), + nameof(OnUpdateAvailable)); + } + + [JSInvokable(nameof(OnUpdateAvailable))] + public Task OnUpdateAvailable() + { + _newVersionAvailable = true; + + StateHasChanged(); + + return Task.CompletedTask; + } + +} \ No newline at end of file |