|
1 |
| -using System; |
2 | 1 | using System.Linq;
|
3 | 2 | using Avalonia;
|
| 3 | +using Avalonia.Controls; |
4 | 4 | using Avalonia.Controls.ApplicationLifetimes;
|
5 |
| -using Avalonia.Data.Core; |
6 | 5 | using Avalonia.Data.Core.Plugins;
|
7 | 6 | using Avalonia.Markup.Xaml;
|
| 7 | +using CommunityToolkit.Mvvm.DependencyInjection; |
| 8 | +using Microsoft.Extensions.DependencyInjection; |
| 9 | +using PCL2.Neo.Services; |
| 10 | +using Avalonia.Platform.Storage; |
8 | 11 | using PCL2.Neo.Helpers;
|
9 | 12 | using PCL2.Neo.Models.Minecraft.Java;
|
10 | 13 | using PCL2.Neo.Utils;
|
11 | 14 | using PCL2.Neo.ViewModels;
|
| 15 | +using PCL2.Neo.ViewModels.Download; |
| 16 | +using PCL2.Neo.ViewModels.Home; |
12 | 17 | using PCL2.Neo.Views;
|
| 18 | +using System; |
13 | 19 | using System.Threading.Tasks;
|
14 | 20 |
|
15 | 21 | namespace PCL2.Neo
|
16 | 22 | {
|
17 | 23 | public partial class App : Application
|
18 | 24 | {
|
19 |
| - public static Java JavaManager; |
| 25 | + // public static Java? JavaManager { get; private set; } |
| 26 | + // public static IStorageProvider StorageProvider { get; private set; } = null!; |
| 27 | + |
20 | 28 | public override void Initialize()
|
21 | 29 | {
|
22 | 30 | AvaloniaXamlLoader.Load(this);
|
23 | 31 | }
|
24 | 32 |
|
| 33 | + private static IServiceProvider ConfigureServices() => new ServiceCollection() |
| 34 | + .AddTransient<MainWindowViewModel>() |
| 35 | + |
| 36 | + .AddTransient<HomeViewModel>() |
| 37 | + .AddTransient<HomeSubViewModel>() |
| 38 | + |
| 39 | + .AddTransient<DownloadViewModel>() |
| 40 | + .AddTransient<DownloadGameViewModel>() |
| 41 | + .AddTransient<DownloadModViewModel>() |
| 42 | + |
| 43 | + .AddSingleton<NavigationService>(s => new NavigationService(s)) |
| 44 | + .AddSingleton<StorageService>() |
| 45 | + .AddSingleton<IJavaManager,JavaManager>() |
| 46 | + .BuildServiceProvider(); |
| 47 | + |
25 | 48 | public override void OnFrameworkInitializationCompleted()
|
26 | 49 | {
|
27 |
| - Task.Run(SetupJavaManager); |
| 50 | + Ioc.Default.ConfigureServices(ConfigureServices()); |
| 51 | + |
| 52 | + var vm = Ioc.Default.GetRequiredService<MainWindowViewModel>(); |
| 53 | + Task.Run(Ioc.Default.GetRequiredService<IJavaManager>().JavaListInit); |
28 | 54 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
29 | 55 | {
|
30 | 56 | // Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
31 | 57 | // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
32 | 58 | DisableAvaloniaDataAnnotationValidation();
|
33 |
| - desktop.MainWindow = new MainWindow(); |
| 59 | + desktop.MainWindow = new MainWindow |
| 60 | + { |
| 61 | + DataContext = vm |
| 62 | + }; |
34 | 63 | }
|
35 | 64 |
|
36 | 65 | base.OnFrameworkInitializationCompleted();
|
37 | 66 | }
|
38 | 67 |
|
39 |
| - private async Task SetupJavaManager() |
40 |
| - { |
41 |
| - JavaManager = await Java.CreateAsync(); |
42 |
| - } |
43 |
| - |
44 | 68 | private void DisableAvaloniaDataAnnotationValidation()
|
45 | 69 | {
|
46 | 70 | // Get an array of plugins to remove
|
|
0 commit comments