1
0

Refactor: Reorganize project structure by moving core components into dedicated directories and introducing new configuration and API models.

This commit is contained in:
2026-02-26 21:51:36 +01:00
parent fbff8c98ff
commit d60730c4bf
13 changed files with 83 additions and 60 deletions

53
IO/ClipboardManager.cs Normal file
View File

@@ -0,0 +1,53 @@
using System.Diagnostics;
namespace Toak.IO;
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.");
}
}
}

25
IO/Notifications.cs Normal file
View File

@@ -0,0 +1,25 @@
using System.Diagnostics;
namespace Toak.IO;
public static class Notifications
{
public static void Notify(string summary, string body = "")
{
try
{
var pInfo = new ProcessStartInfo
{
FileName = "notify-send",
Arguments = $"-a \"Toak\" \"{summary}\" \"{body}\"",
UseShellExecute = false,
CreateNoWindow = true
};
Process.Start(pInfo);
}
catch (Exception ex)
{
Console.WriteLine($"[Notifications] Failed to send notification: {ex.Message}");
}
}
}

43
IO/TextInjector.cs Normal file
View File

@@ -0,0 +1,43 @@
using System.Diagnostics;
namespace Toak.IO;
public static class TextInjector
{
public static void Inject(string text, string backend)
{
if (string.IsNullOrWhiteSpace(text)) return;
try
{
ProcessStartInfo pInfo;
if (backend.ToLowerInvariant() == "wtype")
{
pInfo = new ProcessStartInfo
{
FileName = "wtype",
Arguments = $"\"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
};
}
else // xdotool
{
pInfo = new ProcessStartInfo
{
FileName = "xdotool",
Arguments = $"type --clearmodifiers --delay 0 \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
};
}
var process = Process.Start(pInfo);
process?.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine($"[TextInjector] Error injecting text: {ex.Message}");
Notifications.Notify("Injection Error", "Could not type text into window.");
}
}
}