SQL-MisterMagoo / Blazor.PWA.MSBuild

An MSBuild package which adds simple PWA functionality to Blazor client-side Apps
MIT License
96 stars 11 forks source link

Install UI through Blazor rather than default banner? #15

Open ThatRickGuy opened 4 years ago

ThatRickGuy commented 4 years ago

Looking through your documentation, it sounds like I should be able to put the install button inside my app, but attempting to call await JSRuntime.InvokeAsync<object>("BlazorPWA.installPWA"); results in a WASM error: Microsoft.JSInterop.JSException: Could not find 'BlazorPWA' in 'window'.

I'm assuming I missed a step in there somewhere. I see the ServiceWorker.js and ServiceWorkerRegister.js, but nothing that contains installPWA.

Any pointers for getting the install to kick off from in Blazor, or is the banner the only option?

SQL-MisterMagoo commented 4 years ago

you will need some settings in your csproj

<PropertyGroup Label="PWA">
<ServiceWorkerRegisterInstallableType>installable-blazor</ServiceWorkerRegisterInstallableType>
<ServiceWorkerForce>true</ServiceWorkerForce>
</PropertyGroup>

ServiceWorkerRegisterInstallableType tells it you are using Blazor for the install prompt

ServiceWorkerForce just lets it update the generated files - remove it when you have it working

dknittl commented 4 years ago

I found this to be a great explanation on how to creat a custom install prompt in Blazor: https://wellsb.com/csharp/aspnet/create-pwa-from-blazor-app/