From edb4d743e9d193624871d1522a53c775ee2f1fa2 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Wed, 4 Jun 2025 17:36:37 +0800 Subject: [PATCH] Add timeout for folder size calculation --- .../Views/PreviewPanel.xaml.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs index f4d7f8436..a427a0a42 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Globalization; using System.IO; using System.Runtime.CompilerServices; +using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; @@ -149,8 +150,15 @@ public partial class PreviewPanel : UserControl, INotifyPropertyChanged { var directoryInfo = new DirectoryInfo(folderPath); long size = 0; + var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3)); foreach (var file in directoryInfo.GetFiles("*", SearchOption.AllDirectories)) { + if (cancellationTokenSource.Token.IsCancellationRequested) + { + // Timeout occurred, return unknown size + cancellationTokenSource.Dispose(); + return Main.Context.API.GetTranslation("plugin_explorer_plugin_tooltip_more_info_unknown"); + } size += file.Length; } return ResultManager.ToReadableSize(size, 2);