mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-28 19:23:47 +01:00
fix(gui): do not hardcode db path (#2309)
* feat(gui/backend): add cli_settings tauri command * chore(gui/backend): overdue cargo fmt * fix(gui): use configured db path, not hardcoded
This commit is contained in:
parent
3cf52990e4
commit
128891f53e
9
ui/backend/Cargo.lock
generated
9
ui/backend/Cargo.lock
generated
@ -351,7 +351,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atuin-client"
|
name = "atuin-client"
|
||||||
version = "18.4.0-beta.2"
|
version = "18.4.0-beta.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"atuin-common",
|
"atuin-common",
|
||||||
@ -404,7 +404,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atuin-common"
|
name = "atuin-common"
|
||||||
version = "18.4.0-beta.2"
|
version = "18.4.0-beta.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"directories",
|
"directories",
|
||||||
@ -424,7 +424,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atuin-dotfiles"
|
name = "atuin-dotfiles"
|
||||||
version = "18.4.0-beta.2"
|
version = "18.4.0-beta.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atuin-client",
|
"atuin-client",
|
||||||
"atuin-common",
|
"atuin-common",
|
||||||
@ -438,7 +438,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atuin-history"
|
name = "atuin-history"
|
||||||
version = "18.4.0-beta.2"
|
version = "18.4.0-beta.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"atuin-client",
|
"atuin-client",
|
||||||
@ -1108,6 +1108,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
"serde",
|
||||||
"signal-hook",
|
"signal-hook",
|
||||||
"signal-hook-mio",
|
"signal-hook-mio",
|
||||||
"winapi",
|
"winapi",
|
||||||
|
@ -116,8 +116,7 @@ async fn login(username: String, password: String, key: String) -> Result<String
|
|||||||
async fn logout() -> Result<(), String> {
|
async fn logout() -> Result<(), String> {
|
||||||
let settings = Settings::new().map_err(|e| e.to_string())?;
|
let settings = Settings::new().map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
atuin_client::logout::logout(&settings)
|
atuin_client::logout::logout(&settings).map_err(|e| e.to_string())?;
|
||||||
.map_err(|e| e.to_string())?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -154,10 +153,17 @@ async fn home_info() -> Result<HomeInfo, String> {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
|
||||||
let history = db.list(None, None).await?;
|
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 stats = stats::compute(&settings, &history, 10, 1)
|
||||||
let recent = if history.len() > 5 {history[0..5].to_vec()} else {vec![]};
|
.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 recent = recent.into_iter().map(|h| h.into()).collect();
|
||||||
|
|
||||||
let info = if !settings.logged_in() {
|
let info = if !settings.logged_in() {
|
||||||
@ -257,6 +263,12 @@ async fn prefix_search(query: &str) -> Result<Vec<String>, String> {
|
|||||||
Ok(commands)
|
Ok(commands)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn cli_settings() -> Result<Settings, String> {
|
||||||
|
let settings = Settings::new().map_err(|e| e.to_string())?;
|
||||||
|
Ok(settings)
|
||||||
|
}
|
||||||
|
|
||||||
fn show_window(app: &AppHandle) {
|
fn show_window(app: &AppHandle) {
|
||||||
let windows = app.webview_windows();
|
let windows = app.webview_windows();
|
||||||
|
|
||||||
@ -284,6 +296,7 @@ fn main() {
|
|||||||
logout,
|
logout,
|
||||||
register,
|
register,
|
||||||
history_calendar,
|
history_calendar,
|
||||||
|
cli_settings,
|
||||||
run::pty::pty_open,
|
run::pty::pty_open,
|
||||||
run::pty::pty_write,
|
run::pty::pty_write,
|
||||||
run::pty::pty_resize,
|
run::pty::pty_resize,
|
||||||
@ -298,16 +311,17 @@ fn main() {
|
|||||||
dotfiles::vars::delete_var,
|
dotfiles::vars::delete_var,
|
||||||
dotfiles::vars::set_var,
|
dotfiles::vars::set_var,
|
||||||
])
|
])
|
||||||
.plugin(tauri_plugin_sql::Builder::default().add_migrations("sqlite:runbooks.db", run::migrations::migrations()).build())
|
.plugin(
|
||||||
|
tauri_plugin_sql::Builder::default()
|
||||||
|
.add_migrations("sqlite:runbooks.db", run::migrations::migrations())
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
.plugin(tauri_plugin_http::init())
|
.plugin(tauri_plugin_http::init())
|
||||||
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
|
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
|
||||||
let _ = show_window(app);
|
let _ = show_window(app);
|
||||||
|
|
||||||
}))
|
}))
|
||||||
.manage(state::AtuinState::default())
|
.manage(state::AtuinState::default())
|
||||||
.setup(|app|{
|
.setup(|app| Ok(()))
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
@ -90,13 +90,11 @@ pub(crate) async fn pty_kill(
|
|||||||
|
|
||||||
match pty {
|
match pty {
|
||||||
Some(pty) => {
|
Some(pty) => {
|
||||||
|
|
||||||
pty.kill_child().await.map_err(|e| e.to_string())?;
|
pty.kill_child().await.map_err(|e| e.to_string())?;
|
||||||
println!("RIP {pid:?}");
|
println!("RIP {pid:?}");
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import Database from "@tauri-apps/plugin-sql";
|
import Database from "@tauri-apps/plugin-sql";
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
@ -122,9 +123,8 @@ interface Sync {
|
|||||||
export async function inspectCommandHistory(
|
export async function inspectCommandHistory(
|
||||||
h: ShellHistory,
|
h: ShellHistory,
|
||||||
): Promise<InspectHistory> {
|
): Promise<InspectHistory> {
|
||||||
const db = await Database.load(
|
const settings: Settings = await invoke("cli_settings");
|
||||||
"sqlite:/Users/ellie/.local/share/atuin/history.db",
|
const db = await Database.load("sqlite:" + settings.db_path);
|
||||||
);
|
|
||||||
|
|
||||||
let other: any[] = await db.select(
|
let other: any[] = await db.select(
|
||||||
"select * from history where command=?1 order by timestamp desc",
|
"select * from history where command=?1 order by timestamp desc",
|
||||||
@ -151,9 +151,8 @@ export async function inspectCommandHistory(
|
|||||||
export async function inspectDirectoryHistory(
|
export async function inspectDirectoryHistory(
|
||||||
h: ShellHistory,
|
h: ShellHistory,
|
||||||
): Promise<InspectHistory> {
|
): Promise<InspectHistory> {
|
||||||
const db = await Database.load(
|
const settings: Settings = await invoke("cli_settings");
|
||||||
"sqlite:/Users/ellie/.local/share/atuin/history.db",
|
const db = await Database.load("sqlite:" + settings.db_path);
|
||||||
);
|
|
||||||
|
|
||||||
let other: any[] = await db.select(
|
let other: any[] = await db.select(
|
||||||
"select * from history where cwd=?1 order by timestamp desc",
|
"select * from history where cwd=?1 order by timestamp desc",
|
||||||
|
Loading…
Reference in New Issue
Block a user