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
11 changes: 11 additions & 0 deletions Flow.Launcher.Plugin/GlyphInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Flow.Launcher.Plugin
{
public record GlyphInfo(string FontFamily, string Glyph);
}
10 changes: 9 additions & 1 deletion Flow.Launcher.Plugin/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ public string IcoPath

public delegate ImageSource IconDelegate();

public IconDelegate Icon;
/// <summary>
/// Delegate to Get Image Source
/// </summary>
public IconDelegate Icon { get; set; }

/// <summary>
/// Information for Glyph Icon
/// </summary>
public GlyphInfo Glyph { get; init; }


/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion Flow.Launcher/ResultListBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
<ColumnDefinition Width="0" />
</Grid.ColumnDefinitions>
<Image x:Name="ImageIcon" Width="32" Height="32" HorizontalAlignment="Left"
Source="{Binding Image}" />
Source="{Binding Image}" Visibility="{Binding ShowIcon}" />
<TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center"
Text="{Binding Glyph.Glyph}" FontFamily="{Binding Glyph.FontFamily}" FontSize="24"
Visibility="{Binding ShowGlyph}"/>
<Grid Margin="5 0 5 0" Grid.Column="1" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition />
Expand Down
48 changes: 40 additions & 8 deletions Flow.Launcher/ViewModel/ResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using System.IO;

namespace Flow.Launcher.ViewModel
{
Expand All @@ -16,24 +17,49 @@ public ResultViewModel(Result result, Settings settings)
if (result != null)
{
Result = result;

if (Result.Glyph is { FontFamily: not null } glyph)
{
// Checks if it's a system installed font, which does not require path to be provided.
if (glyph.FontFamily.EndsWith(".ttf") || glyph.FontFamily.EndsWith(".otf"))
{
var fontPath = Result.Glyph.FontFamily;
Glyph = Path.IsPathRooted(fontPath)
? Result.Glyph
: Result.Glyph with
{
FontFamily = Path.Combine(Result.PluginDirectory, fontPath)
};
}
else
{
Glyph = glyph;
}
}
}

Settings = settings;
}

public Settings Settings { get; private set; }
private Settings Settings { get; }

public Visibility ShowOpenResultHotkey =>
Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Hidden;

public Visibility ShowOpenResultHotkey => Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Hidden;
public Visibility ShowIcon => Result.IcoPath != null || Result.Icon is not null || Glyph == null
? Visibility.Visible
: Visibility.Hidden;

public Visibility ShowGlyph => Glyph is not null ? Visibility.Visible : Visibility.Hidden;
public string OpenResultModifiers => Settings.OpenResultModifiers;

public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip)
? Result.Title
: Result.TitleToolTip;
? Result.Title
: Result.TitleToolTip;

public string ShowSubTitleToolTip => string.IsNullOrEmpty(Result.SubTitleToolTip)
? Result.SubTitle
: Result.SubTitleToolTip;
? Result.SubTitle
: Result.SubTitleToolTip;

private volatile bool ImageLoaded;

Expand All @@ -48,10 +74,14 @@ public ImageSource Image
ImageLoaded = true;
_ = LoadImageAsync();
}

return image;
}
private set => image = value;
}

public GlyphInfo Glyph { get; set; }

private async ValueTask LoadImageAsync()
{
var imagePath = Result.IcoPath;
Expand All @@ -64,7 +94,9 @@ private async ValueTask LoadImageAsync()
}
catch (Exception e)
{
Log.Exception($"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e);
Log.Exception(
$"|ResultViewModel.Image|IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>",
e);
}
}

Expand All @@ -74,7 +106,7 @@ private async ValueTask LoadImageAsync()
image = ImageLoader.Load(imagePath);
return;
}

// We need to modify the property not field here to trigger the OnPropertyChanged event
Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false);
}
Expand Down