Merge pull request #3499 from Flow-Launcher/clear_cache_freeze_page

Fix clean cache issue
This commit is contained in:
Jack Ye 2025-04-30 19:55:31 +08:00 committed by GitHub
commit 950a7f5f2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -186,7 +186,8 @@ public partial class SettingsPaneAboutViewModel : BaseModel
{
try
{
dir.Delete(true);
// Log folders are the last level of folders
dir.Delete(recursive: false);
}
catch (Exception e)
{
@ -214,6 +215,7 @@ public partial class SettingsPaneAboutViewModel : BaseModel
{
var success = true;
var cacheDirectory = GetCacheDir();
var pluginCacheDirectory = GetPluginCacheDir();
var cacheFiles = GetCacheFiles();
cacheFiles.ForEach(f =>
@ -229,13 +231,15 @@ public partial class SettingsPaneAboutViewModel : BaseModel
}
});
cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
// Firstly, delete plugin cache directories
pluginCacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
.ToList()
.ForEach(dir =>
{
try
{
dir.Delete(true);
// Plugin may create directories in its cache directory
dir.Delete(recursive: true);
}
catch (Exception e)
{
@ -244,6 +248,18 @@ public partial class SettingsPaneAboutViewModel : BaseModel
}
});
// Then, delete plugin directory
var dir = GetPluginCacheDir();
try
{
dir.Delete(recursive: false);
}
catch (Exception e)
{
App.API.LogException(ClassName, $"Failed to delete cache directory: {dir.Name}", e);
success = false;
}
OnPropertyChanged(nameof(CacheFolderSize));
return success;
@ -254,6 +270,11 @@ public partial class SettingsPaneAboutViewModel : BaseModel
return new DirectoryInfo(DataLocation.CacheDirectory);
}
private static DirectoryInfo GetPluginCacheDir()
{
return new DirectoryInfo(DataLocation.PluginCacheDirectory);
}
private static List<FileInfo> GetCacheFiles()
{
return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList();