mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-09 04:19:47 +08:00
refine
This commit is contained in:
parent
fdd48f4f62
commit
1c97b425f4
@ -1,5 +1,6 @@
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.Helpers.Extensions;
|
||||
using BetterGenshinImpact.Service;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.View;
|
||||
@ -67,26 +68,17 @@ public partial class App : Application
|
||||
services.AddSingleton<INavigationService, NavigationService>();
|
||||
|
||||
// Main window with navigation
|
||||
services.AddSingleton<INavigationWindow, MainWindow>();
|
||||
services.AddSingleton<MainWindowViewModel>();
|
||||
services.AddView<INavigationWindow, MainWindow, MainWindowViewModel>();
|
||||
services.AddSingleton<NotifyIconViewModel>();
|
||||
|
||||
// Views and ViewModels
|
||||
services.AddSingleton<HomePage>();
|
||||
services.AddSingleton<HomePageViewModel>();
|
||||
services.AddSingleton<ScriptControlPage>();
|
||||
services.AddSingleton<ScriptControlViewModel>();
|
||||
services.AddSingleton<TriggerSettingsPage>();
|
||||
services.AddSingleton<TriggerSettingsPageViewModel>();
|
||||
services.AddSingleton<MacroSettingsPage>();
|
||||
services.AddSingleton<MacroSettingsPageViewModel>();
|
||||
services.AddSingleton<CommonSettingsPage>();
|
||||
services.AddSingleton<CommonSettingsPageViewModel>();
|
||||
services.AddSingleton<TaskSettingsPage>();
|
||||
services.AddSingleton<TaskSettingsPageViewModel>();
|
||||
|
||||
services.AddSingleton<HotKeyPage>();
|
||||
services.AddSingleton<HotKeyPageViewModel>();
|
||||
// Views
|
||||
services.AddView<HomePage, HomePageViewModel>();
|
||||
services.AddView<ScriptControlPage, ScriptControlViewModel>();
|
||||
services.AddView<TriggerSettingsPage, TriggerSettingsPageViewModel>();
|
||||
services.AddView<MacroSettingsPage, MacroSettingsPageViewModel>();
|
||||
services.AddView<CommonSettingsPage, CommonSettingsPageViewModel>();
|
||||
services.AddView<TaskSettingsPage, TaskSettingsPageViewModel>();
|
||||
services.AddView<HotKeyPage, HotKeyPageViewModel>();
|
||||
|
||||
// My Services
|
||||
services.AddSingleton<TaskTriggerDispatcher>();
|
||||
|
@ -0,0 +1,27 @@
|
||||
using BetterGenshinImpact.ViewModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.Helpers.Extensions;
|
||||
|
||||
internal static class DependencyInjectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddView<TWindow, TWindowImplementation, TViewModel>(this IServiceCollection services)
|
||||
where TWindow : class
|
||||
where TWindowImplementation : class, TWindow
|
||||
where TViewModel : class, IViewModel
|
||||
{
|
||||
return services
|
||||
.AddSingleton<TWindow, TWindowImplementation>()
|
||||
.AddSingleton<TViewModel>();
|
||||
}
|
||||
|
||||
public static IServiceCollection AddView<TPage, TViewModel>(this IServiceCollection services)
|
||||
where TPage : Page
|
||||
where TViewModel : class, IViewModel
|
||||
{
|
||||
return services
|
||||
.AddSingleton<TPage>()
|
||||
.AddSingleton<TViewModel>();
|
||||
}
|
||||
}
|
3
BetterGenshinImpact/ViewModel/IViewModel.cs
Normal file
3
BetterGenshinImpact/ViewModel/IViewModel.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace BetterGenshinImpact.ViewModel;
|
||||
|
||||
internal interface IViewModel;
|
@ -19,7 +19,7 @@ using Wpf.Ui;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel;
|
||||
|
||||
public partial class MainWindowViewModel : ObservableObject
|
||||
public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
private readonly ILogger<MainWindowViewModel> _logger;
|
||||
private readonly IConfigService _configService;
|
||||
|
@ -60,4 +60,4 @@ file static class WindowBacktray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ using BetterGenshinImpact.View.Windows;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class CommonSettingsPageViewModel : ObservableObject, INavigationAware
|
||||
public partial class CommonSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
|
@ -20,7 +20,7 @@ using Wpf.Ui.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class HomePageViewModel : ObservableObject, INavigationAware
|
||||
public partial class HomePageViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
[ObservableProperty] private string[] _modeNames = GameCaptureFactory.ModeNames();
|
||||
|
||||
|
@ -17,7 +17,7 @@ using BetterGenshinImpact.Model;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class HotKeyPageViewModel : ObservableObject
|
||||
public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
private readonly ILogger<HotKeyPageViewModel> _logger;
|
||||
private readonly TaskSettingsPageViewModel _taskSettingsPageViewModel;
|
||||
|
@ -9,7 +9,7 @@ using Wpf.Ui.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class MacroSettingsPageViewModel : ObservableObject, INavigationAware
|
||||
public partial class MacroSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
|
@ -9,7 +9,7 @@ using System.Diagnostics;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class ScriptControlViewModel : ObservableObject, INavigationAware
|
||||
public partial class ScriptControlViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
public ScriptControlViewModel()
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware
|
||||
public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
|
@ -11,7 +11,7 @@ using Wpf.Ui.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
public partial class TriggerSettingsPageViewModel : ObservableObject, INavigationAware
|
||||
public partial class TriggerSettingsPageViewModel : ObservableObject, INavigationAware, IViewModel
|
||||
{
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user