From eaae3b9ee3953c0952780518630b5e8af1a337ab Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Apr 2023 22:06:46 +0800
Subject: [PATCH 1/3] Save settings and image cache when closing main window
---
Flow.Launcher/MainWindow.xaml.cs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs
index 96b114dac..43bd9fd35 100644
--- a/Flow.Launcher/MainWindow.xaml.cs
+++ b/Flow.Launcher/MainWindow.xaml.cs
@@ -69,13 +69,11 @@ namespace Flow.Launcher
_viewModel.ResultCopy(QueryTextBox.SelectedText);
}
}
-
+
private async void OnClosing(object sender, CancelEventArgs e)
{
- _settings.WindowTop = Top;
- _settings.WindowLeft = Left;
_notifyIcon.Visible = false;
- _viewModel.Save();
+ App.API.SaveAppAllSettings();
e.Cancel = true;
await PluginManager.DisposePluginsAsync();
Notification.Uninstall();
From 07c1a0b5a36ddae2aa7c613b81ab0c9735b98691 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Apr 2023 22:58:32 +0800
Subject: [PATCH 2/3] Init ImageCache from disk
---
Flow.Launcher.Infrastructure/Image/ImageCache.cs | 2 +-
Flow.Launcher.Infrastructure/Image/ImageLoader.cs | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/Flow.Launcher.Infrastructure/Image/ImageCache.cs b/Flow.Launcher.Infrastructure/Image/ImageCache.cs
index e7b1f46f7..7a2b57637 100644
--- a/Flow.Launcher.Infrastructure/Image/ImageCache.cs
+++ b/Flow.Launcher.Infrastructure/Image/ImageCache.cs
@@ -28,7 +28,7 @@ namespace Flow.Launcher.Infrastructure.Image
private const int permissibleFactor = 2;
private SemaphoreSlim semaphore = new(1, 1);
- public void Initialization(Dictionary<(string, bool), int> usage)
+ public void Initialize(Dictionary<(string, bool), int> usage)
{
foreach (var key in usage.Keys)
{
diff --git a/Flow.Launcher.Infrastructure/Image/ImageLoader.cs b/Flow.Launcher.Infrastructure/Image/ImageLoader.cs
index 0a51d56f9..fee2c60bd 100644
--- a/Flow.Launcher.Infrastructure/Image/ImageLoader.cs
+++ b/Flow.Launcher.Infrastructure/Image/ImageLoader.cs
@@ -40,6 +40,8 @@ namespace Flow.Launcher.Infrastructure.Image
var usage = LoadStorageToConcurrentDictionary();
+ ImageCache.Initialize(usage.ToDictionary(x => x.Key, x => x.Value));
+
foreach (var icon in new[]
{
Constant.DefaultIcon, Constant.MissingImgIcon
From d9b70e69f327689682cfe7760264d0b05b6b3f11 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Apr 2023 22:38:36 +0800
Subject: [PATCH 3/3] Refactor save settings logic
SettingWindowViewModel.Save() only saves Flow settings
---
Flow.Launcher.Core/Plugin/PluginManager.cs | 3 +++
Flow.Launcher/PublicAPIInstance.cs | 5 ++++-
Flow.Launcher/SettingWindow.xaml.cs | 1 +
Flow.Launcher/ViewModel/SettingWindowViewModel.cs | 4 +++-
4 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs
index 3b4a6e445..f8c9a3f17 100644
--- a/Flow.Launcher.Core/Plugin/PluginManager.cs
+++ b/Flow.Launcher.Core/Plugin/PluginManager.cs
@@ -48,6 +48,9 @@ namespace Flow.Launcher.Core.Plugin
}
}
+ ///
+ /// Save json and ISavable
+ ///
public static void Save()
{
foreach (var plugin in AllPlugins)
diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs
index 80addcbee..636699ad0 100644
--- a/Flow.Launcher/PublicAPIInstance.cs
+++ b/Flow.Launcher/PublicAPIInstance.cs
@@ -77,7 +77,7 @@ namespace Flow.Launcher
public void SaveAppAllSettings()
{
- SavePluginSettings();
+ PluginManager.Save();
_mainVM.Save();
_settingsVM.Save();
ImageLoader.Save();
@@ -158,6 +158,9 @@ namespace Flow.Launcher
private readonly ConcurrentDictionary _pluginJsonStorages = new();
+ ///
+ /// Save plugin settings.
+ ///
public void SavePluginSettings()
{
foreach (var value in _pluginJsonStorages.Values)
diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs
index f39974142..b80208a0c 100644
--- a/Flow.Launcher/SettingWindow.xaml.cs
+++ b/Flow.Launcher/SettingWindow.xaml.cs
@@ -226,6 +226,7 @@ namespace Flow.Launcher
settings.SettingWindowTop = Top;
settings.SettingWindowLeft = Left;
viewModel.Save();
+ API.SavePluginSettings();
}
private void OnCloseExecuted(object sender, ExecutedRoutedEventArgs e)
diff --git a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
index 9bdf2db4d..47a5cd672 100644
--- a/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
+++ b/Flow.Launcher/ViewModel/SettingWindowViewModel.cs
@@ -133,6 +133,9 @@ namespace Flow.Launcher.ViewModel
}
}
+ ///
+ /// Save Flow settings. Plugins settings are not included.
+ ///
public void Save()
{
foreach (var vm in PluginViewModels)
@@ -143,7 +146,6 @@ namespace Flow.Launcher.ViewModel
Settings.PluginSettings.Plugins[id].Priority = vm.Priority;
}
- PluginManager.Save();
_storage.Save();
}