-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.axaml.cs
More file actions
77 lines (65 loc) · 2.37 KB
/
Copy pathApp.axaml.cs
File metadata and controls
77 lines (65 loc) · 2.37 KB
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
using AHON_TRACK.Services;
using AHON_TRACK.ViewModels;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AHON_TRACK;
public class App : Application
{
private static Mutex? _appMutex;
private BackupSchedulerService? _backupScheduler;
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
_appMutex = new Mutex(true, "AHON_TRACK", out var createdNew);
if (!createdNew)
{
var instanceDialog = new InstanceDialog();
instanceDialog.Show();
return;
}
DisableAvaloniaDataAnnotationValidation();
var provider = new ServiceProvider().RegisterDialogs();
// Initialize the backup scheduler but DON'T await it here
_backupScheduler = provider.GetService<BackupSchedulerService>();
// Start scheduler in background - don't block UI initialization
_ = Task.Run(async () =>
{
try
{
await _backupScheduler.StartSchedulerAsync();
}
catch (System.Exception ex)
{
// Log error but don't crash the app
System.Diagnostics.Debug.WriteLine($"Backup scheduler failed to start: {ex.Message}");
}
});
// Set up cleanup on app exit
desktop.ShutdownRequested += (s, e) =>
{
_backupScheduler?.Dispose();
};
var viewModel = provider.GetService<LoginViewModel>();
viewModel.Initialize();
var loginWindow = new Views.LoginView { DataContext = viewModel };
desktop.MainWindow = loginWindow;
base.OnFrameworkInitializationCompleted();
}
private static void DisableAvaloniaDataAnnotationValidation()
{
// Get an array of plugins to remove
var dataValidationPluginsToRemove =
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
// remove each entry found
foreach (var plugin in dataValidationPluginsToRemove) BindingPlugins.DataValidators.Remove(plugin);
}
}