mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use dependency injection for setting page view models
This commit is contained in:
parent
cbcebad4d0
commit
84b0393fd0
11 changed files with 34 additions and 53 deletions
|
|
@ -19,6 +19,7 @@ using Flow.Launcher.Infrastructure.Logger;
|
|||
using Flow.Launcher.Infrastructure.Storage;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
|
@ -74,14 +75,23 @@ namespace Flow.Launcher
|
|||
.AddSingleton(_ => _settings)
|
||||
.AddSingleton(sp => new Updater(sp.GetRequiredService<IPublicAPI>(), Launcher.Properties.Settings.Default.GithubRepo))
|
||||
.AddSingleton<Portable>()
|
||||
.AddSingleton<SettingWindowViewModel>()
|
||||
.AddSingleton<IAlphabet, PinyinAlphabet>()
|
||||
.AddSingleton<StringMatcher>()
|
||||
.AddSingleton<Internationalization>()
|
||||
.AddSingleton<IPublicAPI, PublicAPIInstance>()
|
||||
.AddSingleton<MainViewModel>()
|
||||
.AddSingleton<Theme>()
|
||||
// Welcome view model & setting window view model is very simple so we just use one instance
|
||||
.AddSingleton<SettingWindowViewModel>()
|
||||
.AddSingleton<WelcomeViewModel>()
|
||||
// Setting page view models are complex so we use transient instance
|
||||
.AddTransient<SettingsPaneAboutViewModel>()
|
||||
.AddTransient<SettingsPaneGeneralViewModel>()
|
||||
.AddTransient<SettingsPaneHotkeyViewModel>()
|
||||
.AddTransient<SettingsPanePluginsViewModel>()
|
||||
.AddTransient<SettingsPanePluginStoreViewModel>()
|
||||
.AddTransient<SettingsPaneProxyViewModel>()
|
||||
.AddTransient<SettingsPaneThemeViewModel>()
|
||||
).Build();
|
||||
Ioc.Default.ConfigureServices(host.Services);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
public Settings Settings { get; }
|
||||
|
||||
private readonly Updater _updater;
|
||||
private readonly IPortable _portable;
|
||||
private readonly Portable _portable;
|
||||
private readonly Internationalization _translater;
|
||||
|
||||
public SettingsPaneGeneralViewModel(Settings settings, Updater updater, IPortable portable, Internationalization translater)
|
||||
public SettingsPaneGeneralViewModel(Settings settings, Updater updater, Portable portable, Internationalization translater)
|
||||
{
|
||||
Settings = settings;
|
||||
_updater = updater;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System.Windows.Navigation;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -14,9 +12,7 @@ public partial class SettingsPaneAbout
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
var updater = Ioc.Default.GetRequiredService<Updater>();
|
||||
_viewModel = new SettingsPaneAboutViewModel(settings, updater);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneAboutViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.Core.Configuration;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
|
@ -16,11 +12,7 @@ public partial class SettingsPaneGeneral
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
var updater = Ioc.Default.GetRequiredService<Updater>();
|
||||
var portable = Ioc.Default.GetRequiredService<Portable>();
|
||||
var translater = Ioc.Default.GetRequiredService<Internationalization>();
|
||||
_viewModel = new SettingsPaneGeneralViewModel(settings, updater, portable, translater);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneGeneralViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -13,8 +12,7 @@ public partial class SettingsPaneHotkey
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = new SettingsPaneHotkeyViewModel(settings);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneHotkeyViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.Windows.Navigation;
|
|||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -17,8 +16,7 @@ public partial class SettingsPanePluginStore
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = new SettingsPanePluginStoreViewModel();
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginStoreViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -14,8 +13,7 @@ public partial class SettingsPanePlugins
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = new SettingsPanePluginsViewModel(settings);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginsViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
|
|
@ -14,13 +12,10 @@ public partial class SettingsPaneProxy
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
var updater = Ioc.Default.GetRequiredService<Updater>();
|
||||
_viewModel = new SettingsPaneProxyViewModel(settings, updater);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneProxyViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
using Page = ModernWpf.Controls.Page;
|
||||
|
||||
namespace Flow.Launcher.SettingPages.Views;
|
||||
|
||||
public partial class SettingsPaneTheme : Page
|
||||
public partial class SettingsPaneTheme
|
||||
{
|
||||
private SettingsPaneThemeViewModel _viewModel = null!;
|
||||
|
||||
|
|
@ -15,13 +12,10 @@ public partial class SettingsPaneTheme : Page
|
|||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
var settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
var theme = Ioc.Default.GetRequiredService<Theme>();
|
||||
_viewModel = new SettingsPaneThemeViewModel(settings, theme);
|
||||
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneThemeViewModel>();
|
||||
DataContext = _viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ namespace Flow.Launcher.ViewModel;
|
|||
|
||||
public partial class SettingWindowViewModel : BaseModel
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private readonly Settings _settings;
|
||||
|
||||
public SettingWindowViewModel(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -17,30 +17,30 @@ public partial class SettingWindowViewModel : BaseModel
|
|||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
Settings.Save();
|
||||
_settings.Save();
|
||||
}
|
||||
|
||||
public double SettingWindowWidth
|
||||
{
|
||||
get => Settings.SettingWindowWidth;
|
||||
set => Settings.SettingWindowWidth = value;
|
||||
get => _settings.SettingWindowWidth;
|
||||
set => _settings.SettingWindowWidth = value;
|
||||
}
|
||||
|
||||
public double SettingWindowHeight
|
||||
{
|
||||
get => Settings.SettingWindowHeight;
|
||||
set => Settings.SettingWindowHeight = value;
|
||||
get => _settings.SettingWindowHeight;
|
||||
set => _settings.SettingWindowHeight = value;
|
||||
}
|
||||
|
||||
public double? SettingWindowTop
|
||||
{
|
||||
get => Settings.SettingWindowTop;
|
||||
set => Settings.SettingWindowTop = value;
|
||||
get => _settings.SettingWindowTop;
|
||||
set => _settings.SettingWindowTop = value;
|
||||
}
|
||||
|
||||
public double? SettingWindowLeft
|
||||
{
|
||||
get => Settings.SettingWindowLeft;
|
||||
set => Settings.SettingWindowLeft = value;
|
||||
get => _settings.SettingWindowLeft;
|
||||
set => _settings.SettingWindowLeft = value;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace Flow.Launcher.ViewModel
|
|||
{
|
||||
_pageNum = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(PageDisplay));
|
||||
UpdateView();
|
||||
}
|
||||
}
|
||||
|
|
@ -47,7 +48,6 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
private void UpdateView()
|
||||
{
|
||||
OnPropertyChanged(nameof(PageDisplay));
|
||||
if (PageNum == 1)
|
||||
{
|
||||
BackEnabled = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue