Skip to content

Commit edb4d74

Browse files
committed
Add timeout for folder size calculation
1 parent b1557dd commit edb4d74

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Globalization;
44
using System.IO;
55
using System.Runtime.CompilerServices;
6+
using System.Threading;
67
using System.Threading.Tasks;
78
using System.Windows;
89
using System.Windows.Controls;
@@ -149,8 +150,15 @@ public static string GetFolderSize(string folderPath)
149150
{
150151
var directoryInfo = new DirectoryInfo(folderPath);
151152
long size = 0;
153+
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));
152154
foreach (var file in directoryInfo.GetFiles("*", SearchOption.AllDirectories))
153155
{
156+
if (cancellationTokenSource.Token.IsCancellationRequested)
157+
{
158+
// Timeout occurred, return unknown size
159+
cancellationTokenSource.Dispose();
160+
return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown");
161+
}
154162
size += file.Length;
155163
}
156164
return ResultManager.ToReadableSize(size, 2);

0 commit comments

Comments
 (0)