From ed480f03d3ba5ef1733660f992fdec736febba26 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sat, 30 May 2020 01:40:01 +0000 Subject: [PATCH] Add basic structure --- Cargo.lock | 89 +++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +++- src/main.rs | 22 +++++++++--- src/tile.rs | 63 +++++++++++++++++++++++++++++++++ src/tiles/mod.rs | 2 ++ src/tiles/time.rs | 34 ++++++++++++++++++ 6 files changed, 210 insertions(+), 6 deletions(-) create mode 100644 src/tile.rs create mode 100644 src/tiles/mod.rs create mode 100644 src/tiles/time.rs diff --git a/Cargo.lock b/Cargo.lock index c7fa417..7a612a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,6 +163,17 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "hermit-abi" version = "0.1.13" @@ -362,6 +373,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +[[package]] +name = "ppv-lite86" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" + [[package]] name = "proc-macro-hack" version = "0.5.16" @@ -392,6 +409,47 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.1.56" @@ -404,8 +462,10 @@ version = "0.1.0" dependencies = [ "dbus", "dbus-tokio", + "serde", "serde_json", "tokio", + "uuid", ] [[package]] @@ -419,6 +479,20 @@ name = "serde" version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99e7b308464d16b56eba9964e4972a3eee817760ab60d88c3f86e1fecb08204c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.110" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "818fbf6bfa9a42d3bfcaca148547aa00c7b915bec71d1757aa2d44ca68771984" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" @@ -511,6 +585,21 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +[[package]] +name = "uuid" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" +dependencies = [ + "rand", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "winapi" version = "0.2.8" diff --git a/Cargo.toml b/Cargo.toml index c50ce7e..dcf86c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,11 @@ edition = "2018" [dependencies] -tokio = { version = "0.2", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" + +uuid = { version = "0.8", features = [ "v4" ] } + +tokio = { version = "0.2", features = ["full"] } dbus-tokio = "0.5" dbus = "0.8" diff --git a/src/main.rs b/src/main.rs index 78797b0..94390f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,16 @@ -use dbus::nonblock::Proxy; -use dbus_tokio::connection; -use std::time::Duration; +pub mod tile; +pub mod tiles; + +use dbus_tokio::connection::new_session_sync; +use std::sync::Arc; +use tile::Tile; use tokio; +use tokio::sync::mpsc::channel; #[tokio::main] async fn main() -> Result<(), Box> { // We can't do much until we have a D-Bus connection so just do it synchronously - let (resource, conn) = connection::new_session_sync()?; + let (resource, conn) = new_session_sync()?; // Now start listening on our D-Bus connection tokio::spawn(async { @@ -14,5 +18,13 @@ async fn main() -> Result<(), Box> { panic!("Lost connection to D-Bus: {}", err); }); - Ok(()) + let (sender, receiver) = channel(1024); + + let tiles: Vec> = vec![Arc::new(tiles::Time::new(0, sender.clone()))]; + + for tile in tiles { + tile.spawn(); + } + + loop {} } diff --git a/src/tile.rs b/src/tile.rs new file mode 100644 index 0000000..50ea1ac --- /dev/null +++ b/src/tile.rs @@ -0,0 +1,63 @@ +use serde::Serialize; +use std::sync::Arc; +use tokio::task::JoinHandle; + +#[derive(Copy, Clone, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Alignment { + Left, + Center, + Right, +} + +impl Default for Alignment { + fn default() -> Self { + Self::Center + } +} + +#[derive(Copy, Clone, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Markup { + None, + Pango, +} + +impl Default for Markup { + fn default() -> Self { + Self::None + } +} + +#[derive(Clone, Serialize, Default)] +pub struct Block { + full_text: Box, + short_text: Option>, + color: Option>, + #[serde(rename = "background")] + background_color: Option>, + #[serde(rename = "border")] + border_color: Option>, + border_top: Option, + border_right: Option, + border_bottom: Option, + border_left: Option, + min_width: Option, + align: Option, + name: Box, + instance: Box, + urgent: Option, + separator: Option, + separator_block_width: Option, + markup: Option, +} + +#[derive(Clone)] +pub struct TileData { + sender_id: usize, + block: Block, +} + +pub trait Tile: Send { + fn spawn(self: Arc) -> JoinHandle<()>; +} diff --git a/src/tiles/mod.rs b/src/tiles/mod.rs new file mode 100644 index 0000000..1ae628f --- /dev/null +++ b/src/tiles/mod.rs @@ -0,0 +1,2 @@ +pub mod time; +pub use time::Time; diff --git a/src/tiles/time.rs b/src/tiles/time.rs new file mode 100644 index 0000000..d298722 --- /dev/null +++ b/src/tiles/time.rs @@ -0,0 +1,34 @@ +use crate::tile::{Block, Tile, TileData}; +use std::sync::Arc; +use tokio::sync::mpsc::Sender; +use tokio::task::JoinHandle; +use tokio::time; +use uuid::Uuid; + +pub struct Time { + sender_id: usize, + sender: Sender, + instance: Box, +} + +impl Time { + pub fn new(sender_id: usize, sender: Sender) -> Time { + let instance = Uuid::new_v4().to_string().into_boxed_str(); + Time { + sender_id, + sender, + instance, + } + } + + async fn run(&self) {} +} + +impl Tile for Time { + fn spawn(self: Arc) -> JoinHandle<()> { + tokio::spawn(async { + let instance = self; + instance.run().await + }) + } +}