Skip to content

Commit 8b01249

Browse files
authored
Merge branch 'dev' into sys-plugin-add-copy-text
2 parents 29c9fd6 + 5f46ee7 commit 8b01249

File tree

8 files changed

+39
-17
lines changed

8 files changed

+39
-17
lines changed

Flow.Launcher.Infrastructure/Constant.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static class Constant
3131
public static readonly string ErrorIcon = Path.Combine(ImagesDirectory, "app_error.png");
3232
public static readonly string MissingImgIcon = Path.Combine(ImagesDirectory, "app_missing_img.png");
3333
public static readonly string LoadingImgIcon = Path.Combine(ImagesDirectory, "loading.png");
34+
public static readonly string ImageIcon = Path.Combine(ImagesDirectory, "image.png");
3435

3536
public static string PythonPath;
3637
public static string NodePath;

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class ImageLoader
2222
private static readonly ConcurrentDictionary<string, string> GuidToKey = new();
2323
private static IImageHashGenerator _hashGenerator;
2424
private static readonly bool EnableImageHash = true;
25+
public static ImageSource Image { get; } = new BitmapImage(new Uri(Constant.ImageIcon));
2526
public static ImageSource MissingImage { get; } = new BitmapImage(new Uri(Constant.MissingImgIcon));
2627
public static ImageSource LoadingImage { get; } = new BitmapImage(new Uri(Constant.LoadingImgIcon));
2728
public const int SmallIconSize = 64;
@@ -139,7 +140,7 @@ private static async ValueTask<ImageResult> LoadInternalAsync(string path, bool
139140
return new ImageResult(image, ImageType.ImageFile);
140141
}
141142

142-
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
143+
if (path.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
143144
{
144145
var imageSource = new BitmapImage(new Uri(path));
145146
imageSource.Freeze();
@@ -215,8 +216,16 @@ private static ImageResult GetThumbnailResult(ref string path, bool loadFullImag
215216
type = ImageType.ImageFile;
216217
if (loadFullImage)
217218
{
218-
image = LoadFullImage(path);
219-
type = ImageType.FullImageFile;
219+
try
220+
{
221+
image = LoadFullImage(path);
222+
type = ImageType.FullImageFile;
223+
}
224+
catch (NotSupportedException)
225+
{
226+
image = Image;
227+
type = ImageType.Error;
228+
}
220229
}
221230
else
222231
{

Flow.Launcher.Plugin/Result.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public string IcoPath
7070
&& !string.IsNullOrEmpty(PluginDirectory)
7171
&& !Path.IsPathRooted(value)
7272
&& !value.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
73-
&& !value.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
73+
&& !value.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
74+
&& !value.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
7475
{
7576
_icoPath = Path.Combine(PluginDirectory, value);
7677
}

Flow.Launcher/Images/image.png

435 Bytes
Loading

Flow.Launcher/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
VerticalAlignment="Center"
309309
Panel.ZIndex="2"
310310
RenderOptions.BitmapScalingMode="HighQuality"
311-
Source="{Binding PluginIconPath}"
311+
Source="{Binding PluginIconSource}"
312312
Stretch="Uniform"
313313
Style="{DynamicResource PluginActivationIcon}" />
314314
<Canvas Style="{DynamicResource SearchIconPosition}">

Flow.Launcher/Storage/TopMostRecord.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Concurrent;
2+
using System.Collections.Generic;
23
using System.Text.Json.Serialization;
34
using Flow.Launcher.Plugin;
45

56
namespace Flow.Launcher.Storage
67
{
7-
// todo this class is not thread safe.... but used from multiple threads.
88
public class TopMostRecord
99
{
1010
[JsonInclude]
11-
public Dictionary<string, Record> records { get; private set; } = new Dictionary<string, Record>();
11+
public ConcurrentDictionary<string, Record> records { get; private set; } = new ConcurrentDictionary<string, Record>();
1212

1313
internal bool IsTopMost(Result result)
1414
{
15-
if (records.Count == 0 || !records.ContainsKey(result.OriginQuery.RawQuery))
15+
if (records.IsEmpty || result.OriginQuery == null ||
16+
!records.TryGetValue(result.OriginQuery.RawQuery, out var value))
1617
{
1718
return false;
1819
}
1920

2021
// since this dictionary should be very small (or empty) going over it should be pretty fast.
21-
return records[result.OriginQuery.RawQuery].Equals(result);
22+
return value.Equals(result);
2223
}
2324

2425
internal void Remove(Result result)
2526
{
26-
records.Remove(result.OriginQuery.RawQuery);
27+
records.Remove(result.OriginQuery.RawQuery, out _);
2728
}
2829

2930
internal void AddOrUpdate(Result result)
@@ -34,17 +35,15 @@ internal void AddOrUpdate(Result result)
3435
Title = result.Title,
3536
SubTitle = result.SubTitle
3637
};
37-
records[result.OriginQuery.RawQuery] = record;
38-
38+
records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
3939
}
4040

4141
public void Load(Dictionary<string, Record> dictionary)
4242
{
43-
records = dictionary;
43+
records = new ConcurrentDictionary<string, Record>(dictionary);
4444
}
4545
}
4646

47-
4847
public class Record
4948
{
5049
public string Title { get; set; }

Flow.Launcher/Storage/UserSelectedRecord.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ private static int GenerateResultHashCode(Result result)
5151

5252
private static int GenerateQueryAndResultHashCode(Query query, Result result)
5353
{
54+
if (query == null)
55+
{
56+
return GenerateResultHashCode(result);
57+
}
58+
5459
int hashcode = GenerateStaticHashCode(query.ActionKeyword);
5560
hashcode = GenerateStaticHashCode(query.Search, hashcode);
5661
hashcode = GenerateStaticHashCode(result.Title, hashcode);
@@ -101,4 +106,4 @@ public int GetSelectedCount(Result result)
101106
return selectedCount;
102107
}
103108
}
104-
}
109+
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading;
@@ -23,6 +23,8 @@
2323
using System.Globalization;
2424
using System.Windows.Input;
2525
using System.ComponentModel;
26+
using Flow.Launcher.Infrastructure.Image;
27+
using System.Windows.Media;
2628

2729
namespace Flow.Launcher.ViewModel
2830
{
@@ -722,6 +724,8 @@ public double ResultSubItemFontSize
722724
set => Settings.ResultSubItemFontSize = value;
723725
}
724726

727+
public ImageSource PluginIconSource { get; private set; } = null;
728+
725729
public string PluginIconPath { get; set; } = null;
726730

727731
public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
@@ -1066,6 +1070,7 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
10661070
Results.Clear();
10671071
Results.Visibility = Visibility.Collapsed;
10681072
PluginIconPath = null;
1073+
PluginIconSource = null;
10691074
SearchIconVisibility = Visibility.Visible;
10701075
return;
10711076
}
@@ -1099,11 +1104,13 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
10991104
if (plugins.Count == 1)
11001105
{
11011106
PluginIconPath = plugins.Single().Metadata.IcoPath;
1107+
PluginIconSource = await ImageLoader.LoadAsync(PluginIconPath);
11021108
SearchIconVisibility = Visibility.Hidden;
11031109
}
11041110
else
11051111
{
11061112
PluginIconPath = null;
1113+
PluginIconSource = null;
11071114
SearchIconVisibility = Visibility.Visible;
11081115
}
11091116

0 commit comments

Comments
 (0)