Skip to content

Commit 0fddb84

Browse files
committed
Add wallpaper path in cache dictionary
1 parent ff45f5f commit 0fddb84

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Flow.Launcher/Helper/WallpaperPathRetrieval.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class WallpaperPathRetrieval
1616
{
1717
private static readonly int MAX_PATH = 260;
1818

19-
private static readonly Dictionary<DateTime, ImageBrush> wallpaperCache = new();
19+
private static readonly Dictionary<(string, DateTime), ImageBrush> wallpaperCache = new();
2020

2121
public static Brush GetWallpaperBrush()
2222
{
@@ -26,20 +26,20 @@ public static Brush GetWallpaperBrush()
2626
return Application.Current.Dispatcher.Invoke(GetWallpaperBrush);
2727
}
2828

29-
var wallpaper = GetWallpaperPath();
30-
if (wallpaper is not null && File.Exists(wallpaper))
29+
var wallpaperPath = GetWallpaperPath();
30+
if (wallpaperPath is not null && File.Exists(wallpaperPath))
3131
{
32-
// Since the wallpaper file name is the same (TranscodedWallpaper),
33-
// we need to use the last modified date to differentiate them
34-
var dateModified = File.GetLastWriteTime(wallpaper);
35-
wallpaperCache.TryGetValue(dateModified, out var cachedWallpaper);
32+
// Since the wallpaper file name can be the same (TranscodedWallpaper),
33+
// we need to add the last modified date to differentiate them
34+
var dateModified = File.GetLastWriteTime(wallpaperPath);
35+
wallpaperCache.TryGetValue((wallpaperPath, dateModified), out var cachedWallpaper);
3636
if (cachedWallpaper != null)
3737
{
3838
return cachedWallpaper;
3939
}
4040

4141
// We should not dispose the memory stream since the bitmap is still in use
42-
var memStream = new MemoryStream(File.ReadAllBytes(wallpaper));
42+
var memStream = new MemoryStream(File.ReadAllBytes(wallpaperPath));
4343
var bitmap = new BitmapImage();
4444
bitmap.BeginInit();
4545
bitmap.StreamSource = memStream;
@@ -49,7 +49,7 @@ public static Brush GetWallpaperBrush()
4949
bitmap.Freeze(); // Make the bitmap thread-safe
5050
var wallpaperBrush = new ImageBrush(bitmap) { Stretch = Stretch.UniformToFill };
5151
wallpaperBrush.Freeze(); // Make the brush thread-safe
52-
wallpaperCache.Add(dateModified, wallpaperBrush);
52+
wallpaperCache.Add((wallpaperPath, dateModified), wallpaperBrush);
5353
return wallpaperBrush;
5454
}
5555

0 commit comments

Comments
 (0)