提交 9f171c74 编写于 作者: A Aigio Liu

🐛 Linux IClipboardPlatformService

上级 83de4dac
...@@ -104,6 +104,9 @@ sealed partial class Program : Startup ...@@ -104,6 +104,9 @@ sealed partial class Program : Startup
services.AddSingleton<IApplication>(s => s.GetRequiredService<App>()); services.AddSingleton<IApplication>(s => s.GetRequiredService<App>());
services.TryAddAvaloniaFilePickerPlatformService(); services.TryAddAvaloniaFilePickerPlatformService();
#if LINUX
services.AddSingleton<IClipboardPlatformService, AvaloniaClipboardPlatformService>();
#endif
#region WindowManager #region WindowManager
......
#if LINUX
namespace BD.WTTS.Services.Implementation;
public sealed class AvaloniaClipboardPlatformService : IClipboardPlatformService
{
public bool PlatformHasText => !string.IsNullOrEmpty(PlatformGetTextAsync().GetAwaiter().GetResult());
public async Task<string> PlatformGetTextAsync()
{
TopLevel? topLevel = App.Instance.MainWindow;
if (topLevel != null)
{
var clipboard = topLevel.Clipboard;
if (clipboard != null)
{
var result = await clipboard.GetTextAsync();
return result ?? string.Empty;
}
}
return string.Empty;
}
public async Task PlatformSetTextAsync(string text)
{
TopLevel? topLevel = App.Instance.MainWindow;
if (topLevel != null)
{
var clipboard = topLevel.Clipboard;
if (clipboard != null)
{
await clipboard.SetTextAsync(text);
}
}
}
}
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册