diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 17f94dd..b07d312 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -69,8 +69,10 @@ dependencies = [ "dirs", "jsonwebtoken", "lazy_static", + "log", "paho-mqtt", "reqwest", + "rumqttc", "serde", "serde_json", "tauri", @@ -853,6 +855,17 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2714,7 +2727,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", @@ -2769,6 +2782,24 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rumqttc" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1568e15fab2d546f940ed3a21f48bbbd1c494c90c99c4481339364a497f94a9" +dependencies = [ + "bytes", + "flume", + "futures-util", + "log", + "rustls-native-certs", + "rustls-pemfile 2.1.1", + "rustls-webpki", + "thiserror", + "tokio", + "tokio-rustls", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2797,6 +2828,33 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.22.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" +dependencies = [ + "log", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" +dependencies = [ + "openssl-probe", + "rustls-pemfile 2.1.1", + "rustls-pki-types", + "schannel", + "security-framework", +] + [[package]] name = "rustls-pemfile" version = "1.0.4" @@ -2806,6 +2864,33 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f48172685e6ff52a556baa527774f61fcaa884f59daf3375c62a3f1cd2549dab" +dependencies = [ + "base64 0.21.7", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ede67b28608b4c60685c7d54122d4400d90f62b40caee7700e700380a390fa8" + +[[package]] +name = "rustls-webpki" +version = "0.102.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -3134,6 +3219,9 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] [[package]] name = "stable_deref_trait" @@ -3182,6 +3270,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "1.0.109" @@ -3648,9 +3742,21 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.48.0", ] +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" @@ -3661,6 +3767,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -4699,3 +4816,9 @@ dependencies = [ "linux-raw-sys", "rustix", ] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 7975840..51a8aff 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -20,10 +20,12 @@ serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.6.0", features = [ "dialog-confirm", "dialog-ask", "dialog-message", "clipboard-all"] } dirs = "5.0.1" reqwest = "0.11.24" -paho-mqtt = "0.12.3" lazy_static = "1.4.0" tokio = "1.36.0" jsonwebtoken = "9.2.0" +rumqttc = "0.24.0" +log = "0.4.21" +paho-mqtt = "0.12.3" [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/handlers/bambu/mod.rs b/src-tauri/src/handlers/bambu/mod.rs index 2dc5fd1..9dcf05e 100644 --- a/src-tauri/src/handlers/bambu/mod.rs +++ b/src-tauri/src/handlers/bambu/mod.rs @@ -1,11 +1,6 @@ -use std::{borrow::Borrow, collections::HashSet, sync::Arc}; - // Imports use crate::constants; use jsonwebtoken::{Algorithm, DecodingKey, Validation}; -use paho_mqtt::connect_options; -use reqwest::header::ValueIter; -use serde::de; use serde_json::{json, Number}; use tokio::sync::Mutex; @@ -278,16 +273,15 @@ impl BambuClient { let mut builder = paho_mqtt::ConnectOptionsBuilder::new(); builder .keep_alive_interval(std::time::Duration::from_secs(30)) - .user_name(jwt_decoded.claims.username) + .user_name(format!("u_{}", jwt_decoded.claims.preferred_username)) .password(token) .ssl_options(paho_mqtt::SslOptions::new()); builder.finalize() }; println!( - "[BambuClient::get_device_ips] Connecting to MQTT broker at {} with options: {:?}", + "[BambuClient::get_device_ips] Connecting to MQTT broker at {}", constants::BAMBU_MQTT_URL, - connect_options ); // Connect to the MQTT broker @@ -326,6 +320,9 @@ impl BambuClient { ); mqtt_client.subscribe(topic, 1).wait().map_err(|e| { + // Print the error stack + eprintln!("{}", e); + std::io::Error::new( std::io::ErrorKind::Other, format!("Failed to subscribe to topic {}: {}", topic, e), diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ee20fb7..717f2f1 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,6 +9,8 @@ use commands::config::{get_config, init_config, save_config}; use commands::util::quit; fn main() { + log::set_max_level(log::LevelFilter::Debug); + tauri::Builder::default() .invoke_handler(tauri::generate_handler![ init_config,