summaryrefslogtreecommitdiffstats
path: root/ui/backend/src/main.rs
blob: 989675627a97ecfdf5838c61a0b58ffa0bc03d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::path::PathBuf;

use atuin_client::settings::Settings;

mod db;
mod dotfiles;
mod store;

use db::{GlobalStats, HistoryDB, UIHistory};
use dotfiles::aliases::aliases;

#[tauri::command]
async fn list() -> Result<Vec<UIHistory>, 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.list(Some(100), false).await?;

    Ok(history)
}

#[tauri::command]
async fn search(query: String) -> Result<Vec<UIHistory>, 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.search(query.as_str()).await?;

    Ok(history)
}

#[tauri::command]
async fn global_stats() -> Result<GlobalStats, 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 stats = db.global_stats().await?;

    Ok(stats)
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![
            list,
            search,
            global_stats,
            aliases,
            dotfiles::aliases::import_aliases,
            dotfiles::aliases::delete_alias,
            dotfiles::aliases::set_alias,
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}