Renamed frontend directory

This commit is contained in:
2026-01-27 19:37:20 +02:00
parent a9dd3eea7a
commit 207947c095
37 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,14 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,78 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tokio::sync::Mutex;
use tauri::{Manager, State, WindowEvent};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use shared::ai::{PromptRequest, ai_daemon_client::AiDaemonClient};
struct AppState {
grpc_client: Mutex<AiDaemonClient<tonic::transport::Channel>>,
}
#[tauri::command]
fn toggle_popup(app_handle: tauri::AppHandle) {
match app_handle.get_webview_window("popup") {
Some(window) => {
let is_visible = window.is_visible().unwrap_or(false);
if is_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
}
}
None => {
println!("ERROR: Window with label 'popup' not found!");
}
}
}
#[tauri::command]
async fn prompt_llm(state: State<'_, AppState>, prompt: String) -> Result<String, String> {
let mut client= state.grpc_client.lock().await;
let request = tonic::Request::new(PromptRequest { prompt });
match client.prompt(request).await {
Ok(response) => Ok(response.into_inner().response),
Err(e) => Err(format!("gRPC error: {}", e)),
}
}
#[tokio::main]
async fn main() {
let channel = tonic::transport::Channel::from_static("http://[::1]:50051")
.connect()
.await
.expect("Could not connect to daemon!");
let client = AiDaemonClient::new(channel);
tauri::Builder::default()
.manage(AppState { grpc_client: Mutex::new(client) })
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
.invoke_handler(tauri::generate_handler![toggle_popup, prompt_llm])
.setup(|app| {
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();
}
}
})
}
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");
}