Skip to content

Commit e730235

Browse files
authored
Merge pull request #3901 from Flow-Launcher/ShowMsgError
Use ShowMsgError API Function & Handle E_ABORT COMException
2 parents 0f243fa + 556dce9 commit e730235

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
@@ -124,13 +124,9 @@ private static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source
124124
API.GetTranslation("pluginsHaveErrored") :
125125
API.GetTranslation("pluginHasErrored");
126126

127-
_ = Task.Run(() =>
128-
{
129-
API.ShowMsgBox($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
130-
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
131-
API.GetTranslation("referToLogs"), string.Empty,
132-
MessageBoxButton.OK, MessageBoxImage.Warning);
133-
});
127+
API.ShowMsgError($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
128+
$"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
129+
API.GetTranslation("referToLogs"));
134130
}
135131

136132
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;
@@ -379,24 +380,35 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
379380
explorer.Start();
380381
}
381382
}
383+
catch (COMException ex) when (ex.ErrorCode == unchecked((int)0x80004004))
384+
{
385+
/*
386+
* The COMException with HResult 0x80004004 is E_ABORT (operation aborted).
387+
* Shell APIs often return this when the operation is canceled or the shell cannot complete it cleanly.
388+
* It most likely comes from Win32Helper.OpenFolderAndSelectFile(targetPath).
389+
* Typical triggers:
390+
* The target file/folder was deleted/moved between computing targetPath and the shell call.
391+
* The folder is on an offline network/removable drive.
392+
* Explorer is restarting/busy and aborts the request.
393+
* A selection request to a new/closing Explorer window is canceled.
394+
* Because it is commonly user- or environment-driven and not actionable,
395+
* we should treat it as expected noise and ignore it to avoid bothering users.
396+
*/
397+
}
382398
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
383399
{
384400
LogError(ClassName, "File Manager not found");
385-
ShowMsgBox(
386-
string.Format(GetTranslation("fileManagerNotFound"), ex.Message),
401+
ShowMsgError(
387402
GetTranslation("fileManagerNotFoundTitle"),
388-
MessageBoxButton.OK,
389-
MessageBoxImage.Error
403+
string.Format(GetTranslation("fileManagerNotFound"), ex.Message)
390404
);
391405
}
392406
catch (Exception ex)
393407
{
394408
LogException(ClassName, "Failed to open folder", ex);
395-
ShowMsgBox(
396-
string.Format(GetTranslation("folderOpenError"), ex.Message),
409+
ShowMsgError(
397410
GetTranslation("errorTitle"),
398-
MessageBoxButton.OK,
399-
MessageBoxImage.Error
411+
string.Format(GetTranslation("folderOpenError"), ex.Message)
400412
);
401413
}
402414
}
@@ -424,11 +436,9 @@ private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
424436
{
425437
var tabOrWindow = browserInfo.OpenInTab ? "tab" : "window";
426438
LogException(ClassName, $"Failed to open URL in browser {tabOrWindow}: {path}, {inPrivate ?? browserInfo.EnablePrivate}, {browserInfo.PrivateArg}", e);
427-
ShowMsgBox(
428-
GetTranslation("browserOpenError"),
439+
ShowMsgError(
429440
GetTranslation("errorTitle"),
430-
MessageBoxButton.OK,
431-
MessageBoxImage.Error
441+
GetTranslation("browserOpenError")
432442
);
433443
}
434444
}

0 commit comments

Comments
 (0)