Skip to content

Commit 74da028

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#3901 from Flow-Launcher/ShowMsgError
Use ShowMsgError API Function & Handle E_ABORT COMException
1 parent d0cc9a5 commit 74da028

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,9 @@ private static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source
104104
API.GetTranslation("pluginsHaveErrored") :
105105
API.GetTranslation("pluginHasErrored");
106106

107-
_ = Task.Run(() =>
108-
{
109-
API.ShowMsgBox($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
110-
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
111-
API.GetTranslation("referToLogs"), string.Empty,
112-
MessageBoxButton.OK, MessageBoxImage.Warning);
113-
});
107+
API.ShowMsgError($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
108+
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
109+
API.GetTranslation("referToLogs"));
114110
}
115111

116112
return plugins;

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Net;
1010
using System.Runtime.CompilerServices;
11+
using System.Runtime.InteropServices;
1112
using System.Threading;
1213
using System.Threading.Tasks;
1314
using System.Windows;
@@ -348,24 +349,35 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
348349
explorer.Start();
349350
}
350351
}
352+
catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004004))
353+
{
354+
/*
355+
* The COMException with HResult 0x80004004 is E_ABORT (operation aborted).
356+
* Shell APIs often return this when the operation is canceled or the shell cannot complete it cleanly.
357+
* It most likely comes from Win32Helper.OpenFolderAndSelectFile(targetPath).
358+
* Typical triggers:
359+
* The target file/folder was deleted/moved between computing targetPath and the shell call.
360+
* The folder is on an offline network/removable drive.
361+
* Explorer is restarting/busy and aborts the request.
362+
* A selection request to a new/closing Explorer window is canceled.
363+
* Because it is commonly user- or environment-driven and not actionable,
364+
* we should treat it as expected noise and ignore it to avoid bothering users.
365+
*/
366+
}
351367
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
352368
{
353369
LogError(ClassName, "File Manager not found");
354-
ShowMsgBox(
355-
string.Format(GetTranslation("fileManagerNotFound"), ex.Message),
370+
ShowMsgError(
356371
GetTranslation("fileManagerNotFoundTitle"),
357-
MessageBoxButton.OK,
358-
MessageBoxImage.Error
372+
string.Format(GetTranslation("fileManagerNotFound"), ex.Message)
359373
);
360374
}
361375
catch (Exception ex)
362376
{
363377
LogException(ClassName, "Failed to open folder", ex);
364-
ShowMsgBox(
365-
string.Format(GetTranslation("folderOpenError"), ex.Message),
378+
ShowMsgError(
366379
GetTranslation("errorTitle"),
367-
MessageBoxButton.OK,
368-
MessageBoxImage.Error
380+
string.Format(GetTranslation("folderOpenError"), ex.Message)
369381
);
370382
}
371383
}
@@ -393,11 +405,9 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
393405
{
394406
var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window";
395407
LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e);
396-
ShowMsgBox(
397-
GetTranslation("browserOpenError"),
408+
ShowMsgError(
398409
GetTranslation("errorTitle"),
399-
MessageBoxButton.OK,
400-
MessageBoxImage.Error
410+
GetTranslation("browserOpenError")
401411
);
402412
}
403413
}

0 commit comments

Comments
 (0)