-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
166 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@if (IsInstallable) | ||
{ | ||
<button @ref="Button" class="btn btn-link navbar-btn nav-link" @onclick="InstallAsync" title="Install as application to your device" data-toggle="tooltip" data-placement="bottom"> | ||
<Icon Identifier="download" /> | ||
Install | ||
</button> | ||
} | ||
else if(IsUpdateable) | ||
{ | ||
<button @ref="Button" class="btn btn-link navbar-btn nav-link" @onclick="UpdateAsync" title="Application update is ready. Reload page to complete." data-toggle="tooltip" data-placement="bottom"> | ||
<Icon Identifier="download" /> | ||
Update | ||
</button> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using Money.Services; | ||
using Neptuo.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Components | ||
{ | ||
public partial class PwaInstall : ComponentBase, IDisposable | ||
{ | ||
[Inject] | ||
internal PwaInstallInterop Interop { get; set; } | ||
|
||
[Inject] | ||
internal ILog<PwaInstall> Log { get; set; } | ||
|
||
[Inject] | ||
internal Navigator Navigator { get; set; } | ||
|
||
protected ElementReference Button { get; set; } | ||
protected bool IsInstallable { get; set; } | ||
protected bool IsUpdateable { get; set; } | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Log.Debug("OnInitialized"); | ||
|
||
base.OnInitialized(); | ||
Interop.Initialize(this); | ||
} | ||
|
||
//protected async override Task OnAfterRenderAsync(bool firstRender) | ||
//{ | ||
// await base.OnAfterRenderAsync(firstRender); | ||
|
||
// if (IsInstallable) | ||
// await Tooltip.InitializeAsync(Button); | ||
//} | ||
|
||
public void MakeInstallable() | ||
{ | ||
Log.Debug("Installable=True"); | ||
|
||
IsInstallable = true; | ||
StateHasChanged(); | ||
} | ||
|
||
public void MakeUpdateable() | ||
{ | ||
Log.Debug("Updateable=True"); | ||
|
||
IsUpdateable = true; | ||
StateHasChanged(); | ||
} | ||
|
||
protected async Task InstallAsync() | ||
{ | ||
await Interop.InstallAsync(); | ||
IsInstallable = false; | ||
} | ||
|
||
protected async Task UpdateAsync() | ||
=> await Navigator.ReloadAsync(); | ||
|
||
public void Dispose() | ||
{ | ||
Interop.Remove(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Microsoft.JSInterop; | ||
using Neptuo; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Money.Components | ||
{ | ||
public class PwaInstallInterop | ||
{ | ||
private static List<PwaInstall> editors = new List<PwaInstall>(); | ||
private readonly IJSRuntime jSRuntime; | ||
|
||
public PwaInstallInterop(IJSRuntime jSRuntime) | ||
{ | ||
Ensure.NotNull(jSRuntime, "jSRuntime"); | ||
this.jSRuntime = jSRuntime; | ||
} | ||
|
||
public void Initialize(PwaInstall editor) | ||
{ | ||
Ensure.NotNull(editor, "editor"); | ||
editors.Add(editor); | ||
} | ||
|
||
public void Remove(PwaInstall editor) | ||
{ | ||
Ensure.NotNull(editor, "editor"); | ||
editors.Remove(editor); | ||
} | ||
|
||
[JSInvokable("Pwa.Installable")] | ||
public static void Installable() | ||
{ | ||
foreach (var editor in editors) | ||
editor.MakeInstallable(); | ||
} | ||
|
||
[JSInvokable("Pwa.Updateable")] | ||
public static void Updateable() | ||
{ | ||
foreach (var editor in editors) | ||
editor.MakeUpdateable(); | ||
} | ||
|
||
public ValueTask InstallAsync() | ||
=> jSRuntime.InvokeVoidAsync("BlazorPWA.installPWA"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters