Skip to content

Commit 5ec474c

Browse files
Merge branch 'dev' into quicklook
2 parents f4f519b + 8972d9e commit 5ec474c

File tree

19 files changed

+194
-144
lines changed

19 files changed

+194
-144
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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,22 @@
344344
<ContentControl>
345345
<ContentControl.Style>
346346
<Style TargetType="ContentControl">
347-
<Setter Property="Visibility" Value="Collapsed" />
347+
<Setter Property="Visibility" Value="Visible" />
348348
<Style.Triggers>
349+
<MultiDataTrigger>
350+
<MultiDataTrigger.Conditions>
351+
<Condition Binding="{Binding ElementName=ResultListBox, Path=Items.Count}" Value="0" />
352+
<Condition Binding="{Binding ElementName=ContextMenu, Path=Visibility}" Value="Collapsed" />
353+
<Condition Binding="{Binding ElementName=History, Path=Visibility}" Value="Collapsed" />
354+
</MultiDataTrigger.Conditions>
355+
<MultiDataTrigger.Setters>
356+
<Setter Property="Visibility" Value="Collapsed" />
357+
<Setter Property="Margin" Value="0" />
358+
<Setter Property="Height" Value="0" />
359+
</MultiDataTrigger.Setters>
360+
</MultiDataTrigger>
361+
</Style.Triggers>
362+
<!--<Style.Triggers>
349363
<DataTrigger Binding="{Binding ElementName=ResultListBox, Path=Visibility}" Value="Visible">
350364
<Setter Property="Visibility" Value="Visible" />
351365
</DataTrigger>
@@ -355,7 +369,7 @@
355369
<DataTrigger Binding="{Binding ElementName=History, Path=Visibility}" Value="Visible">
356370
<Setter Property="Visibility" Value="Visible" />
357371
</DataTrigger>
358-
</Style.Triggers>
372+
</Style.Triggers>-->
359373
</Style>
360374
</ContentControl.Style>
361375
<Rectangle
@@ -368,7 +382,7 @@
368382
</Grid>
369383
<Grid>
370384
<Grid.ColumnDefinitions>
371-
<ColumnDefinition Width="*" MinWidth="100" />
385+
<ColumnDefinition Width="*" MinWidth="80" />
372386
<ColumnDefinition Width="Auto" />
373387
<ColumnDefinition Width="0.85*" MinWidth="244" />
374388
</Grid.ColumnDefinitions>
@@ -439,6 +453,7 @@
439453
Style="{DynamicResource PreviewArea}"
440454
Visibility="{Binding InternalPreviewVisible, Converter={StaticResource BoolToVisibilityConverter}}">
441455
<Border
456+
MinHeight="380"
442457
d:DataContext="{d:DesignInstance vm:ResultViewModel}"
443458
DataContext="{Binding SelectedItem, ElementName=ResultListBox}"
444459
Style="{DynamicResource PreviewBorderStyle}"
@@ -514,6 +529,8 @@
514529
</Grid>
515530
</Border>
516531
<Border
532+
MinHeight="380"
533+
MaxHeight="{Binding ElementName=ResultListBox, Path=ActualHeight}"
517534
d:DataContext="{d:DesignInstance vm:ResultViewModel}"
518535
DataContext="{Binding SelectedItem, ElementName=ResultListBox}"
519536
Style="{DynamicResource PreviewBorderStyle}"

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,26 @@ public MainWindow()
8585

8686
private const int WM_ENTERSIZEMOVE = 0x0231;
8787
private const int WM_EXITSIZEMOVE = 0x0232;
88+
private int _initialWidth;
89+
private int _initialHeight;
8890
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
8991
{
9092
if (msg == WM_ENTERSIZEMOVE)
9193
{
94+
_initialWidth = (int)Width;
95+
_initialHeight = (int)Height;
9296
handled = true;
9397
}
9498
if (msg == WM_EXITSIZEMOVE)
9599
{
96-
OnResizeEnd();
100+
if ( _initialHeight != (int)Height)
101+
{
102+
OnResizeEnd();
103+
}
104+
if (_initialWidth != (int)Width)
105+
{
106+
FlowMainWindow.SizeToContent = SizeToContent.Height;
107+
}
97108
handled = true;
98109
}
99110
return IntPtr.Zero;
@@ -120,9 +131,8 @@ private void OnResizeEnd()
120131
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
121132
}
122133
}
123-
124-
_viewModel.MainWindowWidth = Width;
125134
FlowMainWindow.SizeToContent = SizeToContent.Height;
135+
_viewModel.MainWindowWidth = Width;
126136
}
127137

128138
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
@@ -169,7 +179,6 @@ private void OnLoaded(object sender, RoutedEventArgs _)
169179
{
170180
// MouseEventHandler
171181
PreviewMouseMove += MainPreviewMouseMove;
172-
173182
CheckFirstLaunch();
174183
HideStartup();
175184
// show notify icon when flowlauncher is hidden
@@ -332,11 +341,10 @@ private void InitializeNotifyIcon()
332341
_notifyIcon = new NotifyIcon
333342
{
334343
Text = Infrastructure.Constant.FlowLauncherFullName,
335-
Icon = Properties.Resources.app,
344+
Icon = Constant.Version == "1.0.0" ? Properties.Resources.dev : Properties.Resources.app,
336345
Visible = !_settings.HideNotifyIcon
337346
};
338347

339-
340348
var openIcon = new FontIcon
341349
{
342350
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.

0 commit comments

Comments
 (0)