using Microsoft.JSInterop; namespace Lagerbestand.Components.Shared; /// /// Helper that wires a page's reload method to the browser's /// visibilitychange event via appInterop.registerVisibilityRefresh. /// The caller owns the passed in. /// public static class VisibilityRefresh { /// /// Registers a .NET callback invoked when the browser tab becomes /// visible again after being hidden for at least . /// public static async Task RegisterAsync( IJSRuntime js, DotNetObjectReference 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. } } /// /// Unregisters the visibility callback. Safe to call multiple times. /// public static async Task UnregisterAsync(IJSRuntime js) { try { await js.InvokeVoidAsync("appInterop.unregisterVisibilityRefresh"); } catch { /* ignore */ } } }