Refactor config history management to enforce byte size limit and optimize item prepending; improve hotkey listener synchronization to prevent deadlocks; enhance transcriber error handling to avoid leaking sensitive information; address multiple race conditions and potential crashes in audio processing; implement logging improvements and fix resource leaks; add comprehensive issue tracking documentation.

This commit is contained in:
Your Name
2026-06-09 09:16:55 -07:00
parent 05c8fbc474
commit 52bb65f3a0
14 changed files with 410 additions and 85 deletions
+21 -5
View File
@@ -147,19 +147,35 @@ func (c *Config) applyDefaults() {
}
}
// AddHistoryItem adds a new transcription to the history, enforcing a maximum limit.
// AddHistoryItem adds a new transcription to the history, enforcing limits on
// both the item count and the total byte size of the history payload.
func (c *Config) AddHistoryItem(text, timestamp string) {
newItem := HistoryItem{
Text: text,
Timestamp: timestamp,
}
// Prepend to history so the newest items are at the top
// Bounded item count: keep only the most recent items.
if len(c.History) >= MaxHistoryItems {
c.History = c.History[:MaxHistoryItems-1]
}
// Prepend to history so the newest items are at the top.
c.History = append([]HistoryItem{newItem}, c.History...)
// Bounded history: keep only the most recent items
if len(c.History) > MaxHistoryItems {
c.History = c.History[:MaxHistoryItems]
// Bounded total size: drop oldest items until under the byte cap.
const maxHistoryBytes = 256 * 1024 // 256 KB upper bound on history payload
total := 0
cutoff := 0
for i, item := range c.History {
total += len(item.Text) + len(item.Timestamp) + 32 // rough JSON overhead per item
if total > maxHistoryBytes {
cutoff = i + 1
break
}
}
if cutoff > 0 {
c.History = c.History[cutoff:]
}
}