mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve code quality
This commit is contained in:
parent
d867875cde
commit
d01c67f433
12 changed files with 121 additions and 83 deletions
|
|
@ -10,14 +10,14 @@ namespace Flow.Launcher
|
|||
{
|
||||
public partial class CustomQueryHotkeySetting : Window
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private readonly Settings _settings;
|
||||
|
||||
private bool update;
|
||||
private CustomPluginHotkey updateCustomHotkey;
|
||||
|
||||
public CustomQueryHotkeySetting(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
_settings = settings;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
@ -30,13 +30,13 @@ namespace Flow.Launcher
|
|||
{
|
||||
if (!update)
|
||||
{
|
||||
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
|
||||
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
|
||||
|
||||
var pluginHotkey = new CustomPluginHotkey
|
||||
{
|
||||
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
|
||||
};
|
||||
Settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
_settings.CustomPluginHotkeys.Add(pluginHotkey);
|
||||
|
||||
HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ namespace Flow.Launcher
|
|||
|
||||
public void UpdateItem(CustomPluginHotkey item)
|
||||
{
|
||||
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
||||
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
|
||||
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
|
||||
if (updateCustomHotkey == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.SettingPages.ViewModels;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
public partial class CustomShortcutSetting : Window
|
||||
{
|
||||
public Settings Settings { get; } = Ioc.Default.GetRequiredService<Settings>();
|
||||
|
||||
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
|
||||
public string Key { get; set; } = string.Empty;
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
|
|
|||
|
|
@ -42,14 +42,11 @@ namespace Flow.Launcher.Resources.Controls
|
|||
|
||||
private static void keyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var control = d as UserControl;
|
||||
if (null == control) return; // This should not be possible
|
||||
if (d is not UserControl) return; // This should not be possible
|
||||
|
||||
var newValue = e.NewValue as string;
|
||||
if (null == newValue) return;
|
||||
if (e.NewValue is not string newValue) return;
|
||||
|
||||
if (d is not HotkeyDisplay hotkeyDisplay)
|
||||
return;
|
||||
if (d is not HotkeyDisplay hotkeyDisplay) return;
|
||||
|
||||
hotkeyDisplay.Values.Clear();
|
||||
foreach (var key in newValue.Split('+'))
|
||||
|
|
|
|||
|
|
@ -1,29 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Windows.Navigation;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Core.Resource;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
public partial class WelcomePage1
|
||||
{
|
||||
public Settings Settings { get; private set; }
|
||||
private WelcomeViewModel _viewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 1;
|
||||
InitializeComponent();
|
||||
_viewModel.PageNum = 1;
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
private readonly Internationalization _translater = Ioc.Default.GetRequiredService<Internationalization>();
|
||||
|
||||
public List<Language> Languages => _translater.LoadAvailableLanguages();
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
public string CustomLanguage
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -1,25 +1,31 @@
|
|||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure.Hotkey;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
public partial class WelcomePage2
|
||||
{
|
||||
public Settings Settings { get; set; }
|
||||
public Settings Settings { get; private set; }
|
||||
private WelcomeViewModel _viewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 2;
|
||||
InitializeComponent();
|
||||
_viewModel.PageNum = 2;
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
|
|
|||
|
|
@ -7,15 +7,21 @@ namespace Flow.Launcher.Resources.Pages
|
|||
{
|
||||
public partial class WelcomePage3
|
||||
{
|
||||
public Settings Settings { get; private set; }
|
||||
private WelcomeViewModel _viewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 3;
|
||||
InitializeComponent();
|
||||
_viewModel.PageNum = 3;
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,27 @@
|
|||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using System.Windows.Navigation;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
public partial class WelcomePage4
|
||||
{
|
||||
public Settings Settings { get; private set; }
|
||||
private WelcomeViewModel _viewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 4;
|
||||
InitializeComponent();
|
||||
_viewModel.PageNum = 4;
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,74 @@
|
|||
using System.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Navigation;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Microsoft.Win32;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Resources.Pages
|
||||
{
|
||||
public partial class WelcomePage5
|
||||
{
|
||||
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
public Settings Settings { get; set; }
|
||||
public bool HideOnStartup { get; set; }
|
||||
public Settings Settings { get; private set; }
|
||||
private WelcomeViewModel _viewModel;
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
if (!IsInitialized)
|
||||
{
|
||||
Settings = Ioc.Default.GetRequiredService<Settings>();
|
||||
_viewModel = Ioc.Default.GetRequiredService<WelcomeViewModel>();
|
||||
InitializeComponent();
|
||||
}
|
||||
// Sometimes the navigation is not triggered by button click,
|
||||
// so we need to reset the page number
|
||||
Ioc.Default.GetRequiredService<WelcomeViewModel>().PageNum = 5;
|
||||
InitializeComponent();
|
||||
_viewModel.PageNum = 5;
|
||||
base.OnNavigatedTo(e);
|
||||
}
|
||||
|
||||
private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SetStartup();
|
||||
}
|
||||
private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RemoveStartup();
|
||||
ChangeAutoStartup(true);
|
||||
}
|
||||
|
||||
private void RemoveStartup()
|
||||
private void OnAutoStartupUncheck(object sender, RoutedEventArgs e)
|
||||
{
|
||||
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
|
||||
key?.DeleteValue(Constant.FlowLauncher, false);
|
||||
Settings.StartFlowLauncherOnSystemStartup = false;
|
||||
ChangeAutoStartup(false);
|
||||
}
|
||||
private void SetStartup()
|
||||
|
||||
private void ChangeAutoStartup(bool value)
|
||||
{
|
||||
using var key = Registry.CurrentUser.OpenSubKey(StartupPath, true);
|
||||
key?.SetValue(Constant.FlowLauncher, Constant.ExecutablePath);
|
||||
Settings.StartFlowLauncherOnSystemStartup = true;
|
||||
Settings.StartFlowLauncherOnSystemStartup = value;
|
||||
try
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (Settings.UseLogonTaskForStartup)
|
||||
{
|
||||
AutoStartup.ChangeToViaLogonTask();
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoStartup.ChangeToViaRegistry();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoStartup.DisableViaLogonTaskAndRegistry();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
App.API.ShowMsg(App.API.GetTranslation("setAutoStartFailed"), e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHideOnStartupChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.HideOnStartup = true;
|
||||
}
|
||||
|
||||
private void OnHideOnStartupUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.HideOnStartup = false;
|
||||
|
|
@ -59,6 +79,5 @@ namespace Flow.Launcher.Resources.Pages
|
|||
var window = Window.GetWindow(this);
|
||||
window.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@ namespace Flow.Launcher
|
|||
[INotifyPropertyChanged]
|
||||
public partial class SelectBrowserWindow : Window
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private readonly Settings _settings;
|
||||
|
||||
private int selectedCustomBrowserIndex;
|
||||
|
||||
public int SelectedCustomBrowserIndex
|
||||
{
|
||||
get => selectedCustomBrowserIndex; set
|
||||
get => selectedCustomBrowserIndex;
|
||||
set
|
||||
{
|
||||
selectedCustomBrowserIndex = value;
|
||||
OnPropertyChanged(nameof(CustomBrowser));
|
||||
|
|
@ -27,9 +28,9 @@ namespace Flow.Launcher
|
|||
public CustomBrowserViewModel CustomBrowser => CustomBrowsers[SelectedCustomBrowserIndex];
|
||||
public SelectBrowserWindow(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
CustomBrowsers = new ObservableCollection<CustomBrowserViewModel>(Settings.CustomBrowserList.Select(x => x.Copy()));
|
||||
SelectedCustomBrowserIndex = Settings.CustomBrowserIndex;
|
||||
_settings = settings;
|
||||
CustomBrowsers = new ObservableCollection<CustomBrowserViewModel>(_settings.CustomBrowserList.Select(x => x.Copy()));
|
||||
SelectedCustomBrowserIndex = _settings.CustomBrowserIndex;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
@ -40,8 +41,8 @@ namespace Flow.Launcher
|
|||
|
||||
private void btnDone_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.CustomBrowserList = CustomBrowsers.ToList();
|
||||
Settings.CustomBrowserIndex = SelectedCustomBrowserIndex;
|
||||
_settings.CustomBrowserList = CustomBrowsers.ToList();
|
||||
_settings.CustomBrowserIndex = SelectedCustomBrowserIndex;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ namespace Flow.Launcher
|
|||
[INotifyPropertyChanged]
|
||||
public partial class SelectFileManagerWindow : Window
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
private readonly Settings _settings;
|
||||
|
||||
private int selectedCustomExplorerIndex;
|
||||
|
||||
public int SelectedCustomExplorerIndex
|
||||
{
|
||||
get => selectedCustomExplorerIndex; set
|
||||
get => selectedCustomExplorerIndex;
|
||||
set
|
||||
{
|
||||
selectedCustomExplorerIndex = value;
|
||||
OnPropertyChanged(nameof(CustomExplorer));
|
||||
|
|
@ -29,9 +30,9 @@ namespace Flow.Launcher
|
|||
public CustomExplorerViewModel CustomExplorer => CustomExplorers[SelectedCustomExplorerIndex];
|
||||
public SelectFileManagerWindow(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
CustomExplorers = new ObservableCollection<CustomExplorerViewModel>(Settings.CustomExplorerList.Select(x => x.Copy()));
|
||||
SelectedCustomExplorerIndex = Settings.CustomExplorerIndex;
|
||||
_settings = settings;
|
||||
CustomExplorers = new ObservableCollection<CustomExplorerViewModel>(_settings.CustomExplorerList.Select(x => x.Copy()));
|
||||
SelectedCustomExplorerIndex = _settings.CustomExplorerIndex;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
|
@ -42,8 +43,8 @@ namespace Flow.Launcher
|
|||
|
||||
private void btnDone_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.CustomExplorerList = CustomExplorers.ToList();
|
||||
Settings.CustomExplorerIndex = SelectedCustomExplorerIndex;
|
||||
_settings.CustomExplorerList = CustomExplorers.ToList();
|
||||
_settings.CustomExplorerIndex = SelectedCustomExplorerIndex;
|
||||
Close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ namespace Flow.Launcher.SettingPages.ViewModels;
|
|||
public partial class SettingsPaneGeneralViewModel : BaseModel
|
||||
{
|
||||
public Settings Settings { get; }
|
||||
|
||||
private readonly Updater _updater;
|
||||
private readonly IPortable _portable;
|
||||
private readonly Internationalization _translater;
|
||||
|
|
@ -78,7 +79,7 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
{
|
||||
try
|
||||
{
|
||||
if (UseLogonTaskForStartup)
|
||||
if (value)
|
||||
{
|
||||
AutoStartup.ChangeToViaLogonTask();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue