Initial commit: Lagerbestand Blazor Projekt
This commit is contained in:
commit
cba9414e92
105 files changed
+36431
No files matched your search
@@ -0,0 +1,43 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Lagerbestand.Components.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Helper that wires a page's reload method to the browser's
|
||||
/// <c>visibilitychange</c> event via <c>appInterop.registerVisibilityRefresh</c>.
|
||||
/// The caller owns the <see cref="DotNetObjectReference"/> passed in.
|
||||
/// </summary>
|
||||
public static class VisibilityRefresh
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers a .NET callback invoked when the browser tab becomes
|
||||
/// visible again after being hidden for at least <paramref name="thresholdSeconds"/>.
|
||||
/// </summary>
|
||||
public static async Task RegisterAsync<T>(
|
||||
IJSRuntime js,
|
||||
DotNetObjectReference<T> dotNetRef,
|
||||
string methodName,
|
||||
int thresholdSeconds = 120) where T : class
|
||||
{
|
||||
try
|
||||
{
|
||||
await js.InvokeVoidAsync("appInterop.registerVisibilityRefresh", dotNetRef, methodName, thresholdSeconds);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Circuit may be mid-reconnect — non-fatal.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unregisters the visibility callback. Safe to call multiple times.
|
||||
/// </summary>
|
||||
public static async Task UnregisterAsync(IJSRuntime js)
|
||||
{
|
||||
try
|
||||
{
|
||||
await js.InvokeVoidAsync("appInterop.unregisterVisibilityRefresh");
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user