Skip to content

Commit 40dbc55

Browse files
authored
Merge branch 'dev' into 240529-FixPreviewFit
2 parents 29be504 + 870c2ba commit 40dbc55

20 files changed

+223
-171
lines changed

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<ItemGroup>
5151
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
52-
<PackageReference Include="FastCache.Cached" Version="1.8.2" />
52+
<PackageReference Include="BitFaster.Caching" Version="2.5.0" />
5353
<PackageReference Include="Fody" Version="6.5.5">
5454
<PrivateAssets>all</PrivateAssets>
5555
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Flow.Launcher.Infrastructure/Image/ImageCache.cs

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,81 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Threading;
6+
using System.Threading.Tasks;
67
using System.Windows.Media;
7-
using FastCache;
8-
using FastCache.Services;
8+
using BitFaster.Caching.Lfu;
99

1010
namespace Flow.Launcher.Infrastructure.Image
1111
{
12-
public class ImageUsage
13-
{
14-
public int usage;
15-
public ImageSource imageSource;
16-
17-
public ImageUsage(int usage, ImageSource image)
18-
{
19-
this.usage = usage;
20-
imageSource = image;
21-
}
22-
}
23-
2412
public class ImageCache
2513
{
2614
private const int MaxCached = 150;
2715

28-
public void Initialize(Dictionary<(string, bool), int> usage)
16+
private ConcurrentLfu<(string, bool), ImageSource> CacheManager { get; set; } = new(MaxCached);
17+
18+
public void Initialize(IEnumerable<(string, bool)> usage)
2919
{
30-
foreach (var key in usage.Keys)
20+
foreach (var key in usage)
3121
{
32-
Cached<ImageUsage>.Save(key, new ImageUsage(usage[key], null), TimeSpan.MaxValue, MaxCached);
22+
CacheManager.AddOrUpdate(key, null);
3323
}
3424
}
3525

3626
public ImageSource this[string path, bool isFullImage = false]
3727
{
3828
get
3929
{
40-
if (!Cached<ImageUsage>.TryGet((path, isFullImage), out var value))
41-
{
42-
return null;
43-
}
44-
45-
value.Value.usage++;
46-
return value.Value.imageSource;
30+
return CacheManager.TryGet((path, isFullImage), out var value) ? value : null;
4731
}
4832
set
4933
{
50-
if (Cached<ImageUsage>.TryGet((path, isFullImage), out var cached))
51-
{
52-
cached.Value.imageSource = value;
53-
cached.Value.usage++;
54-
}
55-
56-
Cached<ImageUsage>.Save((path, isFullImage), new ImageUsage(0, value), TimeSpan.MaxValue,
57-
MaxCached);
34+
CacheManager.AddOrUpdate((path, isFullImage), value);
5835
}
5936
}
6037

38+
public async ValueTask<ImageSource> GetOrAddAsync(string key,
39+
Func<(string, bool), Task<ImageSource>> valueFactory,
40+
bool isFullImage = false)
41+
{
42+
return await CacheManager.GetOrAddAsync((key, isFullImage), valueFactory);
43+
}
44+
6145
public bool ContainsKey(string key, bool isFullImage)
6246
{
63-
return Cached<ImageUsage>.TryGet((key, isFullImage), out _);
47+
return CacheManager.TryGet((key, isFullImage), out _);
6448
}
6549

6650
public bool TryGetValue(string key, bool isFullImage, out ImageSource image)
6751
{
68-
if (Cached<ImageUsage>.TryGet((key, isFullImage), out var value))
52+
if (CacheManager.TryGet((key, isFullImage), out var value))
6953
{
70-
image = value.Value.imageSource;
71-
value.Value.usage++;
54+
image = value;
7255
return image != null;
7356
}
7457

58+
7559
image = null;
7660
return false;
7761
}
7862

7963
public int CacheSize()
8064
{
81-
return CacheManager.TotalCount<(string, bool), ImageUsage>();
65+
return CacheManager.Count;
8266
}
8367

8468
/// <summary>
8569
/// return the number of unique images in the cache (by reference not by checking images content)
8670
/// </summary>
8771
public int UniqueImagesInCache()
8872
{
89-
return CacheManager.EnumerateEntries<(string, bool), ImageUsage>().Select(x => x.Value.imageSource)
73+
return CacheManager.Select(x => x.Value)
9074
.Distinct()
9175
.Count();
9276
}
9377

94-
public IEnumerable<Cached<(string, bool), ImageUsage>> EnumerateEntries()
78+
public IEnumerable<KeyValuePair<(string, bool), ImageSource>> EnumerateEntries()
9579
{
96-
return CacheManager.EnumerateEntries<(string, bool), ImageUsage>();
80+
return CacheManager;
9781
}
9882
}
9983
}

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using System.Windows.Documents;
89
using System.Windows.Media;
910
using System.Windows.Media.Imaging;
1011
using Flow.Launcher.Infrastructure.Logger;
@@ -17,7 +18,7 @@ public static class ImageLoader
1718
{
1819
private static readonly ImageCache ImageCache = new();
1920
private static SemaphoreSlim storageLock { get; } = new SemaphoreSlim(1, 1);
20-
private static BinaryStorage<Dictionary<(string, bool), int>> _storage;
21+
private static BinaryStorage<List<(string, bool)>> _storage;
2122
private static readonly ConcurrentDictionary<string, string> GuidToKey = new();
2223
private static IImageHashGenerator _hashGenerator;
2324
private static readonly bool EnableImageHash = true;
@@ -31,12 +32,12 @@ public static class ImageLoader
3132

3233
public static async Task InitializeAsync()
3334
{
34-
_storage = new BinaryStorage<Dictionary<(string, bool), int>>("Image");
35+
_storage = new BinaryStorage<List<(string, bool)>>("Image");
3536
_hashGenerator = new ImageHashGenerator();
3637

3738
var usage = await LoadStorageToConcurrentDictionaryAsync();
3839

39-
ImageCache.Initialize(usage.ToDictionary(x => x.Key, x => x.Value));
40+
ImageCache.Initialize(usage);
4041

4142
foreach (var icon in new[] { Constant.DefaultIcon, Constant.MissingImgIcon })
4243
{
@@ -49,7 +50,7 @@ public static async Task InitializeAsync()
4950
{
5051
await Stopwatch.NormalAsync("|ImageLoader.Initialize|Preload images cost", async () =>
5152
{
52-
foreach (var ((path, isFullImage), _) in usage)
53+
foreach (var (path, isFullImage) in usage)
5354
{
5455
await LoadAsync(path, isFullImage);
5556
}
@@ -66,24 +67,21 @@ public static async Task Save()
6667
try
6768
{
6869
await _storage.SaveAsync(ImageCache.EnumerateEntries()
69-
.ToDictionary(
70-
x => x.Key,
71-
x => x.Value.usage));
70+
.Select(x => x.Key)
71+
.ToList());
7272
}
7373
finally
7474
{
7575
storageLock.Release();
7676
}
7777
}
7878

79-
private static async Task<ConcurrentDictionary<(string, bool), int>> LoadStorageToConcurrentDictionaryAsync()
79+
private static async Task<List<(string, bool)>> LoadStorageToConcurrentDictionaryAsync()
8080
{
8181
await storageLock.WaitAsync();
8282
try
8383
{
84-
var loaded = await _storage.TryLoadAsync(new Dictionary<(string, bool), int>());
85-
86-
return new ConcurrentDictionary<(string, bool), int>(loaded);
84+
return await _storage.TryLoadAsync(new List<(string, bool)>());
8785
}
8886
finally
8987
{

Flow.Launcher.Infrastructure/Storage/BinaryStorage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private async ValueTask<T> DeserializeAsync(Stream stream, T defaultData)
6767
}
6868
catch (System.Exception e)
6969
{
70-
Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
70+
// Log.Exception($"|BinaryStorage.Deserialize|Deserialize error for file <{FilePath}>", e);
7171
return defaultData;
7272
}
7373
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public string Theme
8888

8989
public double SettingWindowWidth { get; set; } = 1000;
9090
public double SettingWindowHeight { get; set; } = 700;
91-
public double SettingWindowTop { get; set; }
92-
public double SettingWindowLeft { get; set; }
91+
public double? SettingWindowTop { get; set; } = null;
92+
public double? SettingWindowLeft { get; set; } = null;
9393
public System.Windows.WindowState SettingWindowState { get; set; } = WindowState.Normal;
9494

9595
public int CustomExplorerIndex { get; set; } = 0;

Flow.Launcher/Flow.Launcher.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@
111111
</Content>
112112
</ItemGroup>
113113

114+
<ItemGroup>
115+
<None Update="Resources\dev.ico">
116+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
117+
</None>
118+
</ItemGroup>
119+
114120
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
115121
<Exec Command="taskkill /f /fi &quot;IMAGENAME eq Flow.Launcher.exe&quot;" />
116122
</Target>

Flow.Launcher/Images/dev.ico

4.19 KB
Binary file not shown.

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,10 @@ private void InitializeNotifyIcon()
341341
_notifyIcon = new NotifyIcon
342342
{
343343
Text = Infrastructure.Constant.FlowLauncherFullName,
344-
Icon = Properties.Resources.app,
344+
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
345345
Visible = !_settings.HideNotifyIcon
346346
};
347347

348-
349348
var openIcon = new FontIcon
350349
{
351350
Glyph = "\ue71e"

Flow.Launcher/Properties/Resources.Designer.cs

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Flow.Launcher/Properties/Resources.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,18 @@
112112
<value>2.0</value>
113113
</resheader>
114114
<resheader name="reader">
115-
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116116
</resheader>
117117
<resheader name="writer">
118-
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
120+
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121121
<data name="app" type="System.Resources.ResXFileRef, System.Windows.Forms">
122122
<value>..\Resources\app.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123123
</data>
124+
<data name="dev" type="System.Resources.ResXFileRef, System.Windows.Forms">
125+
<value>..\Images\dev.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126+
</data>
124127
<data name="gamemode" type="System.Resources.ResXFileRef, System.Windows.Forms">
125128
<value>..\Images\gamemode.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126129
</data>

0 commit comments

Comments
 (0)