generated from Integry/Template_NetMauiBlazorHybrid
59 lines
1.6 KiB
Plaintext
59 lines
1.6 KiB
Plaintext
@page "/"
|
|
@attribute [Authorize]
|
|
@using salesbook.Shared.Core.Interface
|
|
@using salesbook.Shared.Components.Layout.Spinner
|
|
@using salesbook.Shared.Core.Interface.System.Network
|
|
@using salesbook.Shared.Core.Interface.System.Notification
|
|
@using salesbook.Shared.Core.Services
|
|
@inject IFormFactor FormFactor
|
|
@inject INetworkService NetworkService
|
|
@inject IFirebaseNotificationService FirebaseNotificationService
|
|
@inject IShinyNotificationManager NotificationManager
|
|
@inject PreloadService PreloadService
|
|
|
|
<SpinnerLayout FullScreen="true" />
|
|
|
|
@code
|
|
{
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await CheckAndRequestPermissions();
|
|
|
|
try
|
|
{
|
|
await FirebaseNotificationService.InitFirebase();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine($"Firebase init: {e.Message}");
|
|
}
|
|
|
|
var lastSyncDate = LocalStorage.Get<DateTime>("last-sync");
|
|
|
|
if (!FormFactor.IsWeb() && NetworkService.ConnectionAvailable && lastSyncDate.Equals(DateTime.MinValue))
|
|
{
|
|
NavigationManager.NavigateTo("/sync");
|
|
return;
|
|
}
|
|
|
|
_ = StartSyncUser();
|
|
NavigationManager.NavigateTo("/Calendar");
|
|
}
|
|
|
|
private async Task CheckAndRequestPermissions()
|
|
{
|
|
await NotificationManager.RequestAccess();
|
|
|
|
// if (BatteryOptimizationManagerService.IsBatteryOptimizationEnabled())
|
|
// BatteryOptimizationManagerService.OpenBatteryOptimizationSettings(_ => { });
|
|
}
|
|
|
|
private Task StartSyncUser()
|
|
{
|
|
return Task.Run(() =>
|
|
{
|
|
_ = PreloadService.PreloadUsersAsync();
|
|
});
|
|
}
|
|
}
|