diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 027eb3f926d..f00f42ac095 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -226,8 +226,8 @@ public CustomExplorerViewModel CustomExplorer new() { Name = "Files", - Path = "Files", - DirectoryArgument = "-select \"%d\"", + Path = "Files-Stable", + DirectoryArgument = "\"%d\"", FileArgument = "-select \"%f\"" } }; diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs index 942e9447037..969bb75bbf9 100644 --- a/Flow.Launcher/App.xaml.cs +++ b/Flow.Launcher/App.xaml.cs @@ -98,6 +98,10 @@ public App() .AddTransient() .AddTransient() .AddTransient() + // Use transient instance for dialog view models because + // settings will change and we need to recreate them + .AddTransient() + .AddTransient() ).Build(); Ioc.Default.ConfigureServices(host.Services); } diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 22ab2016cc0..f233a30d56f 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -366,6 +366,7 @@ Select File Manager + Learn more Please specify the file location of the file manager you using and add arguments as required. The "%d" represents the directory path to open for, used by the Arg for Folder field and for commands opening specific directories. The "%f" represents the file path to open for, used by the Arg for File field and for commands opening specific files. For example, if the file manager uses a command such as "totalcmd.exe /A c:\windows" to open the c:\windows directory, the File Manager Path will be totalcmd.exe, and the Arg For Folder will be /A "%d". Certain file managers like QTTabBar may just require a path to be supplied, in this instance use "%d" as the File Manager Path and leave the rest of the fileds blank. File Manager @@ -373,6 +374,8 @@ File Manager Path Arg For Folder Arg For File + The file manager '{0}' could not be located at '{1}'. Would you like to continue? + File Manager Path Error Default Web Browser @@ -462,6 +465,14 @@ 1. Upload log file: {0} 2. Copy below exception message + + File Manager Error + + The specified file manager could not be found. Please check the Custom File Manager setting under Settings > General. + + Error + An error occurred while opening the folder. {0} + Please wait... diff --git a/Flow.Launcher/MessageBoxEx.xaml.cs b/Flow.Launcher/MessageBoxEx.xaml.cs index a55aeb81118..c084b5149d3 100644 --- a/Flow.Launcher/MessageBoxEx.xaml.cs +++ b/Flow.Launcher/MessageBoxEx.xaml.cs @@ -22,9 +22,6 @@ private MessageBoxEx(MessageBoxButton button) InitializeComponent(); } - public static MessageBoxResult Show(string messageBoxText) - => Show(messageBoxText, string.Empty, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK); - public static MessageBoxResult Show( string messageBoxText, string caption = "", diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 796f65ae60a..a0614d90fd5 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -32,11 +32,14 @@ using JetBrains.Annotations; using Squirrel; using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; +using System.ComponentModel; namespace Flow.Launcher { public class PublicAPIInstance : IPublicAPI, IRemovable { + private static readonly string ClassName = nameof(PublicAPIInstance); + private readonly Settings _settings; private readonly MainViewModel _mainVM; @@ -316,40 +319,63 @@ public void SavePluginSettings() public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null) { - using var explorer = new Process(); - var explorerInfo = _settings.CustomExplorer; - var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); - var targetPath = FileNameOrFilePath is null - ? DirectoryPath - : Path.IsPathRooted(FileNameOrFilePath) - ? FileNameOrFilePath - : Path.Combine(DirectoryPath, FileNameOrFilePath); - - if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") + try { - // Windows File Manager - // We should ignore and pass only the path to Shell to prevent zombie explorer.exe processes - explorer.StartInfo = new ProcessStartInfo + using var explorer = new Process(); + var explorerInfo = _settings.CustomExplorer; + var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant(); + var targetPath = FileNameOrFilePath is null + ? DirectoryPath + : Path.IsPathRooted(FileNameOrFilePath) + ? FileNameOrFilePath + : Path.Combine(DirectoryPath, FileNameOrFilePath); + + if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer") { - FileName = targetPath, // Not explorer, Only path. - UseShellExecute = true // Must be true to open folder - }; + // Windows File Manager + explorer.StartInfo = new ProcessStartInfo + { + FileName = targetPath, + UseShellExecute = true + }; + } + else + { + // Custom File Manager + explorer.StartInfo = new ProcessStartInfo + { + FileName = explorerInfo.Path.Replace("%d", DirectoryPath), + UseShellExecute = true, + Arguments = FileNameOrFilePath is null + ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) + : explorerInfo.FileArgument + .Replace("%d", DirectoryPath) + .Replace("%f", targetPath) + }; + } + + explorer.Start(); } - else + catch (Win32Exception ex) when (ex.NativeErrorCode == 2) { - // Custom File Manager - explorer.StartInfo = new ProcessStartInfo - { - FileName = explorerInfo.Path.Replace("%d", DirectoryPath), - UseShellExecute = true, - Arguments = FileNameOrFilePath is null - ? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) - : explorerInfo.FileArgument - .Replace("%d", DirectoryPath) - .Replace("%f", targetPath) - }; + LogError(ClassName, "File Manager not found"); + ShowMsgBox( + string.Format(GetTranslation("fileManagerNotFound"), ex.Message), + GetTranslation("fileManagerNotFoundTitle"), + MessageBoxButton.OK, + MessageBoxImage.Error + ); + } + catch (Exception ex) + { + LogException(ClassName, "Failed to open folder", ex); + ShowMsgBox( + string.Format(GetTranslation("folderOpenError"), ex.Message), + GetTranslation("errorTitle"), + MessageBoxButton.OK, + MessageBoxImage.Error + ); } - explorer.Start(); } private void OpenUri(Uri uri, bool? inPrivate = null) diff --git a/Flow.Launcher/SelectBrowserWindow.xaml b/Flow.Launcher/SelectBrowserWindow.xaml index 4a0928dc2e6..d51d597b751 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml +++ b/Flow.Launcher/SelectBrowserWindow.xaml @@ -6,10 +6,11 @@ xmlns:local="clr-namespace:Flow.Launcher" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:vm="clr-namespace:Flow.Launcher.ViewModel" Title="{DynamicResource defaultBrowserTitle}" Width="550" + d:DataContext="{d:DesignInstance vm:SelectBrowserViewModel}" Background="{DynamicResource PopuBGColor}" - DataContext="{Binding RelativeSource={RelativeSource Self}}" Foreground="{DynamicResource PopupTextColor}" ResizeMode="NoResize" SizeToContent="Height" @@ -97,11 +98,11 @@