daemon: scaffolding for settings / sync
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
use directories::ProjectDirs;
|
||||
use std::path::PathBuf;
|
||||
use anyhow::Result;
|
||||
|
||||
use thiserror::Error;
|
||||
use kordophone_db::{
|
||||
database::Database,
|
||||
settings::Settings,
|
||||
models::Conversation,
|
||||
};
|
||||
|
||||
use kordophone::api::http_client::HTTPAPIClient;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum DaemonError {
|
||||
#[error("Client Not Configured")]
|
||||
ClientNotConfigured,
|
||||
}
|
||||
|
||||
pub struct Daemon {
|
||||
pub version: String,
|
||||
database: Database,
|
||||
client: Option<HTTPAPIClient>,
|
||||
}
|
||||
|
||||
impl Daemon {
|
||||
@@ -23,17 +31,25 @@ impl Daemon {
|
||||
std::fs::create_dir_all(database_dir)?;
|
||||
|
||||
let database = Database::new(&database_path.to_string_lossy())?;
|
||||
Ok(Self { version: "0.1.0".to_string(), database })
|
||||
}
|
||||
|
||||
pub fn get_version(&self) -> String {
|
||||
self.version.clone()
|
||||
// TODO: Check to see if we have client settings in the database
|
||||
|
||||
|
||||
Ok(Self { version: "0.1.0".to_string(), database, client: None })
|
||||
}
|
||||
|
||||
pub fn get_conversations(&mut self) -> Vec<Conversation> {
|
||||
self.database.with_repository(|r| r.all_conversations().unwrap())
|
||||
}
|
||||
|
||||
pub fn sync_all_conversations(&mut self) -> Result<()> {
|
||||
let client = self.client
|
||||
.as_mut()
|
||||
.ok_or(DaemonError::ClientNotConfigured)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_database_path() -> PathBuf {
|
||||
if let Some(proj_dirs) = ProjectDirs::from("com", "kordophone", "kordophone") {
|
||||
let data_dir = proj_dirs.data_dir();
|
||||
|
||||
Reference in New Issue
Block a user