A *lot* of work done on the audiogame-manager refactor. Hopefully getting somewhat close to stability, but I doubt it.

This commit is contained in:
Storm Dragon
2025-08-04 19:42:59 -04:00
parent 76f0c66c96
commit 4d2134b9a9
68 changed files with 109 additions and 154 deletions

View File

@@ -39,20 +39,20 @@ fi
# Define a function to safely query the database
query_database() {
local db_file="$1"
local sql_query="$2"
sqlite3 -line "$db_file" "$sql_query"
local dbFile="$1"
local sqlQuery="$2"
sqlite3 -line "$dbFile" "$sqlQuery"
}
# Define a function to safely insert into the database
insert_database() {
local db_file="$1"
local dbFile="$1"
local text="$2"
local translation="$3"
# Use sqlite3 .import feature which is more robust for special characters
echo "$text|$translation" | sqlite3 -separator "|" "$db_file" ".import /dev/stdin temp_import"
sqlite3 "$db_file" "INSERT OR IGNORE INTO translations SELECT * FROM temp_import; DROP TABLE IF EXISTS temp_import;"
echo "$text|$translation" | sqlite3 -separator "|" "$dbFile" ".import /dev/stdin temp_import"
sqlite3 "$dbFile" "INSERT OR IGNORE INTO translations SELECT * FROM temp_import; DROP TABLE IF EXISTS temp_import;"
}
# Read so long as the application is running
@@ -77,25 +77,25 @@ while pgrep -u "$USER" ^$1 &> /dev/null ; do
# Normalize different unicode space characters to the same space
# https://stackoverflow.com/a/43640405
alias normalize_spaces="perl -CSDA -plE 's/[^\\S\\t]/ /g'"
alias normalize_unicode="normalize_spaces | nfc"
alias normalizeSpaces="perl -CSDA -plE 's/[^\\S\\t]/ /g'"
alias normalizeUnicode="normalizeSpaces | nfc"
# Normalize text
normalized_text="$(echo "$text" | normalize_unicode)"
normalizedText="$(echo "$text" | normalizeUnicode)"
# Create a temporary database for import
sqlite3 "$translationFile" "CREATE TABLE IF NOT EXISTS temp_import(text TEXT, translation TEXT);"
# Check if we already have a translation
translated=$(sqlite3 "$translationFile" "SELECT translation FROM translations WHERE text = '$normalized_text' LIMIT 1;" 2>/dev/null)
translated=$(sqlite3 "$translationFile" "SELECT translation FROM translations WHERE text = '$normalizedText' LIMIT 1;" 2>/dev/null)
if [[ -z "$translated" ]]; then
# Get translation from the trans utility
translated="$(trans -no-autocorrect -no-warn -brief "$normalized_text" | head -1 | sed 's/\s*$//' | normalize_unicode)"
translated="$(trans -no-autocorrect -no-warn -brief "$normalizedText" | head -1 | sed 's/\s*$//' | normalizeUnicode)"
if [[ -n "$translated" ]]; then
# Insert using echo piping to avoid escaping issues
echo "$normalized_text|$translated" | sqlite3 -separator "|" "$translationFile" ".import /dev/stdin temp_import"
echo "$normalizedText|$translated" | sqlite3 -separator "|" "$translationFile" ".import /dev/stdin temp_import"
sqlite3 "$translationFile" "INSERT OR IGNORE INTO translations SELECT * FROM temp_import; DELETE FROM temp_import;"
fi
fi

View File

@@ -19,9 +19,9 @@ while pgrep -u "$USER" ^$1 &> /dev/null ; do
if [[ "$wnd_title" =~ $lookfor ]]; then
wnd_title=${BASH_REMATCH[1]}
if [[ "$old_title" != "$wnd_title" ]]; then
if [[ "$oldTitle" != "$wnd_title" ]]; then
spd-say -- "$wnd_title"
old_title="$wnd_title"
oldTitle="$wnd_title"
fi
fi
done