Bugfixes and updated audio playback.

This commit is contained in:
Aodhan Collins
2025-10-06 23:25:21 +01:00
parent f2881710ea
commit 0a7b164b29
15 changed files with 1875 additions and 107 deletions

View File

@@ -4,6 +4,8 @@
use serde::Serialize;
use tauri::{Manager, GlobalShortcutManager};
use tauri::api::notification::Notification;
use std::fs;
use std::path::PathBuf;
#[derive(Serialize, Clone)]
struct Keys {
@@ -46,12 +48,108 @@ fn send_notification(app_handle: tauri::AppHandle, title: String, body: String)
Ok(())
}
// Get the audio cache directory path
fn get_audio_cache_dir(app_handle: tauri::AppHandle) -> Result<PathBuf, String> {
let app_dir = app_handle
.path_resolver()
.app_data_dir()
.ok_or("Failed to get app data directory")?;
let cache_dir = app_dir.join("audio_cache");
// Create directory if it doesn't exist
fs::create_dir_all(&cache_dir)
.map_err(|e| format!("Failed to create cache directory: {}", e))?;
Ok(cache_dir)
}
#[tauri::command]
fn save_audio_file(app_handle: tauri::AppHandle, message_id: String, audio_data: Vec<u8>) -> Result<String, String> {
let cache_dir = get_audio_cache_dir(app_handle)?;
let file_path = cache_dir.join(format!("{}.mp3", message_id));
fs::write(&file_path, audio_data)
.map_err(|e| format!("Failed to write audio file: {}", e))?;
println!("💾 Saved audio file: {:?}", file_path);
Ok(file_path.to_string_lossy().to_string())
}
#[tauri::command]
fn load_audio_file(app_handle: tauri::AppHandle, message_id: String) -> Result<Vec<u8>, String> {
let cache_dir = get_audio_cache_dir(app_handle)?;
let file_path = cache_dir.join(format!("{}.mp3", message_id));
if !file_path.exists() {
return Err("Audio file not found".to_string());
}
fs::read(&file_path)
.map_err(|e| format!("Failed to read audio file: {}", e))
}
#[tauri::command]
fn check_audio_file(app_handle: tauri::AppHandle, message_id: String) -> Result<bool, String> {
let cache_dir = get_audio_cache_dir(app_handle)?;
let file_path = cache_dir.join(format!("{}.mp3", message_id));
Ok(file_path.exists())
}
#[tauri::command]
fn delete_audio_file(app_handle: tauri::AppHandle, message_id: String) -> Result<(), String> {
let cache_dir = get_audio_cache_dir(app_handle)?;
let file_path = cache_dir.join(format!("{}.mp3", message_id));
if file_path.exists() {
fs::remove_file(&file_path)
.map_err(|e| format!("Failed to delete audio file: {}", e))?;
println!("🗑️ Deleted audio file: {:?}", file_path);
}
Ok(())
}
#[tauri::command]
fn delete_audio_files_batch(app_handle: tauri::AppHandle, message_ids: Vec<String>) -> Result<usize, String> {
let cache_dir = get_audio_cache_dir(app_handle)?;
let mut deleted_count = 0;
for message_id in message_ids {
let file_path = cache_dir.join(format!("{}.mp3", message_id));
if file_path.exists() {
match fs::remove_file(&file_path) {
Ok(_) => {
deleted_count += 1;
println!("🗑️ Deleted audio file: {:?}", file_path);
},
Err(e) => {
eprintln!("⚠️ Failed to delete audio file {}: {}", message_id, e);
}
}
}
}
println!("🗑️ Deleted {} audio files", deleted_count);
Ok(deleted_count)
}
fn main() {
// Note: System tray temporarily disabled on Linux due to icon format issues
// The app works perfectly without it - you can minimize/maximize normally
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, get_env_keys, send_notification])
.invoke_handler(tauri::generate_handler![
greet,
get_env_keys,
send_notification,
save_audio_file,
load_audio_file,
check_audio_file,
delete_audio_file,
delete_audio_files_batch
])
.setup(|app| {
// Register global shortcut to show/hide EVE
let window = app.get_window("main").unwrap();