From 1fea8edb747470b076376b76473d52f9c8253f51 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 11:46:09 +0800 Subject: [PATCH 1/6] Add translation for default items & new profile item for explorer & browser window --- .../UserSettings/CustomBrowserViewModel.cs | 17 +++++++++++++---- .../UserSettings/CustomExplorerViewModel.cs | 15 ++++++++++++++- Flow.Launcher/Languages/en.xaml | 3 +++ Flow.Launcher/SelectBrowserWindow.xaml | 2 +- Flow.Launcher/SelectBrowserWindow.xaml.cs | 12 +++++++++++- Flow.Launcher/SelectFileManagerWindow.xaml | 2 +- .../ViewModels/SettingsPaneGeneralViewModel.cs | 4 +++- .../SettingPages/Views/SettingsPaneGeneral.xaml | 4 ++-- .../ViewModel/SelectBrowserViewModel.cs | 12 +----------- 9 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs index 24584115d8c..9c795f952a9 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs @@ -1,11 +1,18 @@ +using System.Text.Json.Serialization; +using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Plugin; -using System.Text.Json.Serialization; namespace Flow.Launcher.Infrastructure.UserSettings { public class CustomBrowserViewModel : BaseModel { + // We should not initialize API in static constructor because it will create another API instance + private static IPublicAPI api = null; + private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); + public string Name { get; set; } + [JsonIgnore] + public string DisplayName => Name == "Default" ? API.GetTranslation("defaultBrowser_default") : Name; public string Path { get; set; } public string PrivateArg { get; set; } public bool EnablePrivate { get; set; } @@ -26,8 +33,10 @@ public CustomBrowserViewModel Copy() Editable = Editable }; } + + public void OnDisplayNameChanged() + { + OnPropertyChanged(nameof(DisplayName)); + } } } - - - diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs index c54c30478b3..5727f073577 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs @@ -1,10 +1,18 @@ -using Flow.Launcher.Plugin; +using System.Text.Json.Serialization; +using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Plugin; namespace Flow.Launcher.ViewModel { public class CustomExplorerViewModel : BaseModel { + // We should not initialize API in static constructor because it will create another API instance + private static IPublicAPI api = null; + private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService(); + public string Name { get; set; } + [JsonIgnore] + public string DisplayName => Name == "Explorer" ? API.GetTranslation("fileManagerExplorer") : Name; public string Path { get; set; } public string FileArgument { get; set; } = "\"%d\""; public string DirectoryArgument { get; set; } = "\"%d\""; @@ -21,5 +29,10 @@ public CustomExplorerViewModel Copy() Editable = Editable }; } + + public void OnDisplayNameChanged() + { + OnPropertyChanged(nameof(DisplayName)); + } } } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index f7fd0c8e588..b38fe8aab67 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -487,6 +487,7 @@ Arg For File The file manager '{0}' could not be located at '{1}'. Would you like to continue? File Manager Path Error + File Explorer Default Web Browser @@ -497,6 +498,8 @@ New Window New Tab Private Mode + Default + New Profile Change Priority diff --git a/Flow.Launcher/SelectBrowserWindow.xaml b/Flow.Launcher/SelectBrowserWindow.xaml index d51d597b751..67c22b07d19 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml +++ b/Flow.Launcher/SelectBrowserWindow.xaml @@ -92,7 +92,7 @@ SelectedIndex="{Binding SelectedCustomBrowserIndex}"> - + diff --git a/Flow.Launcher/SelectBrowserWindow.xaml.cs b/Flow.Launcher/SelectBrowserWindow.xaml.cs index 565b4cbc338..8ef50ca75a3 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml.cs +++ b/Flow.Launcher/SelectBrowserWindow.xaml.cs @@ -31,7 +31,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e) private void btnBrowseFile_Click(object sender, RoutedEventArgs e) { - var selectedFilePath = _viewModel.SelectFile(); + var selectedFilePath = SelectFile(); if (!string.IsNullOrEmpty(selectedFilePath)) { @@ -41,5 +41,15 @@ private void btnBrowseFile_Click(object sender, RoutedEventArgs e) ((Button)sender).Focus(); } } + + private static string SelectFile() + { + var dlg = new Microsoft.Win32.OpenFileDialog(); + var result = dlg.ShowDialog(); + if (result == true) + return dlg.FileName; + + return string.Empty; + } } } diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml b/Flow.Launcher/SelectFileManagerWindow.xaml index b3b219d1c1e..cd4bec42466 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml +++ b/Flow.Launcher/SelectFileManagerWindow.xaml @@ -102,7 +102,7 @@ SelectedIndex="{Binding SelectedCustomExplorerIndex}"> - + diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs index ec75ddf9040..b47b53654b4 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneGeneralViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -219,6 +219,8 @@ private void UpdateEnumDropdownLocalizations() DropdownDataGeneric.UpdateLabels(DialogJumpFileResultBehaviours); // Since we are using Binding instead of DynamicResource, we need to manually trigger the update OnPropertyChanged(nameof(AlwaysPreviewToolTip)); + Settings.CustomExplorer.OnDisplayNameChanged(); + Settings.CustomBrowser.OnDisplayNameChanged(); } public string Language diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml index 81e15df6950..07cc7b6a750 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml @@ -403,7 +403,7 @@ MaxWidth="250" Margin="10 0 0 0" Command="{Binding SelectFileManagerCommand}" - Content="{Binding Settings.CustomExplorer.Name}" /> + Content="{Binding Settings.CustomExplorer.DisplayName}" /> + Content="{Binding Settings.CustomBrowser.DisplayName}" /> diff --git a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs index 67bbbd9301f..bcc6f1489e1 100644 --- a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs @@ -40,22 +40,12 @@ public bool SaveSettings() return true; } - internal string SelectFile() - { - var dlg = new Microsoft.Win32.OpenFileDialog(); - var result = dlg.ShowDialog(); - if (result == true) - return dlg.FileName; - - return string.Empty; - } - [RelayCommand] private void Add() { CustomBrowsers.Add(new() { - Name = "New Profile" + Name = App.API.GetTranslation("defaultBrowser_new_profile") }); SelectedCustomBrowserIndex = CustomBrowsers.Count - 1; } From 647c55eaf7e60a525f7e9c4ffa3a1c5809e39d66 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 11:47:18 +0800 Subject: [PATCH 2/6] Add property changed check --- Flow.Launcher/ViewModel/SelectBrowserViewModel.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs index bcc6f1489e1..f75a0ef8bf2 100644 --- a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs @@ -17,8 +17,11 @@ public int SelectedCustomBrowserIndex get => selectedCustomBrowserIndex; set { - selectedCustomBrowserIndex = value; - OnPropertyChanged(nameof(CustomBrowser)); + if (selectedCustomBrowserIndex != value) + { + selectedCustomBrowserIndex = value; + OnPropertyChanged(nameof(CustomBrowser)); + } } } From dd07baff59756db8b83e0a1ca362c136cd51b2d6 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 11:58:38 +0800 Subject: [PATCH 3/6] Add SelectFile helper method & Improve code quality --- Flow.Launcher.Infrastructure/Win32Helper.cs | 16 +++++++++++++++- Flow.Launcher/SelectBrowserWindow.xaml.cs | 13 ++----------- Flow.Launcher/SelectFileManagerWindow.xaml.cs | 5 +++-- .../ViewModel/SelectFileManagerViewModel.cs | 15 --------------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Win32Helper.cs b/Flow.Launcher.Infrastructure/Win32Helper.cs index 8117339254d..5d30b740d78 100644 --- a/Flow.Launcher.Infrastructure/Win32Helper.cs +++ b/Flow.Launcher.Infrastructure/Win32Helper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; @@ -904,5 +904,19 @@ public static void EnableWin32DarkMode(string colorScheme) } #endregion + + #region File / Folder Dialog + + public static string SelectFile() + { + var dlg = new OpenFileDialog(); + var result = dlg.ShowDialog(); + if (result == true) + return dlg.FileName; + + return string.Empty; + } + + #endregion } } diff --git a/Flow.Launcher/SelectBrowserWindow.xaml.cs b/Flow.Launcher/SelectBrowserWindow.xaml.cs index 8ef50ca75a3..290712aad62 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml.cs +++ b/Flow.Launcher/SelectBrowserWindow.xaml.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Infrastructure; using Flow.Launcher.ViewModel; namespace Flow.Launcher @@ -31,7 +32,7 @@ private void btnDone_Click(object sender, RoutedEventArgs e) private void btnBrowseFile_Click(object sender, RoutedEventArgs e) { - var selectedFilePath = SelectFile(); + var selectedFilePath = Win32Helper.SelectFile(); if (!string.IsNullOrEmpty(selectedFilePath)) { @@ -41,15 +42,5 @@ private void btnBrowseFile_Click(object sender, RoutedEventArgs e) ((Button)sender).Focus(); } } - - private static string SelectFile() - { - var dlg = new Microsoft.Win32.OpenFileDialog(); - var result = dlg.ShowDialog(); - if (result == true) - return dlg.FileName; - - return string.Empty; - } } } diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml.cs b/Flow.Launcher/SelectFileManagerWindow.xaml.cs index d9c672aff67..5143f9a56f8 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml.cs +++ b/Flow.Launcher/SelectFileManagerWindow.xaml.cs @@ -2,6 +2,7 @@ using System.Windows.Controls; using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; +using Flow.Launcher.Infrastructure; using Flow.Launcher.ViewModel; namespace Flow.Launcher @@ -32,13 +33,13 @@ private void btnDone_Click(object sender, RoutedEventArgs e) private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { - _viewModel.OpenUrl(e.Uri.AbsoluteUri); + App.API.OpenUrl(e.Uri.AbsoluteUri); e.Handled = true; } private void btnBrowseFile_Click(object sender, RoutedEventArgs e) { - var selectedFilePath = _viewModel.SelectFile(); + var selectedFilePath = Win32Helper.SelectFile(); if (!string.IsNullOrEmpty(selectedFilePath)) { diff --git a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs index 77f004980b1..253f74b47f1 100644 --- a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs @@ -98,21 +98,6 @@ private static bool IsFileManagerValid(string path) } } - internal void OpenUrl(string absoluteUri) - { - App.API.OpenUrl(absoluteUri); - } - - internal string SelectFile() - { - var dlg = new Microsoft.Win32.OpenFileDialog(); - var result = dlg.ShowDialog(); - if (result == true) - return dlg.FileName; - - return string.Empty; - } - [RelayCommand] private void Add() { From a03f62832ad52362cefc06f23f5130e1d78c82af Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 12:08:49 +0800 Subject: [PATCH 4/6] Ignore index change for -1 --- Flow.Launcher/ViewModel/SelectBrowserViewModel.cs | 2 ++ Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs index f75a0ef8bf2..e3a0e4e4404 100644 --- a/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectBrowserViewModel.cs @@ -17,6 +17,8 @@ public int SelectedCustomBrowserIndex get => selectedCustomBrowserIndex; set { + // When one custom browser is selected and removed, the index will become -1, so we need to ignore this change + if (value < 0) return; if (selectedCustomBrowserIndex != value) { selectedCustomBrowserIndex = value; diff --git a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs index 253f74b47f1..b0851b90c67 100644 --- a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs @@ -21,6 +21,8 @@ public int SelectedCustomExplorerIndex get => selectedCustomExplorerIndex; set { + // When one custom file manager is selected and removed, the index will become -1, so we need to ignore this change + if (value < 0) return; if (selectedCustomExplorerIndex != value) { selectedCustomExplorerIndex = value; From 256ae5c4b0a49b24f37326ef6a25218581d68aec Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 12:15:33 +0800 Subject: [PATCH 5/6] Fill missing translation --- Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs index b0851b90c67..f6a32e3fed5 100644 --- a/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs +++ b/Flow.Launcher/ViewModel/SelectFileManagerViewModel.cs @@ -105,7 +105,7 @@ private void Add() { CustomExplorers.Add(new() { - Name = "New Profile" + Name = App.API.GetTranslation("defaultBrowser_new_profile") }); SelectedCustomExplorerIndex = CustomExplorers.Count - 1; } From 101750115389e169a491f42c3ece4310165eec3d Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 18 Sep 2025 12:36:40 +0800 Subject: [PATCH 6/6] Fix namespace issue --- .../UserSettings/CustomExplorerViewModel.cs | 2 +- Flow.Launcher.Infrastructure/UserSettings/Settings.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs index 5727f073577..2af0bb0e53a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs @@ -2,7 +2,7 @@ using CommunityToolkit.Mvvm.DependencyInjection; using Flow.Launcher.Plugin; -namespace Flow.Launcher.ViewModel +namespace Flow.Launcher.Infrastructure.UserSettings { public class CustomExplorerViewModel : BaseModel { diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 23f9047fef7..f70c4559b38 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -9,7 +9,6 @@ using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; using Flow.Launcher.Plugin.SharedModels; -using Flow.Launcher.ViewModel; namespace Flow.Launcher.Infrastructure.UserSettings {