2023-05-03 09:02:34 -07:00
|
|
|
use crate::api::Result;
|
2023-07-26 20:33:03 -07:00
|
|
|
use theseus::{
|
|
|
|
|
logs::{self, Logs},
|
|
|
|
|
prelude::ProfilePathId,
|
|
|
|
|
};
|
2023-05-03 09:02:34 -07:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
A log is a struct containing the datetime string, stdout, and stderr, as follows:
|
|
|
|
|
|
|
|
|
|
pub struct Logs {
|
|
|
|
|
pub datetime_string: String,
|
|
|
|
|
pub stdout: String,
|
|
|
|
|
pub stderr: String,
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-28 09:58:58 -07:00
|
|
|
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
|
|
|
|
|
tauri::plugin::Builder::new("logs")
|
|
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
logs_get_logs,
|
|
|
|
|
logs_get_logs_by_datetime,
|
|
|
|
|
logs_get_output_by_datetime,
|
|
|
|
|
logs_delete_logs,
|
|
|
|
|
logs_delete_logs_by_datetime,
|
|
|
|
|
])
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 09:02:34 -07:00
|
|
|
/// Get all Logs for a profile, sorted by datetime
|
|
|
|
|
#[tauri::command]
|
2023-05-17 16:05:20 -04:00
|
|
|
pub async fn logs_get_logs(
|
2023-07-26 20:33:03 -07:00
|
|
|
profile_path: ProfilePathId,
|
2023-05-17 16:05:20 -04:00
|
|
|
clear_contents: Option<bool>,
|
|
|
|
|
) -> Result<Vec<Logs>> {
|
2023-07-26 20:33:03 -07:00
|
|
|
let val = logs::get_logs(profile_path, clear_contents).await?;
|
2023-05-17 16:05:20 -04:00
|
|
|
|
|
|
|
|
Ok(val)
|
2023-05-03 09:02:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get a Log struct for a profile by profile id and datetime string
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn logs_get_logs_by_datetime(
|
2023-07-26 20:33:03 -07:00
|
|
|
profile_path: ProfilePathId,
|
2023-05-03 09:02:34 -07:00
|
|
|
datetime_string: String,
|
|
|
|
|
) -> Result<Logs> {
|
2023-07-26 20:33:03 -07:00
|
|
|
Ok(logs::get_logs_by_datetime(profile_path, datetime_string).await?)
|
2023-05-03 09:02:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Get the stdout for a profile by profile id and datetime string
|
|
|
|
|
#[tauri::command]
|
2023-06-19 14:59:06 -07:00
|
|
|
pub async fn logs_get_output_by_datetime(
|
2023-07-26 20:33:03 -07:00
|
|
|
profile_path: ProfilePathId,
|
2023-05-03 09:02:34 -07:00
|
|
|
datetime_string: String,
|
|
|
|
|
) -> Result<String> {
|
2023-07-21 20:16:07 -07:00
|
|
|
let profile_path = if let Some(p) =
|
2023-07-26 20:33:03 -07:00
|
|
|
crate::profile::get(&profile_path, None).await?
|
2023-07-21 20:16:07 -07:00
|
|
|
{
|
|
|
|
|
p.profile_id()
|
|
|
|
|
} else {
|
|
|
|
|
return Err(theseus::Error::from(
|
2023-07-26 20:33:03 -07:00
|
|
|
theseus::ErrorKind::UnmanagedProfileError(profile_path.to_string()),
|
2023-07-21 20:16:07 -07:00
|
|
|
)
|
|
|
|
|
.into());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(logs::get_output_by_datetime(&profile_path, &datetime_string).await?)
|
2023-05-03 09:02:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Delete all logs for a profile by profile id
|
|
|
|
|
#[tauri::command]
|
2023-07-26 20:33:03 -07:00
|
|
|
pub async fn logs_delete_logs(profile_path: ProfilePathId) -> Result<()> {
|
|
|
|
|
Ok(logs::delete_logs(profile_path).await?)
|
2023-05-03 09:02:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Delete a log for a profile by profile id and datetime string
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn logs_delete_logs_by_datetime(
|
2023-07-26 20:33:03 -07:00
|
|
|
profile_path: ProfilePathId,
|
2023-05-03 09:02:34 -07:00
|
|
|
datetime_string: String,
|
|
|
|
|
) -> Result<()> {
|
2023-07-26 20:33:03 -07:00
|
|
|
Ok(logs::delete_logs_by_datetime(profile_path, &datetime_string).await?)
|
2023-05-03 09:02:34 -07:00
|
|
|
}
|