mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #623 from Flow-Launcher/GlyphIcon
Add Glyph Icon Support
This commit is contained in:
commit
5b90d08486
4 changed files with 64 additions and 10 deletions
11
Flow.Launcher.Plugin/GlyphInfo.cs
Normal file
11
Flow.Launcher.Plugin/GlyphInfo.cs
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
@ -47,7 +47,15 @@ namespace Flow.Launcher.Plugin
|
||||||
|
|
||||||
public delegate ImageSource IconDelegate();
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,10 @@
|
||||||
<ColumnDefinition Width="0" />
|
<ColumnDefinition Width="0" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Image x:Name="ImageIcon" Width="32" Height="32" HorizontalAlignment="Left"
|
<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 Margin="5 0 5 0" Grid.Column="1" HorizontalAlignment="Stretch">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using Flow.Launcher.Infrastructure.Image;
|
||||||
using Flow.Launcher.Infrastructure.Logger;
|
using Flow.Launcher.Infrastructure.Logger;
|
||||||
using Flow.Launcher.Infrastructure.UserSettings;
|
using Flow.Launcher.Infrastructure.UserSettings;
|
||||||
using Flow.Launcher.Plugin;
|
using Flow.Launcher.Plugin;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Flow.Launcher.ViewModel
|
namespace Flow.Launcher.ViewModel
|
||||||
{
|
{
|
||||||
|
|
@ -16,24 +17,49 @@ namespace Flow.Launcher.ViewModel
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
Result = result;
|
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;
|
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 OpenResultModifiers => Settings.OpenResultModifiers;
|
||||||
|
|
||||||
public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip)
|
public string ShowTitleToolTip => string.IsNullOrEmpty(Result.TitleToolTip)
|
||||||
? Result.Title
|
? Result.Title
|
||||||
: Result.TitleToolTip;
|
: Result.TitleToolTip;
|
||||||
|
|
||||||
public string ShowSubTitleToolTip => string.IsNullOrEmpty(Result.SubTitleToolTip)
|
public string ShowSubTitleToolTip => string.IsNullOrEmpty(Result.SubTitleToolTip)
|
||||||
? Result.SubTitle
|
? Result.SubTitle
|
||||||
: Result.SubTitleToolTip;
|
: Result.SubTitleToolTip;
|
||||||
|
|
||||||
private volatile bool ImageLoaded;
|
private volatile bool ImageLoaded;
|
||||||
|
|
||||||
|
|
@ -48,10 +74,14 @@ namespace Flow.Launcher.ViewModel
|
||||||
ImageLoaded = true;
|
ImageLoaded = true;
|
||||||
_ = LoadImageAsync();
|
_ = LoadImageAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
private set => image = value;
|
private set => image = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GlyphInfo Glyph { get; set; }
|
||||||
|
|
||||||
private async ValueTask LoadImageAsync()
|
private async ValueTask LoadImageAsync()
|
||||||
{
|
{
|
||||||
var imagePath = Result.IcoPath;
|
var imagePath = Result.IcoPath;
|
||||||
|
|
@ -64,7 +94,9 @@ namespace Flow.Launcher.ViewModel
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +106,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
image = ImageLoader.Load(imagePath);
|
image = ImageLoader.Load(imagePath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
// We need to modify the property not field here to trigger the OnPropertyChanged event
|
||||||
Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false);
|
Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue