Skip to content

Commit 93256fa

Browse files
committed
Images: Remove preloading & use lowercase paths for caching
1 parent f887cd1 commit 93256fa

File tree

3 files changed

+4
-47
lines changed

3 files changed

+4
-47
lines changed

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,55 +37,16 @@ public static async Task InitializeAsync()
3737
_storage = new BinaryStorage<List<(string, bool)>>("Image");
3838
_hashGenerator = new ImageHashGenerator();
3939

40-
var usage = await LoadStorageToConcurrentDictionaryAsync();
41-
_storage.ClearData();
42-
43-
ImageCache.Initialize(usage);
40+
// Even though we no longer do image preloading and thus don't need _storage,
41+
// for some reason MemoryPackSerializer exceptions appear when this is removed
42+
await LoadStorageToConcurrentDictionaryAsync();
4443

4544
foreach (var icon in new[] { Constant.DefaultIcon, Constant.MissingImgIcon })
4645
{
4746
ImageSource img = new BitmapImage(new Uri(icon));
4847
img.Freeze();
4948
ImageCache[icon, false] = img;
5049
}
51-
52-
_ = Task.Run(async () =>
53-
{
54-
await Stopwatch.InfoAsync(ClassName, "Preload images cost", async () =>
55-
{
56-
foreach (var (path, isFullImage) in usage)
57-
{
58-
await LoadAsync(path, isFullImage);
59-
}
60-
});
61-
Log.Info(ClassName, $"Number of preload images is <{ImageCache.CacheSize()}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
62-
});
63-
}
64-
65-
public static async Task SaveAsync()
66-
{
67-
await storageLock.WaitAsync();
68-
69-
try
70-
{
71-
await _storage.SaveAsync(ImageCache.EnumerateEntries()
72-
.Select(x => x.Key)
73-
.ToList());
74-
}
75-
catch (System.Exception e)
76-
{
77-
Log.Exception(ClassName, "Failed to save image cache to file", e);
78-
}
79-
finally
80-
{
81-
storageLock.Release();
82-
}
83-
}
84-
85-
public static async Task WaitSaveAsync()
86-
{
87-
await storageLock.WaitAsync();
88-
storageLock.Release();
8950
}
9051

9152
private static async Task<List<(string, bool)>> LoadStorageToConcurrentDictionaryAsync()
@@ -276,6 +237,7 @@ public static bool TryGetValue(string path, bool loadFullImage, out ImageSource
276237

277238
public static async ValueTask<ImageSource> LoadAsync(string path, bool loadFullImage = false, bool cacheImage = true)
278239
{
240+
path = path.ToLowerInvariant();
279241
var imageResult = await LoadInternalAsync(path, loadFullImage);
280242

281243
var img = imageResult.ImageSource;

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ private async void OnClosing(object sender, CancelEventArgs e)
277277
_notifyIcon.Visible = false;
278278
App.API.SaveAppAllSettings();
279279
e.Cancel = true;
280-
await ImageLoader.WaitSaveAsync();
281280
await PluginManager.DisposePluginsAsync();
282281
Notification.Uninstall();
283282
// After plugins are all disposed, we shutdown application to close app

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ public async void RestartApp()
7676
// UpdateManager.RestartApp() will call Environment.Exit(0)
7777
// which will cause ungraceful exit
7878
SaveAppAllSettings();
79-
80-
// Wait for all image caches to be saved before restarting
81-
await ImageLoader.WaitSaveAsync();
8279
}
8380

8481
public void ShowMainWindow() => _mainVM.Show();
@@ -103,7 +100,6 @@ public void SaveAppAllSettings()
103100
PluginManager.Save();
104101
_mainVM.Save();
105102
}
106-
_ = ImageLoader.SaveAsync();
107103
}
108104

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

0 commit comments

Comments
 (0)