Add api to get and set the frontend state
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
aa568a9365
commit
e71ee47e50
@ -0,0 +1,41 @@
|
||||
use crate::client_api::error::ApiResult;
|
||||
use crate::client_api::IPCApi;
|
||||
use crate::types::repo::FrontendState;
|
||||
use bromine::prelude::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RepoApi {
|
||||
ctx: PooledContext,
|
||||
}
|
||||
|
||||
impl IPCApi for RepoApi {
|
||||
fn namespace() -> &'static str {
|
||||
"repo"
|
||||
}
|
||||
|
||||
fn ctx(&self) -> PoolGuard<Context> {
|
||||
self.ctx.acquire()
|
||||
}
|
||||
}
|
||||
|
||||
impl RepoApi {
|
||||
pub fn new(ctx: PooledContext) -> Self {
|
||||
Self { ctx }
|
||||
}
|
||||
|
||||
/// Returns the state of the frontend that is stored in the repo
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn get_frontend_state(&self) -> ApiResult<FrontendState> {
|
||||
let state = self.emit_and_get("frontend_state", ()).await?;
|
||||
|
||||
Ok(state)
|
||||
}
|
||||
|
||||
/// Sets the state of the frontend
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn set_frontend_state(&self, state: FrontendState) -> ApiResult<()> {
|
||||
self.emit("set_frontend_state", state).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
pub mod files;
|
||||
pub mod identifier;
|
||||
pub mod misc;
|
||||
pub mod repo;
|
||||
pub mod tags;
|
@ -0,0 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct FrontendState {
|
||||
pub state: String,
|
||||
}
|
Loading…
Reference in New Issue