mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 11:59:13 +00:00
57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Input.Platform;
|
|
using Avalonia.Media.Imaging;
|
|
using Avalonia.Platform;
|
|
|
|
namespace v2rayN.Desktop.Common;
|
|
|
|
internal class AvaUtils
|
|
{
|
|
public static async Task<string?> GetClipboardData(Window owner)
|
|
{
|
|
try
|
|
{
|
|
var clipboard = TopLevel.GetTopLevel(owner)?.Clipboard;
|
|
if (clipboard == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return await clipboard.TryGetTextAsync();
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static async Task SetClipboardData(Visual? visual, string strData)
|
|
{
|
|
try
|
|
{
|
|
var clipboard = TopLevel.GetTopLevel(visual)?.Clipboard;
|
|
if (clipboard == null)
|
|
return;
|
|
await clipboard.SetTextAsync(strData);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
public static WindowIcon GetAppIcon(ESysProxyType sysProxyType)
|
|
{
|
|
var index = (int)sysProxyType + 1;
|
|
var fileName = Utils.GetPath($"NotifyIcon{index}.ico");
|
|
if (File.Exists(fileName))
|
|
{
|
|
return new(fileName);
|
|
}
|
|
|
|
var uri = new Uri(Path.Combine(Global.AvaAssets, $"NotifyIcon{index}.ico"));
|
|
using var bitmap = new Bitmap(AssetLoader.Open(uri));
|
|
return new(bitmap);
|
|
}
|
|
}
|