Prompt popup implementation

This commit is contained in:
2026-02-02 20:34:32 +02:00
parent 6416d7c347
commit b5ae7c8550
6 changed files with 97 additions and 29 deletions

View File

@@ -3,10 +3,10 @@
use tokio::sync::Mutex;
use tauri::{Manager, State, WindowEvent};
use tauri::{Emitter, Manager, State, WindowEvent};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use shared::ai::{PromptRequest, ai_daemon_client::AiDaemonClient};
use shared::ai::{ai_daemon_client::AiDaemonClient, PromptRequest};
struct AppState {
grpc_client: Mutex<AiDaemonClient<tonic::transport::Channel>>,
@@ -22,6 +22,7 @@ fn toggle_popup(app_handle: tauri::AppHandle) {
} else {
window.show().unwrap();
window.set_focus().unwrap();
let _ = window.emit("window-focused", ());
}
}
None => {
@@ -32,7 +33,8 @@ fn toggle_popup(app_handle: tauri::AppHandle) {
#[tauri::command]
async fn prompt_llm(state: State<'_, AppState>, prompt: String) -> Result<String, String> {
let mut client= state.grpc_client.lock().await;
println!(">>>> {}", prompt);
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),
@@ -42,7 +44,6 @@ async fn prompt_llm(state: State<'_, AppState>, prompt: String) -> Result<String
#[tokio::main]
async fn main() {
let channel = tonic::transport::Channel::from_static("http://[::1]:50051")
.connect()
.await
@@ -51,7 +52,9 @@ async fn main() {
let client = AiDaemonClient::new(channel);
tauri::Builder::default()
.manage(AppState { grpc_client: Mutex::new(client) })
.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| {
@@ -66,11 +69,12 @@ async fn main() {
})
}
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());
}
})?;
app.global_shortcut()
.on_shortcut(shortcut, move |app, _shortcut, event| {
if event.state() == ShortcutState::Pressed {
toggle_popup(app.clone());
}
})?;
Ok(())
})
.run(tauri::generate_context!())

View File

@@ -23,7 +23,7 @@
"title": "AI Quick Action",
"url": "/popup",
"width": 600,
"height": 100,
"height": 260,
"decorations": false,
"transparent": true,
"alwaysOnTop": true,