-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.xaml.cs
76 lines (63 loc) · 2.25 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using ToDoListApp.Views;
using Microsoft.Maui.Controls;
using Plugin.Maui.Biometric;
using static ToDoListApp.ToastService;
#if IOS
using WebKit;
#endif
namespace ToDoListApp;
public partial class App : Application
{
public App()
{
InitializeComponent();
// Register routes for navigation
Routing.RegisterRoute(nameof(Dashboard), typeof(Dashboard));
Routing.RegisterRoute(nameof(Welcome), typeof(Welcome));
Routing.RegisterRoute(nameof(AppLockedPage), typeof(AppLockedPage));
MainPage = new AppShell();
MainPage.Dispatcher.Dispatch(async () =>
{
bool isBiometricsEnabled = Preferences.Get("BiometricsEnabled", false);
if (Preferences.ContainsKey("IsFirstRun"))
{
MainPage = new AppShell();
}
else
{
// Navigate to the Welcome page and set the first-run preference
await MainPage.Navigation.PushAsync(new Welcome());
Preferences.Set("IsFirstRun", true);
}
if (isBiometricsEnabled)
{
await MainPage.Navigation.PushAsync(new AppLockedPage());
}
});
}
protected override async void OnResume()
{
base.OnResume();
#if ANDROID
await Task.Delay(500); // Android needs this delay or authentication will be bypassed
#endif
bool isBiometricsEnabled = Preferences.Get("BiometricsEnabled", false);
if (isBiometricsEnabled == true)
{
// Biometric authentication
var biometric = await BiometricAuthenticationService.Default.AuthenticateAsync(new AuthenticationRequest()
{
Title = "Authenticate",
Subtitle = "Please authenticate to access the app",
Description = "Please use your biometric to authenticate",
NegativeText = "Cancel",
AuthStrength = AuthenticatorStrength.Weak,
AllowPasswordAuth = true
}, CancellationToken.None);
if (biometric.Status == BiometricResponseStatus.Failure)
{
await MainPage.Navigation.PushAsync(new AppLockedPage());
}
}
}
}