Private
Public Access
1
0

daemon: start working on events. notes:

Probably need to make the locking mechanism more granular. Only lock the
database during db writes, see if we can do multiple readers and a
single writer. Otherwise, the daemon will not be able to service
requests while an event is being handled, which is not good.
This commit is contained in:
2025-04-25 21:42:29 -07:00
parent 82192ffbe5
commit ef74df9f28
7 changed files with 90 additions and 46 deletions

View File

@@ -1,6 +1,7 @@
mod settings;
use settings::Settings;
use std::sync::mpsc;
use directories::ProjectDirs;
use std::path::PathBuf;
use anyhow::Result;
@@ -19,6 +20,10 @@ use kordophone::api::{
TokenManagement,
};
pub enum Event {
SyncAllConversations,
}
#[derive(Debug, Error)]
pub enum DaemonError {
#[error("Client Not Configured")]
@@ -87,6 +92,16 @@ impl Daemon {
Ok(settings)
}
pub async fn handle_event(&mut self, event: Event) {
match event {
Event::SyncAllConversations => {
self.sync_all_conversations().await.unwrap_or_else(|e| {
log::error!("Error handling sync event: {}", e);
});
}
}
}
fn get_client(&mut self) -> Result<HTTPAPIClient> {
let settings = self.database.with_settings(|s|
Settings::from_db(s)
@@ -132,4 +147,3 @@ impl TokenManagement for &mut Daemon {
self.database.set_token(token);
}
}