update to use IcoAbsoluteLocalPath

This commit is contained in:
Jeremy 2025-12-26 21:37:30 +11:00
parent 7958b17968
commit d78d313372
3 changed files with 33 additions and 25 deletions

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Policy;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
@ -21,6 +22,8 @@ namespace Flow.Launcher.Plugin
private string _icoPath;
private string _icoAbsoluteFullPath;
private string _copyText = string.Empty;
private string _badgeIcoPath;
@ -67,12 +70,17 @@ namespace Flow.Launcher.Plugin
/// The image to be displayed for the result.
/// </summary>
/// <value>Can be a local file path or a URL.</value>
/// <remarks>GlyphInfo is prioritized if not null</remarks>
/// <remarks>
/// GlyphInfo is prioritized if not null.
/// Use IcoPathRelative for storage where it needs to be resistant to plugin location change.
/// </remarks>
public string IcoPath
{
get => _icoPath;
set
{
_icoPath = value;
// As a standard this property will handle prepping and converting to absolute local path for icon image processing
if (!string.IsNullOrEmpty(value)
&& !string.IsNullOrEmpty(PluginDirectory)
@ -81,40 +89,40 @@ namespace Flow.Launcher.Plugin
&& !value.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
&& !value.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
{
_icoPath = Path.Combine(PluginDirectory, value);
_icoAbsoluteFullPath = Path.Combine(PluginDirectory, value);
}
else
{
_icoPath = value;
_icoAbsoluteFullPath = value;
}
}
}
/// <summary>
/// Returns the plugin directory relative IcoPath or URL. This path is useful for storage where the it needs
/// to be resistant to changes in plugin location from update or portable mode change.
/// TODO COMMENT
/// </summary>
public string IcoAbsoluteFullPath => _icoAbsoluteFullPath;
/// <summary>
/// Returns IcoPath's relative path based on the plugin directory or original value if not file path.
/// This property is useful for storage where it needs to be resistant to changes in plugin location from update
/// or portable mode change.
/// </summary>
/// <value>Must be a local file path.</value>
/// <remarks>This will be empty string if IcoPath is a URL, so must check for empty string during usage</remarks>
public string IcoPathRelative
{
get => _icoPath;
set
get
{
// As a standard this property will handle prepping and converting to absolute local path for icon image processing
if (!string.IsNullOrEmpty(value)
&& !string.IsNullOrEmpty(PluginDirectory)
&& !Path.IsPathRooted(value)
&& !value.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
&& !value.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
&& !value.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(IcoAbsoluteFullPath)
|| string.IsNullOrEmpty(PluginDirectory)
|| !Path.IsPathRooted(IcoAbsoluteFullPath)
|| IcoAbsoluteFullPath.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
|| IcoAbsoluteFullPath.StartsWith("https://", StringComparison.OrdinalIgnoreCase)
|| IcoAbsoluteFullPath.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
{
_icoPath = Path.Combine(PluginDirectory, value);
}
else
{
_icoPath = value;
return IcoAbsoluteFullPath;
}
return Path.GetRelativePath(PluginDirectory, IcoAbsoluteFullPath);
}
}

View file

@ -333,7 +333,7 @@
Margin="18 24 0 0"
HorizontalAlignment="Left"
RenderOptions.BitmapScalingMode="Fant"
Source="{Binding IcoPath, IsAsync=True}" />
Source="{Binding IcoAbsoluteFullPath, IsAsync=True}" />
<Border
x:Name="LabelUpdate"
Height="12"

View file

@ -141,7 +141,7 @@ namespace Flow.Launcher.ViewModel
private bool GlyphAvailable => Glyph is not null;
private bool ImgIconAvailable => !string.IsNullOrEmpty(Result.IcoPath) || Result.Icon is not null;
private bool ImgIconAvailable => !string.IsNullOrEmpty(Result.IcoAbsoluteFullPath) || Result.Icon is not null;
private bool BadgeIconAvailable => !string.IsNullOrEmpty(Result.BadgeIcoPath) || Result.BadgeIcon is not null;
@ -236,7 +236,7 @@ namespace Flow.Launcher.ViewModel
private async Task LoadImageAsync()
{
var imagePath = Result.IcoPath;
var imagePath = Result.IcoAbsoluteFullPath;
var iconDelegate = Result.Icon;
if (ImageLoader.TryGetValue(imagePath, false, out var img))
{
@ -266,7 +266,7 @@ namespace Flow.Launcher.ViewModel
private async Task LoadPreviewImageAsync()
{
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoPath;
var imagePath = Result.Preview.PreviewImagePath ?? Result.IcoAbsoluteFullPath;
var iconDelegate = Result.Preview.PreviewDelegate ?? Result.Icon;
if (ImageLoader.TryGetValue(imagePath, true, out var img))
{