diff --git a/.gitignore b/.gitignore index 3e759b7..4ae580f 100644 --- a/.gitignore +++ b/.gitignore @@ -326,5 +326,5 @@ ASALocalRun/ # NVidia Nsight GPU debugger configuration file *.nvuser -# MFractors (Xamarin productivity tool) working folder +# MFractors (Xamarin productivity tool) working folder .mfractor/ diff --git a/Directory.Packages.props b/Directory.Packages.props index 90d8b0d..7dff228 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,16 +4,14 @@ - - - - - - - - - - + + + + + + + + diff --git a/src/SharpFM.Plugin.Sample/SharpFM.Plugin.Sample.csproj b/src/SharpFM.Plugin.Sample/SharpFM.Plugin.Sample.csproj index e305001..491d79f 100644 --- a/src/SharpFM.Plugin.Sample/SharpFM.Plugin.Sample.csproj +++ b/src/SharpFM.Plugin.Sample/SharpFM.Plugin.Sample.csproj @@ -18,7 +18,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/SharpFM.Plugin.XmlViewer/SharpFM.Plugin.XmlViewer.csproj b/src/SharpFM.Plugin.XmlViewer/SharpFM.Plugin.XmlViewer.csproj index 74c6f2f..f78149e 100644 --- a/src/SharpFM.Plugin.XmlViewer/SharpFM.Plugin.XmlViewer.csproj +++ b/src/SharpFM.Plugin.XmlViewer/SharpFM.Plugin.XmlViewer.csproj @@ -21,7 +21,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/SharpFM/Services/ClipboardService.cs b/src/SharpFM/Services/ClipboardService.cs index 82e4133..a4e550f 100644 --- a/src/SharpFM/Services/ClipboardService.cs +++ b/src/SharpFM/Services/ClipboardService.cs @@ -1,9 +1,10 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Input; -using FluentAvalonia.UI.Data; +using Avalonia.Input.Platform; namespace SharpFM.Services; @@ -19,31 +20,35 @@ public ClipboardService(Window window) public async Task SetTextAsync(string text) { - var clipboard = _window.Clipboard - ?? throw new InvalidOperationException("Clipboard is not available."); + var clipboard = GetClipboard(); await clipboard.SetTextAsync(text); } public async Task SetDataAsync(string format, byte[] data) { - var clipboard = _window.Clipboard - ?? throw new InvalidOperationException("Clipboard is not available."); - var dp = new DataPackage(); - dp.SetData(format, data); - await clipboard.SetDataObjectAsync(dp); + var clipboard = GetClipboard(); + var dataFormat = DataFormat.CreateBytesPlatformFormat(format); + var transfer = new DataTransfer(); + transfer.Add(DataTransferItem.Create(dataFormat, data)); + await clipboard.SetDataAsync(transfer); } public async Task GetFormatsAsync() { - var clipboard = _window.Clipboard - ?? throw new InvalidOperationException("Clipboard is not available."); - return await clipboard.GetFormatsAsync(); + var clipboard = GetClipboard(); + var formats = await clipboard.GetDataFormatsAsync(); + return formats.Select(f => f.Identifier).ToArray(); } public async Task GetDataAsync(string format) { - var clipboard = _window.Clipboard - ?? throw new InvalidOperationException("Clipboard is not available."); - return await clipboard.GetDataAsync(format); + var clipboard = GetClipboard(); + using var transfer = await clipboard.TryGetDataAsync(); + if (transfer is null) return null; + var dataFormat = DataFormat.CreateBytesPlatformFormat(format); + return await transfer.TryGetValueAsync(dataFormat); } + + private IClipboard GetClipboard() => + _window.Clipboard ?? throw new InvalidOperationException("Clipboard is not available."); } diff --git a/src/SharpFM/SharpFM.csproj b/src/SharpFM/SharpFM.csproj index c50a006..e006680 100644 --- a/src/SharpFM/SharpFM.csproj +++ b/src/SharpFM/SharpFM.csproj @@ -57,18 +57,13 @@ + - - - - runtime; build; native; contentfiles; analyzers; buildtransitive