Skip to content

Commit 95b38d2

Browse files
committed
Wait image cache saved before restarting
1 parent b725975 commit 95b38d2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ await Stopwatch.NormalAsync("|ImageLoader.Initialize|Preload images cost", async
6161
});
6262
}
6363

64-
public static async Task Save()
64+
public static async Task SaveAsync()
6565
{
6666
await storageLock.WaitAsync();
6767

@@ -77,6 +77,12 @@ await _storage.SaveAsync(ImageCache.EnumerateEntries()
7777
}
7878
}
7979

80+
public static async Task WaitSaveAsync()
81+
{
82+
await storageLock.WaitAsync();
83+
storageLock.Release();
84+
}
85+
8086
private static async Task<List<(string, bool)>> LoadStorageToConcurrentDictionaryAsync()
8187
{
8288
await storageLock.WaitAsync();

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void ChangeQuery(string query, bool requery = false)
5757
_mainVM.ChangeQueryText(query, requery);
5858
}
5959

60-
public void RestartApp()
60+
public async void RestartApp()
6161
{
6262
_mainVM.Hide();
6363

@@ -66,6 +66,9 @@ public void RestartApp()
6666
// which will cause ungraceful exit
6767
SaveAppAllSettings();
6868

69+
// wait for all image caches to be saved
70+
await ImageLoader.WaitSaveAsync();
71+
6972
// Restart requires Squirrel's Update.exe to be present in the parent folder,
7073
// it is only published from the project's release pipeline. When debugging without it,
7174
// the project may not restart or just terminates. This is expected.
@@ -88,7 +91,7 @@ public void SaveAppAllSettings()
8891
PluginManager.Save();
8992
_mainVM.Save();
9093
_settings.Save();
91-
_ = ImageLoader.Save();
94+
_ = ImageLoader.SaveAsync();
9295
}
9396

9497
public Task ReloadAllPluginData() => PluginManager.ReloadDataAsync();

0 commit comments

Comments
 (0)