From 5b384487331eaf08031dfe438bb2affa31aafcbb Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Mon, 8 Jul 2024 11:17:47 +0100 Subject: feat(gui): runbooks that run (#2233) * add initial runbooks frontend * fix buttons, scroll, add shell support to editor * work * some tweaks * wip - run crate * functioning executable blocks * handle resizing, killing ptys * clear properly on stop * move terminal to its own component, handle lifecycle better * fix all build issues * ffs codespelll * update lockfile * clippy is needy once more * only build pty stuff on mac/linux * vendor pty handling into desktop * update lockfile --- ui/backend/src/main.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'ui/backend/src/main.rs') diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs index 2ba67e50..7adbbbe5 100644 --- a/ui/backend/src/main.rs +++ b/ui/backend/src/main.rs @@ -1,6 +1,8 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +use tauri::State; + use std::path::PathBuf; use tauri::{AppHandle, Manager}; @@ -9,6 +11,9 @@ use time::format_description::well_known::Rfc3339; mod db; mod dotfiles; mod install; +mod pty; +mod run; +mod state; mod store; use atuin_client::settings::Settings; @@ -168,7 +173,7 @@ async fn home_info() -> Result { } // Match the format that the frontend library we use expects -// All the processing in Rust, not JS. +// All the processing in Rust, not JSunwrap. // Faaaassssssst af ⚡️🦀 #[derive(Debug, serde::Serialize)] pub struct HistoryCalendarDay { @@ -215,6 +220,19 @@ async fn history_calendar() -> Result, String> { Ok(ret) } +#[tauri::command] +async fn prefix_search(query: &str) -> Result, String> { + let settings = Settings::new().map_err(|e| e.to_string())?; + + let db_path = PathBuf::from(settings.db_path.as_str()); + let db = HistoryDB::new(db_path, settings.local_timeout).await?; + + let history = db.prefix_search(query).await?; + let commands = history.into_iter().map(|h| h.command).collect(); + + Ok(commands) +} + fn show_window(app: &AppHandle) { let windows = app.webview_windows(); @@ -228,9 +246,11 @@ fn show_window(app: &AppHandle) { fn main() { tauri::Builder::default() + .plugin(tauri_plugin_shell::init()) .invoke_handler(tauri::generate_handler![ list, search, + prefix_search, global_stats, aliases, home_info, @@ -239,6 +259,10 @@ fn main() { login, register, history_calendar, + run::pty::pty_open, + run::pty::pty_write, + run::pty::pty_resize, + run::pty::pty_kill, install::install_cli, install::is_cli_installed, install::setup_cli, @@ -254,6 +278,7 @@ fn main() { .plugin(tauri_plugin_single_instance::init(|app, args, cwd| { let _ = show_window(app); })) + .manage(state::AtuinState::default()) .run(tauri::generate_context!()) .expect("error while running tauri application"); } -- cgit v1.3.1