From 8e8b5dbbba6d45c9304b556c022fe2ebf277ed5d Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 1 Apr 2025 19:18:32 +0800 Subject: [PATCH 01/26] Code quality --- .../ViewModels/SettingsPaneAboutViewModel.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 20f905411..07e9fba1e 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using System.Windows; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; -using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Infrastructure.UserSettings; @@ -24,7 +23,7 @@ public partial class SettingsPaneAboutViewModel : BaseModel get { var size = GetLogFiles().Sum(file => file.Length); - return $"{InternationalizationManager.Instance.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})"; + return $"{App.API.GetTranslation("clearlogfolder")} ({BytesToReadableString(size)})"; } } @@ -42,7 +41,7 @@ public partial class SettingsPaneAboutViewModel : BaseModel }; public string ActivatedTimes => string.Format( - InternationalizationManager.Instance.GetTranslation("about_activate_times"), + App.API.GetTranslation("about_activate_times"), _settings.ActivateTimes ); @@ -88,8 +87,8 @@ public partial class SettingsPaneAboutViewModel : BaseModel private void AskClearLogFolderConfirmation() { var confirmResult = App.API.ShowMsgBox( - InternationalizationManager.Instance.GetTranslation("clearlogfolderMessage"), - InternationalizationManager.Instance.GetTranslation("clearlogfolder"), + App.API.GetTranslation("clearlogfolderMessage"), + App.API.GetTranslation("clearlogfolder"), MessageBoxButton.YesNo ); @@ -121,7 +120,7 @@ public partial class SettingsPaneAboutViewModel : BaseModel } [RelayCommand] - private Task UpdateApp() => _updater.UpdateAppAsync(false); + private Task UpdateAppAsync() => _updater.UpdateAppAsync(false); private void ClearLogFolder() { From 482fdc939f9fd01dfdd4b75f485e30768c43e63d Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 1 Apr 2025 20:12:27 +0800 Subject: [PATCH 02/26] Add clean cache option --- Flow.Launcher/Languages/en.xaml | 2 + .../ViewModels/SettingsPaneAboutViewModel.cs | 49 ++++++++++++++++++- .../SettingPages/Views/SettingsPaneAbout.xaml | 4 ++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 2df430c3b..6963d81c9 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -325,6 +325,8 @@ Log Folder Clear Logs Are you sure you want to delete all logs? + Clear Caches + Are you sure you want to delete all caches? Wizard User Data Location User settings and installed plugins are saved in the user data folder. This location may vary depending on whether it's in portable mode or not. diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 07e9fba1e..47cb1b6c3 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -27,6 +27,15 @@ public partial class SettingsPaneAboutViewModel : BaseModel } } + public string CacheFolderSize + { + get + { + var size = GetCacheFiles().Sum(file => file.Length); + return $"{App.API.GetTranslation("clearcachefolder")} ({BytesToReadableString(size)})"; + } + } + public string Website => Constant.Website; public string SponsorPage => Constant.SponsorPage; public string ReleaseNotes => _updater.GitHubRepository + "/releases/latest"; @@ -98,6 +107,21 @@ public partial class SettingsPaneAboutViewModel : BaseModel } } + [RelayCommand] + private void AskClearCacheFolderConfirmation() + { + var confirmResult = App.API.ShowMsgBox( + App.API.GetTranslation("clearcachefolderMessage"), + App.API.GetTranslation("clearcachefolder"), + MessageBoxButton.YesNo + ); + + if (confirmResult == MessageBoxResult.Yes) + { + ClearCacheFolder(); + } + } + [RelayCommand] private void OpenSettingsFolder() { @@ -112,7 +136,6 @@ public partial class SettingsPaneAboutViewModel : BaseModel App.API.OpenDirectory(parentFolderPath); } - [RelayCommand] private void OpenLogsFolder() { @@ -147,6 +170,30 @@ public partial class SettingsPaneAboutViewModel : BaseModel return GetLogDir(version).EnumerateFiles("*", SearchOption.AllDirectories).ToList(); } + private void ClearCacheFolder() + { + var cacheDirectory = GetCacheDir(); + var cacheFiles = GetCacheFiles(); + + cacheFiles.ForEach(f => f.Delete()); + + cacheDirectory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly) + .ToList() + .ForEach(dir => dir.Delete(true)); + + OnPropertyChanged(nameof(CacheFolderSize)); + } + + private static DirectoryInfo GetCacheDir() + { + return new DirectoryInfo(DataLocation.CacheDirectory); + } + + private static List GetCacheFiles() + { + return GetCacheDir().EnumerateFiles("*", SearchOption.AllDirectories).ToList(); + } + private static string BytesToReadableString(long bytes) { const int scale = 1024; diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml index 75c513411..f7deee7cf 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml @@ -90,6 +90,10 @@ Margin="0 12 0 0" Icon=""> +