Use private temp directory and auto-cleanup audio files
Security improvements: - Audio file now stored in user's private NSTemporaryDirectory - Filename includes process ID to avoid conflicts - Audio file deleted after transcription (success or failure) - Audio file deleted when app terminates Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,7 +63,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
var isRecording = false
|
var isRecording = false
|
||||||
var settingsWindow: NSWindow?
|
var settingsWindow: NSWindow?
|
||||||
|
|
||||||
let audioFilePath = "/tmp/whisper-dictate.wav"
|
// Use private temp directory with unique filename
|
||||||
|
var audioFilePath: String {
|
||||||
|
let tempDir = NSTemporaryDirectory()
|
||||||
|
return (tempDir as NSString).appendingPathComponent("whisper-dictate-\(ProcessInfo.processInfo.processIdentifier).wav")
|
||||||
|
}
|
||||||
|
|
||||||
var language: String {
|
var language: String {
|
||||||
get { UserDefaults.standard.string(forKey: Defaults.language) ?? "hu" }
|
get { UserDefaults.standard.string(forKey: Defaults.language) ?? "hu" }
|
||||||
@@ -90,6 +94,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.")
|
NSLog("WhisperDictate started. Press ⌃⌥D to toggle recording.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func applicationWillTerminate(_ notification: Notification) {
|
||||||
|
cleanupAudioFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanupAudioFile() {
|
||||||
|
try? FileManager.default.removeItem(atPath: audioFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Status Item
|
// MARK: - Status Item
|
||||||
func setupStatusItem() {
|
func setupStatusItem() {
|
||||||
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||||
@@ -479,6 +491,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
result = result.trimmingCharacters(in: .whitespaces)
|
result = result.trimmingCharacters(in: .whitespaces)
|
||||||
|
|
||||||
|
// Cleanup audio file after transcription
|
||||||
|
self.cleanupAudioFile()
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if !result.isEmpty {
|
if !result.isEmpty {
|
||||||
self.pasteText(result)
|
self.pasteText(result)
|
||||||
@@ -490,6 +505,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
// Cleanup even on error
|
||||||
|
self.cleanupAudioFile()
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.statusItem.button?.title = "🎤"
|
self.statusItem.button?.title = "🎤"
|
||||||
self.updateStatus("Error")
|
self.updateStatus("Error")
|
||||||
|
|||||||
Reference in New Issue
Block a user