Add basic structure
This commit is contained in:
parent
5b38d809aa
commit
ed480f03d3
89
Cargo.lock
generated
89
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
22
src/main.rs
22
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<dyn std::error::Error>> {
|
||||
// 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<dyn std::error::Error>> {
|
|||
panic!("Lost connection to D-Bus: {}", err);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
let (sender, receiver) = channel(1024);
|
||||
|
||||
let tiles: Vec<Arc<dyn Tile>> = vec![Arc::new(tiles::Time::new(0, sender.clone()))];
|
||||
|
||||
for tile in tiles {
|
||||
tile.spawn();
|
||||
}
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
|
63
src/tile.rs
Normal file
63
src/tile.rs
Normal file
|
@ -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<str>,
|
||||
short_text: Option<Box<str>>,
|
||||
color: Option<Box<str>>,
|
||||
#[serde(rename = "background")]
|
||||
background_color: Option<Box<str>>,
|
||||
#[serde(rename = "border")]
|
||||
border_color: Option<Box<str>>,
|
||||
border_top: Option<u32>,
|
||||
border_right: Option<u32>,
|
||||
border_bottom: Option<u32>,
|
||||
border_left: Option<u32>,
|
||||
min_width: Option<u32>,
|
||||
align: Option<Alignment>,
|
||||
name: Box<str>,
|
||||
instance: Box<str>,
|
||||
urgent: Option<bool>,
|
||||
separator: Option<bool>,
|
||||
separator_block_width: Option<u32>,
|
||||
markup: Option<Markup>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TileData {
|
||||
sender_id: usize,
|
||||
block: Block,
|
||||
}
|
||||
|
||||
pub trait Tile: Send {
|
||||
fn spawn(self: Arc<Self>) -> JoinHandle<()>;
|
||||
}
|
2
src/tiles/mod.rs
Normal file
2
src/tiles/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod time;
|
||||
pub use time::Time;
|
34
src/tiles/time.rs
Normal file
34
src/tiles/time.rs
Normal file
|
@ -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<TileData>,
|
||||
instance: Box<str>,
|
||||
}
|
||||
|
||||
impl Time {
|
||||
pub fn new(sender_id: usize, sender: Sender<TileData>) -> 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<Self>) -> JoinHandle<()> {
|
||||
tokio::spawn(async {
|
||||
let instance = self;
|
||||
instance.run().await
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue