diff --git a/Cargo.lock b/Cargo.lock index 21f1b7b..1d19495 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2368,16 +2368,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] -name = "tubest" +name = "tubest-common" +version = "0.1.0" +dependencies = [ + "serde", +] + +[[package]] +name = "tubest-driver" version = "0.1.0" dependencies = [ "futures", "libmpv", + "tokio", + "tokio-stream", + "tubest-common", +] + +[[package]] +name = "tubest-matrix" +version = "0.1.0" +dependencies = [ "matrix-sdk", "serde", "serde_json", "tokio", - "tokio-stream", + "tubest-common", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7a7b752..cbc97f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,17 @@ -[package] -name = "tubest" -version = "0.1.0" -edition = "2021" +[workspace] +resolver = "2" +members = [ + "common", + "matrix", + "driver", +] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] +[workspace.dependencies] +tubest-common = { path = "common" } futures = { version = "0.3" } libmpv = { git = "https://github.com/ParadoxSpiral/libmpv-rs", rev = "3e6c389b716f52a595cc5e8e3fa1f96cb76b3de7" } matrix-sdk = { version = "0.6" } -tokio = { version = "1", features = ["full"] } -tokio-stream = { version = "0.1", features = ["full"] } serde = { version = "1" } serde_json = { version = "1" } +tokio = { version = "1", features = ["full"] } +tokio-stream = { version = "0.1", features = ["full"] } diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..d15aad5 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "tubest-common" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde.workspace = true diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..d0d62cc --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1 @@ +pub const PROG_NAME: &str = "tubest"; diff --git a/driver/Cargo.toml b/driver/Cargo.toml new file mode 100644 index 0000000..83237c2 --- /dev/null +++ b/driver/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "tubest-driver" +version = "0.1.0" +edition = "2021" + +[dependencies] +tubest-common.workspace = true +futures.workspace = true +libmpv.workspace = true +tokio.workspace = true +tokio-stream.workspace = true diff --git a/src/bin/main.rs b/driver/src/bin/driver.rs similarity index 100% rename from src/bin/main.rs rename to driver/src/bin/driver.rs diff --git a/matrix/Cargo.toml b/matrix/Cargo.toml new file mode 100644 index 0000000..b1f7d1c --- /dev/null +++ b/matrix/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "tubest-matrix" +version = "0.1.0" +edition = "2021" + +[dependencies] +tubest-common.workspace = true +matrix-sdk.workspace = true +serde.workspace = true +serde_json.workspace = true +tokio.workspace = true diff --git a/src/bin/matrix.rs b/matrix/src/bin/matrix.rs similarity index 95% rename from src/bin/matrix.rs rename to matrix/src/bin/matrix.rs index 3a860ca..c5c6181 100644 --- a/src/bin/matrix.rs +++ b/matrix/src/bin/matrix.rs @@ -9,6 +9,7 @@ use matrix_sdk::{ use serde::{Deserialize, Serialize}; use std::io::Write; use std::path::PathBuf; +use tubest_common::PROG_NAME; #[derive(Serialize, Deserialize)] struct Config { @@ -22,7 +23,7 @@ impl Config { fn path() -> PathBuf { #[allow(deprecated)] let home = std::env::home_dir().expect("no coats and no home"); - home.join(".config").join("tubest").join("matrix.json") + home.join(".config").join(PROG_NAME).join("matrix.json") } fn read() -> Self { let path = Self::path(); @@ -57,7 +58,7 @@ async fn main() -> Result<(), Box> { client .login_username(&cfg.user, cfg.password.as_ref().unwrap()) .device_id(session.device_id.as_str()) - .initial_device_display_name("tubest") + .initial_device_display_name(PROG_NAME) .request_refresh_token() .send() .await?; @@ -68,7 +69,7 @@ async fn main() -> Result<(), Box> { if let Some(ref password) = cfg.password { client .login_username(&cfg.user, password) - .initial_device_display_name("tubest") + .initial_device_display_name(PROG_NAME) .request_refresh_token() .send() .await?; @@ -80,7 +81,7 @@ async fn main() -> Result<(), Box> { .devices .into_iter() .filter(|d| { - d.display_name.clone().unwrap_or_default().as_str() == "tubest" + d.display_name.clone().unwrap_or_default().as_str() == PROG_NAME && d.device_id != client.device_id().unwrap() }) .map(|d| d.device_id)