initial commit
This commit is contained in:
53
ClipboardManager.cs
Normal file
53
ClipboardManager.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Toak;
|
||||
|
||||
public static class ClipboardManager
|
||||
{
|
||||
public static void Copy(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text)) return;
|
||||
try
|
||||
{
|
||||
string sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE")?.ToLowerInvariant() ?? "";
|
||||
|
||||
ProcessStartInfo pInfo;
|
||||
if (sessionType == "wayland")
|
||||
{
|
||||
pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "wl-copy",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardInput = true
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "xclip",
|
||||
Arguments = "-selection clipboard",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardInput = true
|
||||
};
|
||||
}
|
||||
|
||||
var process = Process.Start(pInfo);
|
||||
if (process != null)
|
||||
{
|
||||
using (var sw = process.StandardInput)
|
||||
{
|
||||
sw.Write(text);
|
||||
}
|
||||
process.WaitForExit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[ClipboardManager] Error copying text: {ex.Message}");
|
||||
Notifications.Notify("Clipboard Error", "Could not copy text to clipboard.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user