mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
[File Explorer] OneDrive SVG fix (#8926)
* Move SVG file reading out of the UI thread * Also move Blocked-check out of the UI thread
This commit is contained in:
@@ -42,22 +42,37 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
/// <param name="dataSource">Stream reference to access source file.</param>
|
/// <param name="dataSource">Stream reference to access source file.</param>
|
||||||
public override void DoPreview<T>(T dataSource)
|
public override void DoPreview<T>(T dataSource)
|
||||||
{
|
{
|
||||||
|
string svgData = null;
|
||||||
|
bool blocked = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var stream = new ReadonlyStream(dataSource as IStream))
|
||||||
|
{
|
||||||
|
using (var reader = new StreamReader(stream))
|
||||||
|
{
|
||||||
|
svgData = reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
blocked = SvgPreviewHandlerHelper.CheckBlockedElements(svgData);
|
||||||
|
}
|
||||||
|
#pragma warning disable CA1031 // Do not catch general exception types
|
||||||
|
catch (Exception ex)
|
||||||
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
|
{
|
||||||
|
PreviewError(ex, dataSource);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
InvokeOnControlThread(() =>
|
InvokeOnControlThread(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_infoBarAdded = false;
|
_infoBarAdded = false;
|
||||||
string svgData = null;
|
|
||||||
using (var stream = new ReadonlyStream(dataSource as IStream))
|
|
||||||
{
|
|
||||||
using (var reader = new StreamReader(stream))
|
|
||||||
{
|
|
||||||
svgData = reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a info bar on top of the Preview if any blocked element is present.
|
// Add a info bar on top of the Preview if any blocked element is present.
|
||||||
if (SvgPreviewHandlerHelper.CheckBlockedElements(svgData))
|
if (blocked)
|
||||||
{
|
{
|
||||||
_infoBarAdded = true;
|
_infoBarAdded = true;
|
||||||
AddTextBoxControl(Resource.BlockedElementInfoText);
|
AddTextBoxControl(Resource.BlockedElementInfoText);
|
||||||
@@ -72,11 +87,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
#pragma warning restore CA1031 // Do not catch general exception types
|
#pragma warning restore CA1031 // Do not catch general exception types
|
||||||
{
|
{
|
||||||
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = ex.Message });
|
PreviewError(ex, dataSource);
|
||||||
Controls.Clear();
|
|
||||||
_infoBarAdded = true;
|
|
||||||
AddTextBoxControl(Resource.SvgNotPreviewedError);
|
|
||||||
base.DoPreview(dataSource);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -138,5 +149,19 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
|
|||||||
_textBox.BorderStyle = BorderStyle.None;
|
_textBox.BorderStyle = BorderStyle.None;
|
||||||
Controls.Add(_textBox);
|
Controls.Add(_textBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when an error occurs during preview.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception">The exception which occurred.</param>
|
||||||
|
/// <param name="dataSource">Stream reference to access source file.</param>
|
||||||
|
private void PreviewError<T>(Exception exception, T dataSource)
|
||||||
|
{
|
||||||
|
PowerToysTelemetry.Log.WriteEvent(new SvgFilePreviewError { Message = exception.Message });
|
||||||
|
Controls.Clear();
|
||||||
|
_infoBarAdded = true;
|
||||||
|
AddTextBoxControl(Resource.SvgNotPreviewedError);
|
||||||
|
base.DoPreview(dataSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user