aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml3
-rw-r--r--protocol.d.ts14
-rw-r--r--src/condition.rs26
-rw-r--r--src/interface.rs5
-rw-r--r--src/main.rs30
-rw-r--r--src/protocol.rs16
7 files changed, 56 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 73eb781..bcb7a9f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -36,7 +36,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "calender-thing"
-version = "0.1.0"
+version = "0.1.1"
dependencies = [
"anyhow",
"chrono",
diff --git a/Cargo.toml b/Cargo.toml
index b3eb94a..2008cc8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "calender-thing"
-version = "0.1.0"
+version = "0.1.1"
edition = "2021"
[dependencies]
@@ -11,4 +11,3 @@ env_logger = "0.9.0"
crossbeam-channel = "0.5.4"
serde_json = "1.0.81"
chrono = "0.4.19"
-
diff --git a/protocol.d.ts b/protocol.d.ts
index 16f45d8..79949b8 100644
--- a/protocol.d.ts
+++ b/protocol.d.ts
@@ -45,15 +45,11 @@ interface Task {
*/
// should only have one property
-interface Condition {
- from: Condition
-
- or: Condition[]
- and: Condition[]
-
- equal?: { prop: Thing, value: number, mod?: number }
- range?: { prop: Thing, min: number, max: number, mod?: number }
-}
+export type Condition = { from?: Condition }
+ | { or?: Condition[] }
+ | { and?: Condition[] }
+ | { equal?: { prop: Thing, value: number, mod?: number } }
+ | { range?: { prop: Thing, min: number, max: number, mod?: number } }
type Thing = "year"
| "monthofyear"
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<Condition>),
@@ -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<ClientboundPacket
loop {
for (client_id, packet, responder) in packets.try_iter() {
println!("{:?}, {:?}, {:?}", client_id, packet, responder);
+ match packet {
+ ServerboundPacket::Download => {
+ 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<String>,
- priority: f64,
+ pub tags: Vec<String>,
+ pub priority: f64,
- completed: u64,
- scheduled: u64,
+ pub completed: Option<u64>,
+ pub scheduled: Option<u64>,
- occurence: Option<Condition>,
- deadline: Option<Condition>,
+ pub occurence: Option<Condition>,
+ pub deadline: Option<Condition>,
}