Files
AI-translater-clinet/src-tauri/src/main.rs
2026-01-18 21:36:59 +01:00

61 lines
1.8 KiB
Rust

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod utilities;
mod controllers;
mod viewers;
use log::info;
use utilities::config::load_config;
use utilities::logging::setup_logging;
use controllers::app_state::init_state;
use controllers::settings::{get_settings, save_settings};
use controllers::greet::greet;
use viewers::tray::setup_tray;
#[tokio::main]
async fn main() {
// 1. Load configuration
let config = match load_config() {
Ok(c) => c,
Err(e) => {
eprintln!("Failed to load config: {}", e);
// Default config fallback logic is inside load_config, but if file IO fails we might get here.
// We can try to proceed with default logging if possible, but for now just print to stderr.
return;
}
};
// 2. Init logging
if let Err(e) = setup_logging(&config) {
eprintln!("Failed to setup logging: {}", e);
}
info!("Application started");
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![get_settings, save_settings, greet])
.setup(|app| {
info!("Setting up application...");
// 3. Init State
init_state(app);
// 4. Setup Tray
setup_tray(app)?;
Ok(())
})
.on_window_event(|window, event| {
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
// Prevent the window from closing (destroying)
// Instead, hide it. This keeps the app running in the tray.
window.hide().unwrap();
api.prevent_close();
}
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}