aboutsummaryrefslogtreecommitdiffstats
path: root/ui/backend
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@atuin.sh>2024-07-23 13:18:54 +0100
committerGitHub <noreply@github.com>2024-07-23 13:18:54 +0100
commitf8c963c7d668fc57680f25413f20bc207d4bf64a (patch)
treec7f952ddc0220cded24f5447d03b3bff46fb1d45 /ui/backend
parentfix(themes): Restore default theme, refactor (#2294) (diff)
downloadatuin-f8c963c7d668fc57680f25413f20bc207d4bf64a.zip
feat(gui): clean up home page, fix a few bugs (#2304)
* wip home screen changes * more * adjust * fixes and things * patch runbook pty check
Diffstat (limited to 'ui/backend')
-rw-r--r--ui/backend/Cargo.lock4
-rw-r--r--ui/backend/src/db.rs2
-rw-r--r--ui/backend/src/main.rs14
3 files changed, 17 insertions, 3 deletions
diff --git a/ui/backend/Cargo.lock b/ui/backend/Cargo.lock
index 3f79cf04..1459e7e7 100644
--- a/ui/backend/Cargo.lock
+++ b/ui/backend/Cargo.lock
@@ -2866,9 +2866,9 @@ dependencies = [
[[package]]
name = "itertools"
-version = "0.12.1"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
+checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [
"either",
]
diff --git a/ui/backend/src/db.rs b/ui/backend/src/db.rs
index 56d422ab..b08d8ebe 100644
--- a/ui/backend/src/db.rs
+++ b/ui/backend/src/db.rs
@@ -36,7 +36,7 @@ pub struct GlobalStats {
pub last_30d: u64,
}
-#[derive(Serialize)]
+#[derive(Serialize, Debug)]
pub struct UIHistory {
pub id: String,
/// When the command was run.
diff --git a/ui/backend/src/main.rs b/ui/backend/src/main.rs
index cff9558a..13e02c98 100644
--- a/ui/backend/src/main.rs
+++ b/ui/backend/src/main.rs
@@ -30,6 +30,8 @@ struct HomeInfo {
pub history_count: u64,
pub username: Option<String>,
pub last_sync: Option<String>,
+ pub top_commands: Vec<(String, u64)>,
+ pub recent_commands: Vec<UIHistory>,
}
#[tauri::command]
@@ -138,6 +140,8 @@ async fn home_info() -> Result<HomeInfo, String> {
let sqlite_store = SqliteStore::new(record_store_path, settings.local_timeout)
.await
.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 last_sync = Settings::last_sync()
.map_err(|e| e.to_string())?
@@ -150,12 +154,20 @@ async fn home_info() -> Result<HomeInfo, String> {
.await
.map_err(|e| e.to_string())?;
+
+ let history = db.list(None, None).await?;
+ let stats = stats::compute(&settings, &history, 10, 1).map_or(vec![], |stats|stats.top[0..5].to_vec()).iter().map(|(commands, count)| (commands.join(" "), *count as u64)).collect();
+ let recent = if history.len() > 5 {history[0..5].to_vec()} else {vec![]};
+ let recent = recent.into_iter().map(|h|h.into()).collect();
+
let info = if !settings.logged_in() {
HomeInfo {
username: None,
last_sync: None,
record_count,
history_count,
+ top_commands: stats,
+ recent_commands: recent,
}
} else {
let client = atuin_client::api_client::Client::new(
@@ -176,6 +188,8 @@ async fn home_info() -> Result<HomeInfo, String> {
last_sync: Some(last_sync.to_string()),
record_count,
history_count,
+ top_commands: stats,
+ recent_commands: recent,
}
};