refactor: modernize code, improve performance, and clean up various components.
This commit is contained in:
@@ -1,31 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
using Toak.Core.Interfaces;
|
||||
|
||||
namespace Toak.IO;
|
||||
|
||||
public class ClipboardManager : IClipboardManager
|
||||
public class ClipboardManager(INotifications notifications) : IClipboardManager
|
||||
{
|
||||
private readonly INotifications _notifications;
|
||||
|
||||
public ClipboardManager(INotifications notifications)
|
||||
{
|
||||
_notifications = notifications;
|
||||
}
|
||||
private readonly INotifications _notifications = notifications;
|
||||
|
||||
public void Copy(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text)) return;
|
||||
try
|
||||
{
|
||||
string sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE")?.ToLowerInvariant() ?? "";
|
||||
var sessionType = Environment.GetEnvironmentVariable("XDG_SESSION_TYPE")?.ToLowerInvariant() ?? "";
|
||||
|
||||
ProcessStartInfo pInfo;
|
||||
if (sessionType == "wayland")
|
||||
{
|
||||
pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = Toak.Core.Constants.Commands.ClipboardWayland,
|
||||
FileName = Core.Constants.Commands.ClipboardWayland,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardInput = true
|
||||
@@ -35,7 +29,7 @@ public class ClipboardManager : IClipboardManager
|
||||
{
|
||||
pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = Toak.Core.Constants.Commands.ClipboardX11,
|
||||
FileName = Core.Constants.Commands.ClipboardX11,
|
||||
Arguments = "-selection clipboard",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
@@ -44,14 +38,12 @@ public class ClipboardManager : IClipboardManager
|
||||
}
|
||||
|
||||
var process = Process.Start(pInfo);
|
||||
if (process != null)
|
||||
if (process == null) return;
|
||||
using (var sw = process.StandardInput)
|
||||
{
|
||||
using (var sw = process.StandardInput)
|
||||
{
|
||||
sw.Write(text);
|
||||
}
|
||||
process.WaitForExit();
|
||||
sw.Write(text);
|
||||
}
|
||||
process.WaitForExit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user