2023-04-03 13:46:04 -07:00
|
|
|
//! Theseus profile management interface
|
2023-06-30 08:11:32 -07:00
|
|
|
|
2023-04-03 13:46:04 -07:00
|
|
|
pub use crate::{
|
|
|
|
|
State,
|
2025-05-02 04:51:17 -05:00
|
|
|
state::{Hooks, MemorySettings, Profile, Settings, WindowSize},
|
2023-04-03 13:46:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Gets entire settings
|
|
|
|
|
#[tracing::instrument]
|
|
|
|
|
pub async fn get() -> crate::Result<Settings> {
|
|
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
let settings = Settings::get(&state.pool).await?;
|
|
|
|
|
Ok(settings)
|
2023-04-03 13:46:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Sets entire settings
|
|
|
|
|
#[tracing::instrument]
|
|
|
|
|
pub async fn set(settings: Settings) -> crate::Result<()> {
|
|
|
|
|
let state = State::get().await?;
|
2024-07-24 11:03:19 -07:00
|
|
|
settings.update(&state.pool).await?;
|
2023-07-21 20:16:07 -07:00
|
|
|
|
2023-04-03 13:46:04 -07:00
|
|
|
Ok(())
|
2023-04-05 10:07:59 -07:00
|
|
|
}
|
2024-08-16 23:20:11 -07:00
|
|
|
|
|
|
|
|
#[tracing::instrument]
|
|
|
|
|
pub async fn cancel_directory_change() -> crate::Result<()> {
|
2025-07-02 21:32:15 +01:00
|
|
|
// This is called to handle state initialization errors due to folder migrations
|
|
|
|
|
// failing, so fetching a DB connection pool from `State::get` is not reliable here
|
2024-08-16 23:20:11 -07:00
|
|
|
let pool = crate::state::db::connect().await?;
|
|
|
|
|
let mut settings = Settings::get(&pool).await?;
|
|
|
|
|
|
|
|
|
|
if let Some(prev_custom_dir) = settings.prev_custom_dir {
|
|
|
|
|
settings.prev_custom_dir = None;
|
|
|
|
|
settings.custom_dir = Some(prev_custom_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings.update(&pool).await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|