Files
ws-agent/frontend/src-tauri/src/main.rs

67 lines
2.2 KiB
Rust

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod commands;
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use tokio::sync::Mutex;
use commands::{chat, chat_history, daemon_state, toggle_dark_mode, toggle_popup};
use shared::ai::ai_daemon_client::AiDaemonClient;
pub struct AppConfig {
dark_mode: bool,
}
pub struct AppState {
grpc_client: Mutex<AiDaemonClient<tonic::transport::Channel>>,
config: Mutex<AppConfig>,
current_chat_id: Mutex<i32>,
}
#[tokio::main]
async fn main() {
let channel = tonic::transport::Channel::from_static("http://[::1]:50051").connect_lazy();
let client = AiDaemonClient::new(channel);
tauri::Builder::default()
.manage(AppState {
grpc_client: Mutex::new(client),
config: Mutex::new(AppConfig { dark_mode: true }),
current_chat_id: Mutex::new(-1),
})
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.invoke_handler(tauri::generate_handler![
toggle_popup,
chat_history,
chat,
daemon_state,
toggle_dark_mode,
])
.setup(|app| {
/* Auto-hide popup when focus is lost
if let Some(window) = app.get_webview_window("popup") {
let w = window.clone();
window.on_window_event(move |event| {
if let WindowEvent::Focused(focuced) = event {
if !focuced {
w.hide().unwrap();
}
}
})
}
*/
// Global shortcut to pull up the popup
let shortcut = Shortcut::new(Some(Modifiers::META), Code::Space);
app.global_shortcut()
.on_shortcut(shortcut, move |app, _shortcut, event| {
if event.state() == ShortcutState::Pressed {
toggle_popup(app.clone());
}
})?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}