mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-19 17:50:17 +01:00
Compare commits
1 Commits
async-cpp-
...
leilzh/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c7c9cf43c |
@@ -54,6 +54,8 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
|
|
||||||
private bool IsPng() => Item.Extension == ".png";
|
private bool IsPng() => Item.Extension == ".png";
|
||||||
|
|
||||||
|
private bool IsSvg() => Item.Extension == ".svg";
|
||||||
|
|
||||||
private bool IsQoi() => Item.Extension == ".qoi";
|
private bool IsQoi() => Item.Extension == ".qoi";
|
||||||
|
|
||||||
private DispatcherQueue Dispatcher { get; }
|
private DispatcherQueue Dispatcher { get; }
|
||||||
@@ -61,7 +63,7 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
private static readonly HashSet<string> _supportedFileTypes =
|
private static readonly HashSet<string> _supportedFileTypes =
|
||||||
BitmapDecoder.GetDecoderInformationEnumerator()
|
BitmapDecoder.GetDecoderInformationEnumerator()
|
||||||
.SelectMany(di => di.FileExtensions)
|
.SelectMany(di => di.FileExtensions)
|
||||||
.Union([".qoi"])
|
.Union([".svg", ".qoi"])
|
||||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public static bool IsItemSupported(IFileSystemItem item)
|
public static bool IsItemSupported(IFileSystemItem item)
|
||||||
@@ -73,7 +75,15 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (IsQoi())
|
if (IsSvg())
|
||||||
|
{
|
||||||
|
var size = await Task.Run(Item.GetSvgSize);
|
||||||
|
if (size != null)
|
||||||
|
{
|
||||||
|
ImageSize = size.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IsQoi())
|
||||||
{
|
{
|
||||||
var size = await Task.Run(Item.GetQoiSize);
|
var size = await Task.Run(Item.GetQoiSize);
|
||||||
if (size != null)
|
if (size != null)
|
||||||
@@ -166,16 +176,31 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
if (IsQoi())
|
using FileStream stream = ReadHelper.OpenReadOnly(Item.Path);
|
||||||
|
|
||||||
|
if (IsSvg())
|
||||||
|
{
|
||||||
|
var source = new SvgImageSource();
|
||||||
|
source.RasterizePixelHeight = ImageSize?.Height ?? 0;
|
||||||
|
source.RasterizePixelWidth = ImageSize?.Width ?? 0;
|
||||||
|
|
||||||
|
var loadStatus = await source.SetSourceAsync(stream.AsRandomAccessStream());
|
||||||
|
if (loadStatus != SvgImageSourceLoadStatus.Success)
|
||||||
|
{
|
||||||
|
Logger.LogError("Error loading SVG: " + loadStatus.ToString());
|
||||||
|
throw new ImageLoadingException(nameof(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
Preview = source;
|
||||||
|
}
|
||||||
|
else if (IsQoi())
|
||||||
{
|
{
|
||||||
using FileStream stream = ReadHelper.OpenReadOnly(Item.Path);
|
|
||||||
using var bitmap = QoiImage.FromStream(stream);
|
using var bitmap = QoiImage.FromStream(stream);
|
||||||
|
|
||||||
Preview = await BitmapHelper.BitmapToImageSource(bitmap, true, cancellationToken);
|
Preview = await BitmapHelper.BitmapToImageSource(bitmap, true, cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using FileStream stream = ReadHelper.OpenReadOnly(Item.Path);
|
|
||||||
Preview = new BitmapImage();
|
Preview = new BitmapImage();
|
||||||
await ((BitmapImage)Preview).SetSourceAsync(stream.AsRandomAccessStream());
|
await ((BitmapImage)Preview).SetSourceAsync(stream.AsRandomAccessStream());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,6 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
|
|
||||||
// Markdown
|
// Markdown
|
||||||
".md",
|
".md",
|
||||||
|
|
||||||
// SVG - using WebView2 for better compatibility with complex SVGs
|
|
||||||
// (e.g., from Adobe Illustrator, Inkscape)
|
|
||||||
".svg",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -115,10 +111,9 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
{
|
{
|
||||||
bool isHtml = File.Extension == ".html" || File.Extension == ".htm";
|
bool isHtml = File.Extension == ".html" || File.Extension == ".htm";
|
||||||
bool isMarkdown = File.Extension == ".md";
|
bool isMarkdown = File.Extension == ".md";
|
||||||
bool isSvg = File.Extension == ".svg";
|
|
||||||
|
|
||||||
bool supportedByMonaco = MonacoHelper.SupportedMonacoFileTypes.Contains(File.Extension);
|
bool supportedByMonaco = MonacoHelper.SupportedMonacoFileTypes.Contains(File.Extension);
|
||||||
bool useMonaco = supportedByMonaco && !isHtml && !isMarkdown && !isSvg;
|
bool useMonaco = supportedByMonaco && !isHtml && !isMarkdown;
|
||||||
|
|
||||||
IsDevFilePreview = supportedByMonaco;
|
IsDevFilePreview = supportedByMonaco;
|
||||||
CustomContextMenu = useMonaco;
|
CustomContextMenu = useMonaco;
|
||||||
@@ -133,13 +128,6 @@ namespace Peek.FilePreviewer.Previewers
|
|||||||
var raw = await ReadHelper.Read(File.Path.ToString());
|
var raw = await ReadHelper.Read(File.Path.ToString());
|
||||||
Preview = new Uri(MarkdownHelper.PreviewTempFile(raw, File.Path, TempFolderPath.Path));
|
Preview = new Uri(MarkdownHelper.PreviewTempFile(raw, File.Path, TempFolderPath.Path));
|
||||||
}
|
}
|
||||||
else if (isSvg)
|
|
||||||
{
|
|
||||||
// SVG files are rendered directly by WebView2 for better compatibility
|
|
||||||
// with complex SVGs from Adobe Illustrator, Inkscape, etc.
|
|
||||||
IsDevFilePreview = false;
|
|
||||||
Preview = new Uri(File.Path);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Simple html file to preview. Shouldn't do things like enabling scripts or using a virtual mapped directory.
|
// Simple html file to preview. Shouldn't do things like enabling scripts or using a virtual mapped directory.
|
||||||
|
|||||||
Reference in New Issue
Block a user