aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/interface.rs4
-rw-r--r--src/main.rs31
2 files changed, 25 insertions, 10 deletions
diff --git a/src/interface.rs b/src/interface.rs
index 870162c..205bb43 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -1,5 +1,5 @@
use std::{sync::{Arc, Mutex}, time::Duration};
-use zbus::dbus_interface;
+use zbus::interface;
use crate::pomd::Pomd;
@@ -17,7 +17,7 @@ impl PomdInterface {
}
}
-#[dbus_interface(name = "dev.exvacuum.pomd")]
+#[interface(name = "dev.exvacuum.pomd")]
impl PomdInterface {
fn get_remaining(&self) -> Duration {
let data = self.state.lock().unwrap();
diff --git a/src/main.rs b/src/main.rs
index 3a8bcb0..97e28b5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
-use std::sync::{Mutex, Arc};
+use std::sync::{Arc, Mutex};
use std::{thread::sleep, time::Duration};
-use zbus::{ConnectionBuilder, Result};
+use zbus::{connection::Builder, Result};
use crate::config::PomdConfig;
use crate::interface::PomdInterface;
@@ -14,12 +14,27 @@ mod pomd;
async fn main() -> Result<()> {
let config: PomdConfig = confy::load("pomd", "config").expect("Failed to load config!");
let pomd = Arc::new(Mutex::new(Pomd::new(config)));
- let pomd_interface = PomdInterface::new(pomd.clone());
- let _connection = ConnectionBuilder::session()?
- .name("dev.exvacuum.pomd")?
- .serve_at("/dev/exvacuum/pomd", pomd_interface)?
- .build()
- .await?;
+ let mut _connection;
+ loop {
+ let pomd_interface = PomdInterface::new(pomd.clone());
+ match Builder::session()?
+ .name("dev.exvacuum.pomd")?
+ .serve_at("/dev/exvacuum/pomd", pomd_interface)?
+ .build()
+ .await
+ {
+ Ok(connection) => {
+ _connection = connection;
+ break;
+ }
+ Err(e) => {
+ eprintln!("Failed to start D-Bus session: {e:?}");
+ eprintln!("Trying again in 10 seconds...");
+ sleep(Duration::from_secs(10));
+ continue;
+ }
+ }
+ }
loop {
pomd.lock().unwrap().update();
sleep(Duration::from_millis(100));