From bfee170d0fbeba908d9f228771af7a08351e7a10 Mon Sep 17 00:00:00 2001 From: Sparrkle Date: Wed, 5 Oct 2022 16:20:41 +0900 Subject: [PATCH 01/20] Changed ProgressBar Storyboard (No Dispatcher) --- Flow.Launcher/MainWindow.xaml | 1 - Flow.Launcher/MainWindow.xaml.cs | 60 +++++++++++--------------------- 2 files changed, 21 insertions(+), 40 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index dc3b3f145..7d8c195f3 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -250,7 +250,6 @@ Height="2" HorizontalAlignment="Right" StrokeThickness="1" - Style="{DynamicResource PendingLineStyle}" Visibility="{Binding ProgressBarVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" X1="-150" X2="-50" diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 332e0f502..1dd9fe34d 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -28,9 +28,6 @@ namespace Flow.Launcher public partial class MainWindow { #region Private Fields - - private readonly Storyboard _progressBarStoryboard = new Storyboard(); - private bool isProgressBarStoryboardPaused; private Settings _settings; private NotifyIcon _notifyIcon; private ContextMenu contextMenu; @@ -119,39 +116,9 @@ namespace Flow.Launcher _viewModel.LastQuerySelected = true; } - if (_viewModel.ProgressBarVisibility == Visibility.Visible && isProgressBarStoryboardPaused) - { - _progressBarStoryboard.Begin(ProgressBar, true); - isProgressBarStoryboardPaused = false; - } - if(_settings.UseAnimation) WindowAnimator(); } - else if (!isProgressBarStoryboardPaused) - { - _progressBarStoryboard.Stop(ProgressBar); - isProgressBarStoryboardPaused = true; - } - - break; - } - case nameof(MainViewModel.ProgressBarVisibility): - { - Dispatcher.Invoke(() => - { - if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused) - { - _progressBarStoryboard.Stop(ProgressBar); - isProgressBarStoryboardPaused = true; - } - else if (_viewModel.MainWindowVisibilityStatus && - isProgressBarStoryboardPaused) - { - _progressBarStoryboard.Begin(ProgressBar, true); - isProgressBarStoryboardPaused = false; - } - }); break; } case nameof(MainViewModel.QueryTextCursorMovedToEnd): @@ -291,17 +258,32 @@ namespace Flow.Launcher } private void InitProgressbarAnimation() { - var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150, - new Duration(new TimeSpan(0, 0, 0, 0, 1600))); + var progressBarStoryBoard = new Storyboard(); + + var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 50, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)")); Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)")); - _progressBarStoryboard.Children.Add(da); - _progressBarStoryboard.Children.Add(da1); - _progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; + progressBarStoryBoard.Children.Add(da); + progressBarStoryBoard.Children.Add(da1); + progressBarStoryBoard.RepeatBehavior = RepeatBehavior.Forever; + + da.Freeze(); + da1.Freeze(); + + var beginStoryboard = new BeginStoryboard(); + beginStoryboard.Storyboard = progressBarStoryBoard; + + var trigger = new Trigger { Property = System.Windows.Shapes.Line.VisibilityProperty, Value = Visibility.Visible }; + trigger.EnterActions.Add(beginStoryboard); + + var progressStyle = new Style(typeof(System.Windows.Shapes.Line)); + progressStyle.BasedOn = FindResource("PendingLineStyle") as Style; + progressStyle.Triggers.Add(trigger); + + ProgressBar.Style = progressStyle; _viewModel.ProgressBarVisibility = Visibility.Hidden; - isProgressBarStoryboardPaused = true; } public void WindowAnimator() { From 6f0c2549cea809b0a1e406951f734daf4fb8cc0d Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Thu, 24 Nov 2022 14:01:32 -0600 Subject: [PATCH 02/20] also pause animation when exit visible --- Flow.Launcher/MainWindow.xaml.cs | 151 ++++++++++++++++++------------- 1 file changed, 89 insertions(+), 62 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 245ab4d05..efa43000b 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -36,6 +36,7 @@ namespace Flow.Launcher public partial class MainWindow { #region Private Fields + private Settings _settings; private NotifyIcon _notifyIcon; private ContextMenu contextMenu; @@ -50,7 +51,7 @@ namespace Flow.Launcher DataContext = mainVM; _viewModel = mainVM; _settings = settings; - + InitializeComponent(); InitializePosition(); animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); @@ -60,7 +61,7 @@ namespace Flow.Launcher { InitializeComponent(); } - + private void OnCopy(object sender, ExecutedRoutedEventArgs e) { if (QueryTextBox.SelectionLength == 0) @@ -108,29 +109,29 @@ namespace Flow.Launcher switch (e.PropertyName) { case nameof(MainViewModel.MainWindowVisibilityStatus): + { + if (_viewModel.MainWindowVisibilityStatus) { - if (_viewModel.MainWindowVisibilityStatus) + if (_settings.UseSound) { - if (_settings.UseSound) - { - animationSound.Position = TimeSpan.Zero; - animationSound.Play(); - } - UpdatePosition(); - Activate(); - QueryTextBox.Focus(); - _settings.ActivateTimes++; - if (!_viewModel.LastQuerySelected) - { - QueryTextBox.SelectAll(); - _viewModel.LastQuerySelected = true; - } - - if(_settings.UseAnimation) - WindowAnimator(); + animationSound.Position = TimeSpan.Zero; + animationSound.Play(); } - break; + UpdatePosition(); + Activate(); + QueryTextBox.Focus(); + _settings.ActivateTimes++; + if (!_viewModel.LastQuerySelected) + { + QueryTextBox.SelectAll(); + _viewModel.LastQuerySelected = true; + } + + if (_settings.UseAnimation) + WindowAnimator(); } + break; + } case nameof(MainViewModel.QueryTextCursorMovedToEnd): if (_viewModel.QueryTextCursorMovedToEnd) { @@ -211,35 +212,45 @@ namespace Flow.Launcher Visible = !_settings.HideNotifyIcon }; contextMenu = new ContextMenu(); - var openIcon = new FontIcon { Glyph = "\ue71e" }; + var openIcon = new FontIcon + { + Glyph = "\ue71e" + }; var open = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", - Icon = openIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon + }; + var gamemodeIcon = new FontIcon + { + Glyph = "\ue7fc" }; - var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" }; var gamemode = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("GameMode"), - Icon = gamemodeIcon + Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon + }; + var positionresetIcon = new FontIcon + { + Glyph = "\ue73f" }; - var positionresetIcon = new FontIcon { Glyph = "\ue73f" }; var positionreset = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), - Icon = positionresetIcon + Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon + }; + var settingsIcon = new FontIcon + { + Glyph = "\ue713" }; - var settingsIcon = new FontIcon { Glyph = "\ue713" }; var settings = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), - Icon = settingsIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon + }; + var exitIcon = new FontIcon + { + Glyph = "\ue7e8" }; - var exitIcon = new FontIcon { Glyph = "\ue7e8" }; var exit = new MenuItem { - Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), - Icon = exitIcon + Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon }; open.Click += (o, e) => _viewModel.ToggleFlowLauncher(); @@ -300,10 +311,10 @@ namespace Flow.Launcher } private async void PositionReset() { - _viewModel.Show(); - await Task.Delay(300); // If don't give a time, Positioning will be weird. - Left = HorizonCenter(); - Top = VerticalCenter(); + _viewModel.Show(); + await Task.Delay(300); // If don't give a time, Positioning will be weird. + Left = HorizonCenter(); + Top = VerticalCenter(); } private void InitProgressbarAnimation() { @@ -320,14 +331,30 @@ namespace Flow.Launcher da.Freeze(); da1.Freeze(); - var beginStoryboard = new BeginStoryboard(); - beginStoryboard.Storyboard = progressBarStoryBoard; + const string progressBarAnimationName = "ProgressBarAnimation"; + var beginStoryboard = new BeginStoryboard + { + Name = progressBarAnimationName, Storyboard = progressBarStoryBoard + }; + + var stopStoryboard = new StopStoryboard() + { + BeginStoryboardName = progressBarAnimationName + }; - var trigger = new Trigger { Property = System.Windows.Shapes.Line.VisibilityProperty, Value = Visibility.Visible }; + var trigger = new Trigger + { + Property = VisibilityProperty, Value = Visibility.Visible + }; trigger.EnterActions.Add(beginStoryboard); + trigger.ExitActions.Add(stopStoryboard); - var progressStyle = new Style(typeof(System.Windows.Shapes.Line)); - progressStyle.BasedOn = FindResource("PendingLineStyle") as Style; + + var progressStyle = new Style(typeof(System.Windows.Shapes.Line)) + { + BasedOn = FindResource("PendingLineStyle") as Style + }; + progressStyle.RegisterName(progressBarAnimationName, beginStoryboard); progressStyle.Triggers.Add(trigger); ProgressBar.Style = progressStyle; @@ -343,7 +370,7 @@ namespace Flow.Launcher UpdatePosition(); Storyboard sb = new Storyboard(); Storyboard iconsb = new Storyboard(); - CircleEase easing = new CircleEase(); // or whatever easing class you want + CircleEase easing = new CircleEase(); // or whatever easing class you want easing.EasingMode = EasingMode.EaseInOut; var da = new DoubleAnimation { @@ -360,14 +387,14 @@ namespace Flow.Launcher Duration = TimeSpan.FromSeconds(0.25), FillBehavior = FillBehavior.Stop }; - var da3 = new DoubleAnimation - { - From = 12, - To = 0, - EasingFunction = easing, - Duration = TimeSpan.FromSeconds(0.36), - FillBehavior = FillBehavior.Stop - }; + var da3 = new DoubleAnimation + { + From = 12, + To = 0, + EasingFunction = easing, + Duration = TimeSpan.FromSeconds(0.36), + FillBehavior = FillBehavior.Stop + }; Storyboard.SetTarget(da, this); Storyboard.SetTargetProperty(da, new PropertyPath(Window.OpacityProperty)); Storyboard.SetTargetProperty(da2, new PropertyPath(Window.TopProperty)); @@ -395,10 +422,10 @@ namespace Flow.Launcher private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e) { _viewModel.Hide(); - - if(_settings.UseAnimation) + + if (_settings.UseAnimation) await Task.Delay(100); - + App.API.OpenSettingDialog(); } @@ -416,7 +443,7 @@ namespace Flow.Launcher // and always after Settings window is closed. if (_settings.UseAnimation) await Task.Delay(100); - + if (_settings.HideWhenDeactive) { _viewModel.Hide(); @@ -454,7 +481,7 @@ namespace Flow.Launcher _viewModel.Show(); } } - + public double HorizonCenter() { var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); @@ -536,9 +563,9 @@ namespace Flow.Launcher && QueryTextBox.Text.Length > 0 && QueryTextBox.CaretIndex == QueryTextBox.Text.Length) { - var queryWithoutActionKeyword = + var queryWithoutActionKeyword = QueryBuilder.Build(QueryTextBox.Text.Trim(), PluginManager.NonGlobalPlugins).Search; - + if (FilesFolders.IsLocationPathString(queryWithoutActionKeyword)) { _viewModel.BackspaceCommand.Execute(null); @@ -574,7 +601,7 @@ namespace Flow.Launcher private void QueryTextBox_KeyUp(object sender, KeyEventArgs e) { - if(_viewModel.QueryText != QueryTextBox.Text) + if (_viewModel.QueryText != QueryTextBox.Text) { BindingExpression be = QueryTextBox.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty); be.UpdateSource(); From 31d47a2340173b09ec30b1d1e6ab201796204fc1 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 5 Mar 2025 15:18:06 +0800 Subject: [PATCH 03/20] Use dependency injection instead of navigation parameter --- .../SettingPages/Views/SettingsPaneAbout.xaml.cs | 10 ++++++---- .../SettingPages/Views/SettingsPaneGeneral.xaml.cs | 11 +++++++---- .../SettingPages/Views/SettingsPaneHotkey.xaml.cs | 8 ++++---- .../Views/SettingsPanePluginStore.xaml.cs | 8 ++++---- .../SettingPages/Views/SettingsPanePlugins.xaml.cs | 8 ++++---- .../SettingPages/Views/SettingsPaneProxy.xaml.cs | 10 ++++++---- .../SettingPages/Views/SettingsPaneTheme.xaml.cs | 10 ++++------ Flow.Launcher/SettingWindow.xaml.cs | 13 ++----------- 8 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs index de6a4df5e..1ecc02aa6 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs @@ -1,6 +1,8 @@ -using System; -using System.Windows.Navigation; +using System.Windows.Navigation; +using Flow.Launcher.Core; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.Infrastructure.UserSettings; +using CommunityToolkit.Mvvm.DependencyInjection; namespace Flow.Launcher.SettingPages.Views; @@ -12,8 +14,8 @@ public partial class SettingsPaneAbout { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater }) - throw new ArgumentException("Settings are required for SettingsPaneAbout."); + var settings = Ioc.Default.GetRequiredService(); + var updater = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPaneAboutViewModel(settings, updater); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs index f95015b2e..dd7fd13a9 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs @@ -1,5 +1,7 @@ -using System; -using System.Windows.Navigation; +using System.Windows.Navigation; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Core; +using Flow.Launcher.Core.Configuration; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.SettingPages.ViewModels; @@ -13,8 +15,9 @@ public partial class SettingsPaneGeneral { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: {} updater, Portable: {} portable }) - throw new ArgumentException("Settings, Updater and Portable are required for SettingsPaneGeneral."); + var settings = Ioc.Default.GetRequiredService(); + var updater = Ioc.Default.GetRequiredService(); + var portable = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPaneGeneralViewModel(settings, updater, portable); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs index 061eabf51..eb100da0c 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs @@ -1,6 +1,7 @@ -using System; -using System.Windows.Navigation; +using System.Windows.Navigation; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.Infrastructure.UserSettings; namespace Flow.Launcher.SettingPages.Views; @@ -12,8 +13,7 @@ public partial class SettingsPaneHotkey { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings }) - throw new ArgumentException("Settings are required for SettingsPaneHotkey."); + var settings = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPaneHotkeyViewModel(settings); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs index db4763319..3bd24bc13 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs @@ -1,10 +1,11 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; using System.Windows.Data; using System.Windows.Input; 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; @@ -16,8 +17,7 @@ public partial class SettingsPanePluginStore { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings }) - throw new ArgumentException($"Settings are required for {nameof(SettingsPanePluginStore)}."); + var settings = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPanePluginStoreViewModel(); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs index d48505c3d..f6b435186 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs @@ -1,7 +1,8 @@ -using System; -using System.Windows.Input; +using System.Windows.Input; 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 +14,7 @@ public partial class SettingsPanePlugins { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings }) - throw new ArgumentException("Settings are required for SettingsPaneHotkey."); + var settings = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPanePluginsViewModel(settings); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs index 95c88d627..26350b8bb 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs @@ -1,6 +1,8 @@ -using System; -using System.Windows.Navigation; +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; @@ -12,8 +14,8 @@ public partial class SettingsPaneProxy { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, Updater: { } updater }) - throw new ArgumentException($"Settings are required for {nameof(SettingsPaneProxy)}."); + var settings = Ioc.Default.GetRequiredService(); + var updater = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPaneProxyViewModel(settings, updater); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index 7f32728c2..bf7502e19 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -1,10 +1,9 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; +using System.Windows.Controls; using System.Windows.Navigation; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.SettingPages.ViewModels; using Page = ModernWpf.Controls.Page; +using Flow.Launcher.Infrastructure.UserSettings; namespace Flow.Launcher.SettingPages.Views; @@ -16,8 +15,7 @@ public partial class SettingsPaneTheme : Page { if (!IsInitialized) { - if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings }) - throw new ArgumentException($"Settings are required for {nameof(SettingsPaneTheme)}."); + var settings = Ioc.Default.GetRequiredService(); _viewModel = new SettingsPaneThemeViewModel(settings); DataContext = _viewModel; InitializeComponent(); diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index f87194c30..30b51f992 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -4,8 +4,6 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using CommunityToolkit.Mvvm.DependencyInjection; -using Flow.Launcher.Core; -using Flow.Launcher.Core.Configuration; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; @@ -18,8 +16,6 @@ namespace Flow.Launcher; public partial class SettingWindow { - private readonly Updater _updater; - private readonly IPortable _portable; private readonly IPublicAPI _api; private readonly Settings _settings; private readonly SettingWindowViewModel _viewModel; @@ -30,8 +26,6 @@ public partial class SettingWindow _settings = Ioc.Default.GetRequiredService(); DataContext = viewModel; _viewModel = viewModel; - _updater = Ioc.Default.GetRequiredService(); - _portable = Ioc.Default.GetRequiredService(); _api = Ioc.Default.GetRequiredService(); InitializePosition(); InitializeComponent(); @@ -166,10 +160,9 @@ public partial class SettingWindow private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) { - var paneData = new PaneData(_settings, _updater, _portable); if (args.IsSettingsSelected) { - ContentFrame.Navigate(typeof(SettingsPaneGeneral), paneData); + ContentFrame.Navigate(typeof(SettingsPaneGeneral)); } else { @@ -191,7 +184,7 @@ public partial class SettingWindow nameof(About) => typeof(SettingsPaneAbout), _ => typeof(SettingsPaneGeneral) }; - ContentFrame.Navigate(pageType, paneData); + ContentFrame.Navigate(pageType); } } @@ -211,6 +204,4 @@ public partial class SettingWindow { NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */ } - - public record PaneData(Settings Settings, Updater Updater, IPortable Portable); } From bc0cde289c2af505f1ea7890173dc2226486dbb9 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 18:20:25 +0800 Subject: [PATCH 04/20] Add translations for system plugin command column --- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 28747cc7c..05687701d 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -28,8 +28,12 @@ namespace Flow.Launcher.Plugin.Sys public Control CreateSettingPanel() { - var results = Commands(); - return new SysSettings(results); + var commands = Commands(); + foreach (var c in commands) + { + c.Title = GetDynamicTitle(null, c); + } + return new SysSettings(commands); } public List Query(Query query) @@ -73,6 +77,11 @@ namespace Flow.Launcher.Plugin.Sys var translatedTitle = context.API.GetTranslation(translationKey); + if (query == null) + { + return translatedTitle; + } + if (result.Title == translatedTitle) { return result.Title; From 01e8be779ce47dea22ae8d6a959baadb3aa2df46 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 19:30:51 +0800 Subject: [PATCH 05/20] Fix FL settings issue --- Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs index 38619cbbc..e67b4e5c5 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs @@ -2,7 +2,7 @@ using System.Linq; using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Core.Resource; -using Flow.Launcher.Infrastructure.UserSettings; +using FLSettings = Flow.Launcher.Infrastructure.UserSettings.Settings; namespace Flow.Launcher.Plugin.Sys { @@ -10,7 +10,7 @@ namespace Flow.Launcher.Plugin.Sys { public const string Keyword = "fltheme"; - private readonly Settings _settings; + private readonly FLSettings _settings; private readonly Theme _theme; private readonly PluginInitContext _context; @@ -43,7 +43,7 @@ namespace Flow.Launcher.Plugin.Sys { _context = context; _theme = Ioc.Default.GetRequiredService(); - _settings = Ioc.Default.GetRequiredService(); + _settings = Ioc.Default.GetRequiredService(); } public List Query(Query query) From 8335821ad080818586f3a09d23a72b4c09da0edc Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 22:02:45 +0800 Subject: [PATCH 06/20] Clean up codes --- .../SettingsViewModel.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs index a2538893b..e07e30cb2 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SettingsViewModel.cs @@ -1,21 +1,12 @@ -using Flow.Launcher.Infrastructure.Storage; - -namespace Flow.Launcher.Plugin.WebSearch +namespace Flow.Launcher.Plugin.WebSearch { public class SettingsViewModel { - private readonly PluginJsonStorage _storage; - public SettingsViewModel(Settings settings) { Settings = settings; } public Settings Settings { get; } - - public void Save() - { - _storage.Save(); - } } -} \ No newline at end of file +} From e0f02a0d7bc62ba0b2c84359cf952545c963ec14 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 13 Mar 2025 22:34:50 +0800 Subject: [PATCH 07/20] Initialize localized grid & Edit button --- Plugins/Flow.Launcher.Plugin.Sys/Command.cs | 17 +++ .../Languages/en.xaml | 5 +- Plugins/Flow.Launcher.Plugin.Sys/Main.cs | 103 +++++++++----- Plugins/Flow.Launcher.Plugin.Sys/Settings.cs | 127 ++++++++++++++++++ .../SettingsViewModel.cs | 12 ++ .../Flow.Launcher.Plugin.Sys/SysSettings.xaml | 38 +++++- .../SysSettings.xaml.cs | 44 ++++-- 7 files changed, 301 insertions(+), 45 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/Command.cs create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/Settings.cs create mode 100644 Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Command.cs b/Plugins/Flow.Launcher.Plugin.Sys/Command.cs new file mode 100644 index 000000000..84f5f046f --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/Command.cs @@ -0,0 +1,17 @@ +using System.Text.Json.Serialization; + +namespace Flow.Launcher.Plugin.Sys +{ + public class Command : BaseModel + { + public string Key { get; set; } + + [JsonIgnore] + public string Name { get; set; } + + [JsonIgnore] + public string Description { get; set; } + + public string Keyword { get; set; } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml index 2a266f8f6..e1d83fa38 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml @@ -4,8 +4,9 @@ xmlns:system="clr-namespace:System;assembly=mscorlib"> - Command + Name Description + Command Shutdown Restart @@ -29,6 +30,8 @@ Toggle Game Mode Set the Flow Launcher Theme + Edit + Shutdown Computer Restart Computer diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs index 05687701d..ef9da2719 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/Main.cs @@ -19,8 +19,36 @@ namespace Flow.Launcher.Plugin.Sys public class Main : IPlugin, ISettingProvider, IPluginI18n { private PluginInitContext context; + private Settings settings; private ThemeSelector themeSelector; - private Dictionary KeywordTitleMappings = new Dictionary(); + + private readonly Dictionary KeywordTitleMappings = new() + { + {"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"}, + {"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"}, + {"Restart With Advanced Boot Options", "flowlauncher_plugin_sys_restart_advanced_cmd"}, + {"Log Off/Sign Out", "flowlauncher_plugin_sys_log_off_cmd"}, + {"Lock", "flowlauncher_plugin_sys_lock_cmd"}, + {"Sleep", "flowlauncher_plugin_sys_sleep_cmd"}, + {"Hibernate", "flowlauncher_plugin_sys_hibernate_cmd"}, + {"Index Option", "flowlauncher_plugin_sys_indexoption_cmd"}, + {"Empty Recycle Bin", "flowlauncher_plugin_sys_emptyrecyclebin_cmd"}, + {"Open Recycle Bin", "flowlauncher_plugin_sys_openrecyclebin_cmd"}, + {"Exit", "flowlauncher_plugin_sys_exit_cmd"}, + {"Save Settings", "flowlauncher_plugin_sys_save_all_settings_cmd"}, + {"Restart Flow Launcher", "flowlauncher_plugin_sys_restart_cmd"}, + {"Settings", "flowlauncher_plugin_sys_setting_cmd"}, + {"Reload Plugin Data", "flowlauncher_plugin_sys_reload_plugin_data_cmd"}, + {"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"}, + {"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"}, + {"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"}, + {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"}, + {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, + {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} + }; + private readonly Dictionary KeywordDescriptionMappings = new(); + + private SettingsViewModel _viewModel; // SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons. // SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure @@ -28,12 +56,8 @@ namespace Flow.Launcher.Plugin.Sys public Control CreateSettingPanel() { - var commands = Commands(); - foreach (var c in commands) - { - c.Title = GetDynamicTitle(null, c); - } - return new SysSettings(commands); + UpdateLocalizedNameDescription(false); + return new SysSettings(_viewModel); } public List Query(Query query) @@ -67,6 +91,29 @@ namespace Flow.Launcher.Plugin.Sys return results; } + private string GetTitle(string key) + { + if (!KeywordTitleMappings.TryGetValue(key, out var translationKey)) + { + Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Title not found for: {key}"); + return "Title Not Found"; + } + + return context.API.GetTranslation(translationKey); + } + + private string GetDescription(string key) + { + if (!KeywordDescriptionMappings.TryGetValue(key, out var translationKey)) + { + Log.Error("Flow.Launcher.Plugin.Sys.Main", $"Description not found for: {key}"); + return "Description Not Found"; + } + + return context.API.GetTranslation(translationKey); + } + + [Obsolete] private string GetDynamicTitle(Query query, Result result) { if (!KeywordTitleMappings.TryGetValue(result.Title, out var translationKey)) @@ -96,30 +143,26 @@ namespace Flow.Launcher.Plugin.Sys public void Init(PluginInitContext context) { this.context = context; + settings = context.API.LoadSettingJsonStorage(); + _viewModel = new SettingsViewModel(settings); themeSelector = new ThemeSelector(context); - KeywordTitleMappings = new Dictionary{ - {"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"}, - {"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"}, - {"Restart With Advanced Boot Options", "flowlauncher_plugin_sys_restart_advanced_cmd"}, - {"Log Off/Sign Out", "flowlauncher_plugin_sys_log_off_cmd"}, - {"Lock", "flowlauncher_plugin_sys_lock_cmd"}, - {"Sleep", "flowlauncher_plugin_sys_sleep_cmd"}, - {"Hibernate", "flowlauncher_plugin_sys_hibernate_cmd"}, - {"Index Option", "flowlauncher_plugin_sys_indexoption_cmd"}, - {"Empty Recycle Bin", "flowlauncher_plugin_sys_emptyrecyclebin_cmd"}, - {"Open Recycle Bin", "flowlauncher_plugin_sys_openrecyclebin_cmd"}, - {"Exit", "flowlauncher_plugin_sys_exit_cmd"}, - {"Save Settings", "flowlauncher_plugin_sys_save_all_settings_cmd"}, - {"Restart Flow Launcher", "flowlauncher_plugin_sys_restart_cmd"}, - {"Settings", "flowlauncher_plugin_sys_setting_cmd"}, - {"Reload Plugin Data", "flowlauncher_plugin_sys_reload_plugin_data_cmd"}, - {"Check For Update", "flowlauncher_plugin_sys_check_for_update_cmd"}, - {"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"}, - {"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"}, - {"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"}, - {"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}, - {"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"} - }; + foreach (string key in KeywordTitleMappings.Keys) + { + // Remove _cmd in the last of the strings + KeywordDescriptionMappings[key] = KeywordTitleMappings[key][..^4]; + } + } + + private void UpdateLocalizedNameDescription(bool force) + { + if (string.IsNullOrEmpty(settings.Commands[0].Name) || force) + { + foreach (var c in settings.Commands) + { + c.Name = GetTitle(c.Key); + c.Description = GetDescription(c.Key); + } + } } private static unsafe bool EnableShutdownPrivilege() diff --git a/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs new file mode 100644 index 000000000..f39e6d65f --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/Settings.cs @@ -0,0 +1,127 @@ +using System.Collections.ObjectModel; +using System.Text.Json.Serialization; + +namespace Flow.Launcher.Plugin.Sys; + +public class Settings : BaseModel +{ + public Settings() + { + if (Commands.Count > 0) + { + SelectedCommand = Commands[0]; + } + } + + public ObservableCollection Commands { get; set; } = new ObservableCollection + { + new() + { + Key = "Shutdown", + Keyword = "Shutdown" + }, + new() + { + Key = "Restart", + Keyword = "Restart" + }, + new() + { + Key = "Restart With Advanced Boot Options", + Keyword = "Restart With Advanced Boot Options" + }, + new() + { + Key = "Log Off/Sign Out", + Keyword = "Log Off/Sign Out" + }, + new() + { + Key = "Lock", + Keyword = "Lock" + }, + new() + { + Key = "Sleep", + Keyword = "Sleep" + }, + new() + { + Key = "Hibernate", + Keyword = "Hibernate" + }, + new() + { + Key = "Index Option", + Keyword = "Index Option" + }, + new() + { + Key = "Empty Recycle Bin", + Keyword = "Empty Recycle Bin" + }, + new() + { + Key = "Open Recycle Bin", + Keyword = "Open Recycle Bin" + }, + new() + { + Key = "Exit", + Keyword = "Exit" + }, + new() + { + Key = "Save Settings", + Keyword = "Save Settings" + }, + new() + { + Key = "Restart Flow Launcher", + Keyword = "Restart Flow Launcher" + }, + new() + { + Key = "Settings", + Keyword = "Settings" + }, + new() + { + Key = "Reload Plugin Data", + Keyword = "Reload Plugin Data" + }, + new() + { + Key = "Check For Update", + Keyword = "Check For Update" + }, + new() + { + Key = "Open Log Location", + Keyword = "Open Log Location" + }, + new() + { + Key = "Flow Launcher Tips", + Keyword = "Flow Launcher Tips" + }, + new() + { + Key = "Flow Launcher UserData Folder", + Keyword = "Flow Launcher UserData Folder" + }, + new() + { + Key = "Toggle Game Mode", + Keyword = "Toggle Game Mode" + }, + new() + { + Key = "Set Flow Launcher Theme", + Keyword = "Set Flow Launcher Theme" + } + }; + + [JsonIgnore] + public Command SelectedCommand { get; set; } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs new file mode 100644 index 000000000..0755dffa9 --- /dev/null +++ b/Plugins/Flow.Launcher.Plugin.Sys/SettingsViewModel.cs @@ -0,0 +1,12 @@ +namespace Flow.Launcher.Plugin.Sys +{ + public class SettingsViewModel + { + public SettingsViewModel(Settings settings) + { + Settings = settings; + } + + public Settings Settings { get; } + } +} diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml index f806900de..67e840e53 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml @@ -4,36 +4,66 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vm="clr-namespace:Flow.Launcher.Plugin.Sys" + d:DataContext="{d:DesignInstance vm:SettingsViewModel}" d:DesignHeight="300" d:DesignWidth="300" mc:Ignorable="d"> - + + + + + + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -99,11 +99,12 @@ Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" - Margin="10,0,10,0" + Margin="10 0 10 0" HorizontalAlignment="Left" VerticalAlignment="Center" HorizontalContentAlignment="Left" - DefaultHotkey="" /> + DefaultHotkey="" + Type="None" /> @@ -132,21 +133,21 @@ + BorderThickness="0 1 0 0">