From 6c54ad85894b7cdd7065aa56965d7fa4823bf1e7 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 5 Dec 2022 16:01:20 +0800
Subject: [PATCH] refactor preview info
---
Flow.Launcher.Plugin/Result.cs | 43 +++++++++----------
Flow.Launcher/ViewModel/ResultViewModel.cs | 4 +-
.../Search/ResultManager.cs | 25 +++++++++--
.../Programs/UWP.cs | 8 +++-
4 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/Flow.Launcher.Plugin/Result.cs b/Flow.Launcher.Plugin/Result.cs
index 89965c6c5..912a23a6f 100644
--- a/Flow.Launcher.Plugin/Result.cs
+++ b/Flow.Launcher.Plugin/Result.cs
@@ -81,16 +81,6 @@ namespace Flow.Launcher.Plugin
///
public bool RoundedIcon { get; set; } = false;
- ///
- /// Full image used for preview panel
- ///
- public string PreviewImage { get; set; } = null;
-
- ///
- /// Determines if the preview image should occupy the full width of the preveiw panel.
- ///
- public bool FullWidthPreview { get; set; } = false;
-
///
/// Delegate function, see
///
@@ -240,22 +230,29 @@ namespace Flow.Launcher.Plugin
/// #26a0da (blue)
public string ProgressBarColor { get; set; } = "#26a0da";
+ public PreviewInfo Preview { get; set; } = PreviewInfo.Default;
+
///
- /// Suggests the preview image of result should use full width of the default preview panel by result's file extension.
+ /// Info of the preview image.
///
- /// File extension. Dot included.
- public static bool ShouldUseFullWidthPreview(string extension)
+ public record PreviewInfo
{
- return extension is ".jpg"
- or ".png"
- or ".avi"
- or ".mkv"
- or ".bmp"
- or ".gif"
- or ".wmv"
- or ".mp3"
- or ".flac"
- or ".mp4";
+ ///
+ /// Full image used for preview panel
+ ///
+ public string PreviewImagePath { get; set; }
+ ///
+ /// Determines if the preview image should occupy the full width of the preveiw panel.
+ ///
+ public bool IsMedia { get; set; }
+ public string Description { get; set; }
+
+ public static PreviewInfo Default { get; } = new()
+ {
+ PreviewImagePath = null,
+ Description = null,
+ IsMedia = false,
+ };
}
}
}
diff --git a/Flow.Launcher/ViewModel/ResultViewModel.cs b/Flow.Launcher/ViewModel/ResultViewModel.cs
index 8889b0321..59ff345f6 100644
--- a/Flow.Launcher/ViewModel/ResultViewModel.cs
+++ b/Flow.Launcher/ViewModel/ResultViewModel.cs
@@ -169,7 +169,7 @@ namespace Flow.Launcher.ViewModel
///
/// Determines if to use the full width of the preview panel
///
- public bool UseBigThumbnail => Result.FullWidthPreview;
+ public bool UseBigThumbnail => Result.Preview.IsMedia;
public GlyphInfo Glyph { get; set; }
@@ -210,7 +210,7 @@ namespace Flow.Launcher.ViewModel
private async Task LoadPreviewImageAsync()
{
- var imagePath = Result.PreviewImage ?? Result.IcoPath;
+ var imagePath = string.IsNullOrEmpty(Result.Preview.PreviewImagePath) ? Result.IcoPath : Result.Preview.PreviewImagePath;
var iconDelegate = Result.Icon;
if (ImageLoader.CacheContainImage(imagePath, true))
{
diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
index e110b58b5..7e11b4532 100644
--- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
+++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/ResultManager.cs
@@ -174,7 +174,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search
}, StringSplitOptions.None).Last();
var title = $"Open {folderName}";
-
+
var subtitleFolderName = folderName;
// ie. max characters can be displayed without subtitle cutting off: "Program Files (x86)"
@@ -205,14 +205,17 @@ namespace Flow.Launcher.Plugin.Explorer.Search
internal static Result CreateFileResult(string filePath, Query query, int score = 0, bool windowsIndexed = false)
{
- bool shouldUseBigThumbnail = Result.ShouldUseFullWidthPreview(Path.GetExtension(filePath));
+ Result.PreviewInfo preview = IsMedia(Path.GetExtension(filePath)) ? new Result.PreviewInfo {
+ IsMedia = true,
+ PreviewImagePath = filePath,
+ } : Result.PreviewInfo.Default;
+
var result = new Result
{
Title = Path.GetFileName(filePath),
SubTitle = Path.GetDirectoryName(filePath),
IcoPath = filePath,
- PreviewImage = shouldUseBigThumbnail ? filePath : null,
- FullWidthPreview = shouldUseBigThumbnail,
+ Preview = preview,
AutoCompleteText = GetPathWithActionKeyword(filePath, ResultType.File),
TitleHighlightData = StringMatcher.FuzzySearch(query.Search, Path.GetFileName(filePath)).MatchData,
Score = score,
@@ -266,6 +269,20 @@ namespace Flow.Launcher.Plugin.Explorer.Search
};
return result;
}
+
+ public static bool IsMedia(string extension)
+ {
+ return extension is ".jpg"
+ or ".png"
+ or ".avi"
+ or ".mkv"
+ or ".bmp"
+ or ".gif"
+ or ".wmv"
+ or ".mp3"
+ or ".flac"
+ or ".mp4";
+ }
}
public enum ResultType
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 5dc856b08..d06c4cc8d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -405,8 +405,12 @@ namespace Flow.Launcher.Plugin.Program.Programs
Title = title,
SubTitle = Main._settings.HideAppsPath ? string.Empty : Location,
IcoPath = LogoPath,
- PreviewImage = PreviewImagePath,
- FullWidthPreview = false,
+ Preview = new Result.PreviewInfo
+ {
+ IsMedia = false,
+ PreviewImagePath = PreviewImagePath,
+ Description = Description
+ },
Score = matchResult.Score,
TitleHighlightData = matchResult.MatchData,
ContextData = this,