1
0

refactor: modernize code, improve performance, and clean up various components.

This commit is contained in:
2026-03-01 21:05:35 +01:00
parent 15f9647f8a
commit a6c7df0a71
37 changed files with 240 additions and 627 deletions

View File

@@ -1,19 +1,12 @@
using System.Diagnostics;
using Toak.Core;
using Toak.Core.Interfaces;
namespace Toak.IO;
public class TextInjector : ITextInjector
public class TextInjector(INotifications notifications) : ITextInjector
{
private readonly INotifications _notifications;
public TextInjector(INotifications notifications)
{
_notifications = notifications;
}
private readonly INotifications _notifications = notifications;
public Task InjectTextAsync(string text, string backend = "xdotool")
{
@@ -28,8 +21,8 @@ public class TextInjector : ITextInjector
Logger.LogDebug($"Injecting text using wtype...");
pInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeWayland,
Arguments = $"-d {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
FileName = Constants.Commands.TypeWayland,
Arguments = $"-d {Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
};
@@ -39,7 +32,7 @@ public class TextInjector : ITextInjector
Logger.LogDebug($"Injecting text using ydotool...");
pInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeYdotool,
FileName = Constants.Commands.TypeYdotool,
Arguments = $"type \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
@@ -50,8 +43,8 @@ public class TextInjector : ITextInjector
Logger.LogDebug($"Injecting text using xdotool...");
pInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeX11,
Arguments = $"type --clearmodifiers --delay {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
FileName = Constants.Commands.TypeX11,
Arguments = $"type --clearmodifiers --delay {Constants.Defaults.DefaultTypeDelayMs} \"{text.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
};
@@ -69,7 +62,7 @@ public class TextInjector : ITextInjector
public async Task<string> InjectStreamAsync(IAsyncEnumerable<string> tokenStream, string backend)
{
string fullText = string.Empty;
var fullText = string.Empty;
try
{
ProcessStartInfo pInfo;
@@ -78,8 +71,8 @@ public class TextInjector : ITextInjector
Logger.LogDebug($"Setting up stream injection using wtype...");
pInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeWayland,
Arguments = $"-d {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} -",
FileName = Constants.Commands.TypeWayland,
Arguments = $"-d {Constants.Defaults.DefaultTypeDelayMs} -",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true
@@ -94,7 +87,7 @@ public class TextInjector : ITextInjector
fullText += token;
var chunkInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeYdotool,
FileName = Constants.Commands.TypeYdotool,
Arguments = $"type \"{token.Replace("\"", "\\\"")}\"",
UseShellExecute = false,
CreateNoWindow = true
@@ -109,8 +102,8 @@ public class TextInjector : ITextInjector
Logger.LogDebug($"Setting up stream injection using xdotool...");
pInfo = new ProcessStartInfo
{
FileName = Toak.Core.Constants.Commands.TypeX11,
Arguments = $"type --clearmodifiers --delay {Toak.Core.Constants.Defaults.DefaultTypeDelayMs} --file -",
FileName = Constants.Commands.TypeX11,
Arguments = $"type --clearmodifiers --delay {Constants.Defaults.DefaultTypeDelayMs} --file -",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true