Refactor: Reorganize project structure by moving core components into dedicated directories and introducing new configuration and API models.
This commit is contained in:
43
IO/TextInjector.cs
Normal file
43
IO/TextInjector.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user