Added automatic retry + updated dependencies

This commit is contained in:
Silas Bartha 2024-12-11 03:36:50 -05:00
parent 4c99274340
commit 070ae7a6ac
4 changed files with 610 additions and 536 deletions

1099
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
[package] [package]
name = "pomd" name = "pomd"
version = "1.4.1" version = "1.5.0"
description = "A simple configurable pomodoro D-Bus daemon" description = "A simple configurable pomodoro D-Bus daemon"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"
@ -9,8 +9,8 @@ repository = "https://github.com/exvacuum/pomd"
[dependencies] [dependencies]
notify-rust = "4" notify-rust = "4"
zbus = "3.14.1" zbus = "5.1"
async-std = { version = "1.12.0", features = ["attributes"] } async-std = { version = "1.12", features = ["attributes"] }
pausable_clock = "1.0.1" pausable_clock = "1.0"
confy = "0.5.1" confy = "0.6"
serde = "1.0.193" serde = "1.0"

View File

@ -1,5 +1,5 @@
use std::{sync::{Arc, Mutex}, time::Duration}; use std::{sync::{Arc, Mutex}, time::Duration};
use zbus::dbus_interface; use zbus::interface;
use crate::pomd::Pomd; use crate::pomd::Pomd;
@ -17,7 +17,7 @@ impl PomdInterface {
} }
} }
#[dbus_interface(name = "dev.exvacuum.pomd")] #[interface(name = "dev.exvacuum.pomd")]
impl PomdInterface { impl PomdInterface {
fn get_remaining(&self) -> Duration { fn get_remaining(&self) -> Duration {
let data = self.state.lock().unwrap(); let data = self.state.lock().unwrap();

View File

@ -1,6 +1,6 @@
use std::sync::{Mutex, Arc}; use std::sync::{Arc, Mutex};
use std::{thread::sleep, time::Duration}; use std::{thread::sleep, time::Duration};
use zbus::{ConnectionBuilder, Result}; use zbus::{connection::Builder, Result};
use crate::config::PomdConfig; use crate::config::PomdConfig;
use crate::interface::PomdInterface; use crate::interface::PomdInterface;
@ -14,12 +14,27 @@ mod pomd;
async fn main() -> Result<()> { async fn main() -> Result<()> {
let config: PomdConfig = confy::load("pomd", "config").expect("Failed to load config!"); let config: PomdConfig = confy::load("pomd", "config").expect("Failed to load config!");
let pomd = Arc::new(Mutex::new(Pomd::new(config))); let pomd = Arc::new(Mutex::new(Pomd::new(config)));
let mut _connection;
loop {
let pomd_interface = PomdInterface::new(pomd.clone()); let pomd_interface = PomdInterface::new(pomd.clone());
let _connection = ConnectionBuilder::session()? match Builder::session()?
.name("dev.exvacuum.pomd")? .name("dev.exvacuum.pomd")?
.serve_at("/dev/exvacuum/pomd", pomd_interface)? .serve_at("/dev/exvacuum/pomd", pomd_interface)?
.build() .build()
.await?; .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 { loop {
pomd.lock().unwrap().update(); pomd.lock().unwrap().update();
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));