Skip to content

Commit

Permalink
added support for replace.dict
Browse files Browse the repository at this point in the history
  • Loading branch information
jame25 authored Apr 14, 2024
1 parent 5d6829a commit 6967506
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions TrayApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void UpdatePiperArgs()

private void ShowAboutWindow()
{
string version = "1.1.8";
string version = "1.1.9";
string message = $"Piper Tray\n\nVersion: {version}\n\nDeveloped by jame25";
string url = "https://github.com/jame25/Piper-Tray";

Expand Down Expand Up @@ -642,6 +642,21 @@ private async void StartMonitoring()
// Read the ignore dictionary file
string[] ignoreWords = File.Exists("ignore.dict") ? File.ReadAllLines("ignore.dict") : new string[0];

// Read the replace dictionary file
Dictionary<string, string> replaceWords = new Dictionary<string, string>();
if (File.Exists("replace.dict"))
{
string[] lines = File.ReadAllLines("replace.dict");
foreach (string line in lines)
{
string[] parts = line.Split('=');
if (parts.Length == 2)
{
replaceWords[parts[0].Trim()] = parts[1].Trim();
}
}
}

while (isRunning)
{
if (isMonitoringEnabled)
Expand Down Expand Up @@ -678,10 +693,21 @@ private async void StartMonitoring()
// Filter out the ignored words
string filteredText = string.Join(" ", words.Where(word => !ignoreWords.Contains(word, StringComparer.OrdinalIgnoreCase)));

// Write the filtered text to the temporary file
// Replace words based on the replace dictionary
string[] modifiedWords = filteredText.Split(new[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < modifiedWords.Length; i++)
{
if (replaceWords.ContainsKey(modifiedWords[i]))
{
modifiedWords[i] = replaceWords[modifiedWords[i]];
}
}
string modifiedText = string.Join(" ", modifiedWords);

// Write the modified text to the temporary file
try
{
File.WriteAllText(TempFile, filteredText);
File.WriteAllText(TempFile, modifiedText);
}
catch (IOException ex)
{
Expand Down Expand Up @@ -747,6 +773,7 @@ await Task.Run(() =>
}
}


private void UpdateTrayIcon(ActivityState state)
{
if (trayIcon == null)
Expand Down

0 comments on commit 6967506

Please sign in to comment.