diff --git a/src/Avalonia.Base/Platform/Storage/FileIO/BclLauncher.cs b/src/Avalonia.Base/Platform/Storage/FileIO/BclLauncher.cs index da4cb01df5..a380be57e2 100644 --- a/src/Avalonia.Base/Platform/Storage/FileIO/BclLauncher.cs +++ b/src/Avalonia.Base/Platform/Storage/FileIO/BclLauncher.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Avalonia.Logging; namespace Avalonia.Platform.Storage.FileIO; @@ -38,31 +39,40 @@ internal class BclLauncher : ILauncher private static bool Exec(string urlOrFile) { - if (OperatingSystem.IsLinux()) + try { - // If no associated application/json MimeType is found xdg-open opens return error - // but it tries to open it anyway using the console editor (nano, vim, other..) - var args = EscapeForShell(urlOrFile); - ShellExecRaw($"xdg-open \\\"{args}\\\"", waitForExit: false); - return true; - } - else if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) - { - var info = new ProcessStartInfo + if (OperatingSystem.IsLinux()) + { + // If no associated application/json MimeType is found xdg-open opens return error + // but it tries to open it anyway using the console editor (nano, vim, other..) + var args = EscapeForShell(urlOrFile); + ShellExecRaw($"xdg-open \\\"{args}\\\"", waitForExit: false); + return true; + } + else if (OperatingSystem.IsWindows() || OperatingSystem.IsMacOS()) { - FileName = OperatingSystem.IsWindows() ? urlOrFile : "open", - CreateNoWindow = true, - UseShellExecute = OperatingSystem.IsWindows() - }; - // Using the argument list avoids having to escape spaces and other special - // characters that are part of valid macos file and folder paths. - if (OperatingSystem.IsMacOS()) - info.ArgumentList.Add(urlOrFile); - using var process = Process.Start(info); - return true; + var info = new ProcessStartInfo + { + FileName = OperatingSystem.IsWindows() ? urlOrFile : "open", + CreateNoWindow = true, + UseShellExecute = OperatingSystem.IsWindows() + }; + // Using the argument list avoids having to escape spaces and other special + // characters that are part of valid macos file and folder paths. + if (OperatingSystem.IsMacOS()) + info.ArgumentList.Add(urlOrFile); + using var process = Process.Start(info); + return true; + } + else + { + return false; + } } - else + catch(Exception ex) { + Logger.TryGet(LogEventLevel.Error, nameof(BclLauncher))? + .Log(null, "Exception during BclLauncher.Exec: {Error}", ex); return false; } }