Skip to content

Commit

Permalink
Fixed problem when Clip construction is interrupted by COM exception. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Tum4ik authored Aug 14, 2023
1 parent 1337299 commit 1e602e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
namespace Tum4ik.JustClipboardManager.Converters;
internal class BytesToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
using var memoryStream = new MemoryStream((byte[]) value);
return BitmapFrame.Create(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
var bytes = (byte[]) value;
if (bytes.Length > 0)
{
using var memoryStream = new MemoryStream((byte[]) value);
return BitmapFrame.Create(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
}

return null;
}


Expand Down
5 changes: 5 additions & 0 deletions Tum4ik.JustClipboardManager/Services/ClipboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ private async Task SaveClipAsync()
Analytics.TrackEvent("Unrecognized Clip Type", eventProps);
}

if (representationData.Length <= 0)
{
return;
}

var clip = new Clip
{
ClipType = clipType,
Expand Down

0 comments on commit 1e602e9

Please sign in to comment.