diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index ac134fb5f..20dd50668 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -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(), Launcher.Properties.Settings.Default.GithubRepo)) .AddSingleton() - .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() + // Welcome view model & setting window view model is very simple so we just use one instance + .AddSingleton() .AddSingleton() + // Setting page view models are complex so we use transient instance + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient() ).Build(); Ioc.Default.ConfigureServices(host.Services); } diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index c8b83c730..1a887c4b7 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -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; diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs index 1ecc02aa6..e57cba6d4 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs @@ -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(); - var updater = Ioc.Default.GetRequiredService(); - _viewModel = new SettingsPaneAboutViewModel(settings, updater); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs index 569d489d2..31653962d 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs @@ -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(); - var updater = Ioc.Default.GetRequiredService(); - var portable = Ioc.Default.GetRequiredService(); - var translater = Ioc.Default.GetRequiredService(); - _viewModel = new SettingsPaneGeneralViewModel(settings, updater, portable, translater); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs index eb100da0c..8b757bd60 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs @@ -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(); - _viewModel = new SettingsPaneHotkeyViewModel(settings); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index 3bd24bc13..131dfab6d 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -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(); - _viewModel = new SettingsPanePluginStoreViewModel(); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs index f6b435186..97574b3ce 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs @@ -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(); - _viewModel = new SettingsPanePluginsViewModel(settings); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs index 26350b8bb..258f2a4ad 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs @@ -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(); - var updater = Ioc.Default.GetRequiredService(); - _viewModel = new SettingsPaneProxyViewModel(settings, updater); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } - base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index a1a0231a5..cee8e4ae4 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -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(); - var theme = Ioc.Default.GetRequiredService(); - _viewModel = new SettingsPaneThemeViewModel(settings, theme); + _viewModel = Ioc.Default.GetRequiredService(); DataContext = _viewModel; InitializeComponent(); } - base.OnNavigatedTo(e); } } diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs index f05893cf4..0fe4557a7 100644 --- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs +++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs @@ -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; } /// @@ -17,30 +17,30 @@ public partial class SettingWindowViewModel : BaseModel /// 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; } } diff --git a/Flow.Launcher/ViewModel/WelcomeViewModel.cs b/Flow.Launcher/ViewModel/WelcomeViewModel.cs index 5eecabfde..82d19273f 100644 --- a/Flow.Launcher/ViewModel/WelcomeViewModel.cs +++ b/Flow.Launcher/ViewModel/WelcomeViewModel.cs @@ -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;