From a392a04c83b4e0a8050066280f7efc74d182bcab Mon Sep 17 00:00:00 2001 From: metamuffin Date: Fri, 10 Jun 2022 10:00:06 +0200 Subject: blub --- src/condition.rs | 26 ++++++-------------------- src/interface.rs | 5 +++++ src/main.rs | 30 ++++++++++++++++++++++++++++++ src/protocol.rs | 16 ++++++++-------- 4 files changed, 49 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/condition.rs b/src/condition.rs index c7be56c..bc1b3ec 100644 --- a/src/condition.rs +++ b/src/condition.rs @@ -6,6 +6,7 @@ use Direction::*; use Edge::*; #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] pub enum Condition { From(Box), @@ -27,6 +28,7 @@ pub enum Condition { } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] pub enum Property { Year, Monthofyear, @@ -73,16 +75,10 @@ impl Condition { .iter() .map(|c| c.find(Start, dir, from)) .reduce(|a, b| Some(max(a?, b?)))?; - let first_end = - cs.iter() - .map(|c| c.find(End, dir, from)) - .reduce(|a, b| match a { - Some(a) => match b { - Some(b) => Some(min(a, b)), - None => None, - }, - None => None, - })?; + let first_end = cs + .iter() + .map(|c| c.find(End, dir, from)) + .reduce(|a, b| Some(min(a?, b?)))?; match last_start { Some(start) => match first_end { Some(end) => { @@ -92,7 +88,6 @@ impl Condition { End => end, }); } else { - println!("{:?} {:?}", start, end); from = start - Duration::seconds(10); // TODO proper fix } } @@ -155,15 +150,6 @@ impl Condition { NaiveTime::from_hms(0, 0, 0), )) } else { - println!( - "{:?}", - ( - from.year() + (rollover + dir_off + 1) as i32, - value as u32 + 1, - rollover, - dir_off - ) - ); Some(NaiveDateTime::new( NaiveDate::from_ymd( from.year() + (rollover + dir_off + 1) as i32, diff --git a/src/interface.rs b/src/interface.rs index 568c450..0020736 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -34,6 +34,11 @@ fn handle_connection( ) -> io::Result<()> { let mut reader = BufReader::new(stream.try_clone()?); let (responder, responses) = crossbeam_channel::unbounded(); + responder + .send(ClientboundPacket::Handshake { + version: env!("CARGO_PKG_VERSION").to_string(), + }) + .unwrap(); thread::spawn(move || { for m in responses { debug!("{id} -> {m:?}"); diff --git a/src/main.rs b/src/main.rs index d237df0..e447202 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,11 @@ use interface::network_loop; use protocol::{ClientboundPacket, ServerboundPacket}; use std::time::Duration; +use crate::{ + condition::{Condition, Property}, + protocol::Task, +}; + fn main() { let (s, r) = crossbeam_channel::unbounded(); std::thread::spawn(move || network_loop(s)); @@ -17,6 +22,31 @@ fn main_loop(packets: Receiver<(u32, ServerboundPacket, Sender { + let _ = responder.send(ClientboundPacket::DownloadResponse(vec![Task { + name: "blub".to_string(), + description: "blob".to_string(), + tags: vec![], + priority: 69.0, + completed: None, + scheduled: None, + occurence: Some(Condition::And(vec![ + Condition::Equal { + modulus: None, + prop: Property::Monthofyear, + value: 1, + }, + Condition::Equal { + modulus: None, + prop: Property::Hour, + value: 12, + }, + ])), + deadline: None, + }])); + } + } } std::thread::sleep(Duration::from_secs_f64(10.0 / 30.0)); } diff --git a/src/protocol.rs b/src/protocol.rs index e7527eb..af89263 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -18,15 +18,15 @@ pub enum ServerboundPacket { #[derive(Debug, Serialize, Deserialize)] pub struct Task { - name: String, - description: String, + pub name: String, + pub description: String, - tags: Vec, - priority: f64, + pub tags: Vec, + pub priority: f64, - completed: u64, - scheduled: u64, + pub completed: Option, + pub scheduled: Option, - occurence: Option, - deadline: Option, + pub occurence: Option, + pub deadline: Option, } -- cgit v1.2.3-70-g09d2