-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.xaml.cs
82 lines (59 loc) · 2.61 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
77
78
79
80
namespace TranscribeMe;
public partial class App : Application {
private readonly IHost _host;
private FirebaseAuthConfig? config;
private string? DatabaeURL;
public App() {
//For debugging purposes
//Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
SyncfusionLicenseProvider.RegisterLicense(ConstantsHelpers.SYNCFUSION_KEY);
_host = Host.CreateDefaultBuilder()
.ConfigureServices((context, services) => {
DatabaeURL = context.Configuration.GetValue<string>("DATABASEURL");
string? FireDomain = context.Configuration.GetValue<string>("FIREBASE_DOMAIN");
string? FireKey = context.Configuration.GetValue<string>("FIREBASE_KEY");
config = new FirebaseAuthConfig() {
ApiKey = FireKey,
AuthDomain = FireDomain,
Providers = new FirebaseAuthProvider[] {
new EmailProvider()
}
};
services.AddSingleton((services) =>
new SignUpLoginWondow(config, DatabaeURL!));
// Register another window
services.AddSingleton((services) => new MainWindow());
})
.Build();
}
protected override async void OnStartup(StartupEventArgs e) {
var uid = await LoginWithSavedDataAsync();
if (!string.IsNullOrEmpty(uid)) {
MainWindow = _host.Services.GetRequiredService<MainWindow>();
MainWindow.DataContext = new MainWindowViewModel(uid!, DatabaeURL!);
} else {
MainWindow = _host.Services.GetRequiredService<SignUpLoginWondow>();
}
MainWindow.Show();
base.OnStartup(e);
}
private async Task<string?> LoginWithSavedDataAsync() {
string userDataFile = Path.Combine(
Environment.GetFolderPath
(Environment.SpecialFolder.LocalApplicationData), "userdata.json");
if (File.Exists(userDataFile)) {
var json = File.ReadAllText(userDataFile);
var savedUser = JsonSerializer.Deserialize<UserData>(json);
if (savedUser != null) {
FirebaseAuthService firebaseAuth = new(config!);
var res = await firebaseAuth.LoginAsync(savedUser.Object.Email,
savedUser.Object.Password);
if (res.User != null) {
return res.User.Uid;
}
}
}
return null;
}
}