Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Flow.Launcher.Infrastructure/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static class Constant
public static readonly string ErrorIcon = Path.Combine(ImagesDirectory, "app_error.png");
public static readonly string MissingImgIcon = Path.Combine(ImagesDirectory, "app_missing_img.png");
public static readonly string LoadingImgIcon = Path.Combine(ImagesDirectory, "loading.png");
public static readonly string ImageIcon = Path.Combine(ImagesDirectory, "image.png");

public static string PythonPath;
public static string NodePath;
Expand Down
13 changes: 11 additions & 2 deletions Flow.Launcher.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class ImageLoader
private static readonly ConcurrentDictionary<string, string> GuidToKey = new();
private static IImageHashGenerator _hashGenerator;
private static readonly bool EnableImageHash = true;
public static ImageSource Image { get; } = new BitmapImage(new Uri(Constant.ImageIcon));
public static ImageSource MissingImage { get; } = new BitmapImage(new Uri(Constant.MissingImgIcon));
public static ImageSource LoadingImage { get; } = new BitmapImage(new Uri(Constant.LoadingImgIcon));
public const int SmallIconSize = 64;
Expand Down Expand Up @@ -215,8 +216,16 @@ private static ImageResult GetThumbnailResult(ref string path, bool loadFullImag
type = ImageType.ImageFile;
if (loadFullImage)
{
image = LoadFullImage(path);
type = ImageType.FullImageFile;
try
{
image = LoadFullImage(path);
type = ImageType.FullImageFile;
}
catch (NotSupportedException)
{
image = Image;
type = ImageType.Error;
}
}
else
{
Expand Down
Binary file modified Flow.Launcher/Images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Flow.Launcher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
VerticalAlignment="Center"
Panel.ZIndex="2"
RenderOptions.BitmapScalingMode="HighQuality"
Source="{Binding PluginIconPath}"
Source="{Binding PluginIconSource}"
Stretch="Uniform"
Style="{DynamicResource PluginActivationIcon}" />
<Canvas Style="{DynamicResource SearchIconPosition}">
Expand Down
19 changes: 9 additions & 10 deletions Flow.Launcher/Storage/TopMostRecord.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin;

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

internal bool IsTopMost(Result result)
{
if (records.Count == 0 || !records.ContainsKey(result.OriginQuery.RawQuery))
if (records.IsEmpty || result.OriginQuery == null ||
!records.TryGetValue(result.OriginQuery.RawQuery, out var value))
{
return false;
}

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

internal void Remove(Result result)
{
records.Remove(result.OriginQuery.RawQuery);
records.Remove(result.OriginQuery.RawQuery, out _);
}

internal void AddOrUpdate(Result result)
Expand All @@ -34,17 +35,15 @@ internal void AddOrUpdate(Result result)
Title = result.Title,
SubTitle = result.SubTitle
};
records[result.OriginQuery.RawQuery] = record;

records.AddOrUpdate(result.OriginQuery.RawQuery, record, (key, oldValue) => record);
}

public void Load(Dictionary<string, Record> dictionary)
{
records = dictionary;
records = new ConcurrentDictionary<string, Record>(dictionary);
}
}


public class Record
{
public string Title { get; set; }
Expand Down
7 changes: 6 additions & 1 deletion Flow.Launcher/Storage/UserSelectedRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ private static int GenerateResultHashCode(Result result)

private static int GenerateQueryAndResultHashCode(Query query, Result result)
{
if (query == null)
{
return GenerateResultHashCode(result);
}

int hashcode = GenerateStaticHashCode(query.ActionKeyword);
hashcode = GenerateStaticHashCode(query.Search, hashcode);
hashcode = GenerateStaticHashCode(result.Title, hashcode);
Expand Down Expand Up @@ -101,4 +106,4 @@ public int GetSelectedCount(Result result)
return selectedCount;
}
}
}
}
9 changes: 8 additions & 1 deletion Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand All @@ -23,6 +23,8 @@
using System.Globalization;
using System.Windows.Input;
using System.ComponentModel;
using Flow.Launcher.Infrastructure.Image;
using System.Windows.Media;

namespace Flow.Launcher.ViewModel
{
Expand Down Expand Up @@ -722,6 +724,8 @@ public double ResultSubItemFontSize
set => Settings.ResultSubItemFontSize = value;
}

public ImageSource PluginIconSource { get; private set; } = null;

public string PluginIconPath { get; set; } = null;

public string OpenResultCommandModifiers => Settings.OpenResultModifiers;
Expand Down Expand Up @@ -1066,6 +1070,7 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
Results.Clear();
Results.Visibility = Visibility.Collapsed;
PluginIconPath = null;
PluginIconSource = null;
SearchIconVisibility = Visibility.Visible;
return;
}
Expand Down Expand Up @@ -1099,11 +1104,13 @@ private async void QueryResults(bool isReQuery = false, bool reSelect = true)
if (plugins.Count == 1)
{
PluginIconPath = plugins.Single().Metadata.IcoPath;
PluginIconSource = await ImageLoader.LoadAsync(PluginIconPath);
SearchIconVisibility = Visibility.Hidden;
}
else
{
PluginIconPath = null;
PluginIconSource = null;
SearchIconVisibility = Visibility.Visible;
}

Expand Down
Loading