diff --git a/Cargo.lock b/Cargo.lock index c4f4202..34c890c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,12 +39,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "async-once-cell" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b49bd4c5b769125ea6323601c39815848972880efd33ffb2d01f9f909adc699" - [[package]] name = "autocfg" version = "1.1.0" @@ -92,9 +86,9 @@ checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -172,8 +166,9 @@ dependencies = [ [[package]] name = "discord-presence" -version = "0.5.18" -source = "git+https://github.com/jewlexx/discord-presence.git#856ccbe12cd5707b2f9b2a1458aa47507b93d005" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0b42c644ad2150387ded023bedd258052306d67a43d40e36678491c59dec0c" dependencies = [ "byteorder", "bytes", @@ -183,6 +178,7 @@ dependencies = [ "num-derive", "num-traits", "parking_lot", + "paste", "quork", "serde", "serde_json", @@ -268,9 +264,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -283,9 +279,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -293,15 +289,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -310,38 +306,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.48", ] [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -603,15 +599,6 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "mime" version = "0.3.17" @@ -657,7 +644,7 @@ dependencies = [ "serde", "serde_json", "tokio", - "toml 0.8.2", + "toml 0.8.11", "tracing", "tracing-subscriber", "universal-config", @@ -665,11 +652,10 @@ dependencies = [ [[package]] name = "mpd-utils" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8fe9ce469f08cb23f2811201f61d7327b76b0fe15cf8ee0a2ea358fababcd7" +checksum = "7081a86d39a604868a671b0166febc1f31a4c4801d9436ab733f2664baabf8a4" dependencies = [ - "async-once-cell", "futures", "mpd_client", "thiserror", @@ -731,16 +717,13 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "cfg-if", "libc", - "memoffset", - "pin-utils", - "static_assertions", ] [[package]] @@ -888,6 +871,12 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "percent-encoding" version = "2.2.0" @@ -957,9 +946,9 @@ dependencies = [ [[package]] name = "quork" -version = "0.4.0" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6267e0f525db217637d4b69c59f924bd963e4ee350384cf2ba81f50ba272a2ae" +checksum = "1015eb796ce468e7b5434f9d1b309036a80f1afbadfa224b27f423762c8e5893" dependencies = [ "cc", "cfg-if", @@ -1051,9 +1040,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.25" +version = "0.11.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eea5a9eb898d3783f17c6407670e3592fd174cb81a10e51d4c37f49450b9946" +checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" dependencies = [ "base64", "bytes", @@ -1195,9 +1184,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -1258,12 +1247,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "syn" version = "1.0.109" @@ -1294,20 +1277,20 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" [[package]] name = "system-configuration" -version = "0.6.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bc6ee10a9b4fcf576e9b0819d95ec16f4d2c02d39fd83ac1c8789785c4a42" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "bitflags 2.4.2", + "bitflags 1.3.2", "core-foundation", "system-configuration-sys", ] [[package]] name = "system-configuration-sys" -version = "0.6.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" dependencies = [ "core-foundation-sys", "libc", @@ -1328,18 +1311,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -1437,21 +1420,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.22.7", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -1466,20 +1449,20 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.15", ] [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.22.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" dependencies = [ "indexmap 2.0.0", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.5", ] [[package]] @@ -1598,9 +1581,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" dependencies = [ "getrandom", ] @@ -1912,6 +1895,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/Cargo.toml b/Cargo.toml index 950e323..49412c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,19 +10,16 @@ readme = "README.md" keywords = ["mpd", "discord", "rpc", "music", "mopidy"] [dependencies] -discord-presence = "0.5.18" +discord-presence = "1.1.1" mpd_client = "1.4.1" dirs = "5.0.1" -toml = "0.8.2" +toml = "0.8.11" regex = "1.10.3" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.114" -reqwest = { version = "0.11.25", features = ["json"] } +reqwest = { version = "0.11.26", features = ["json"] } tokio = { version = "1.36.0", features = ["rt-multi-thread"] } universal-config = { version = "0.4.3", default-features = false, features = ["toml"] } -mpd-utils = "0.1.0" +mpd-utils = "0.2.0" tracing = "0.1.40" -tracing-subscriber = "0.3.18" - -[patch.crates-io] -discord-presence = { git = "https://github.com/jewlexx/discord-presence.git" } \ No newline at end of file +tracing-subscriber = "0.3.18" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8a76b7a..2838253 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::time::Duration; -use discord_presence::Client as DiscordClient; +use discord_presence::models::EventData; +use discord_presence::{Client as DiscordClient, DiscordError}; use mpd_client::responses::{PlayState, Song, Status}; use mpd_utils::MultiHostClient; use regex::Regex; @@ -35,8 +36,7 @@ async fn main() { }; // MPD and Discord connections - let hosts = config.hosts.iter().map(String::as_str).collect::>(); - let mut mpd = MultiHostClient::new(&hosts, Duration::from_secs(IDLE_TIME)); + let mut mpd = MultiHostClient::new(config.hosts.clone(), Duration::from_secs(IDLE_TIME)); mpd.init(); let (tx, mut rx) = mpsc::channel(16); @@ -45,7 +45,7 @@ async fn main() { loop { tokio::select! { - Some(event) = mpd.recv() => { + Ok(event) = mpd.recv() => { info!("Detected change, updating status"); debug!("Change: {event:?}"); @@ -101,27 +101,27 @@ impl<'a> Service<'a> { fn new(config: &'a Config, tokens: Tokens, event_tx: mpsc::Sender) -> Self { let event_tx2 = event_tx.clone(); - let mut drpc = DiscordClient::new(config.id); + let drpc = DiscordClient::new(config.id); drpc.on_ready(move |_| { + debug!("Discord RPC ready"); event_tx .try_send(ServiceEvent::Ready) .expect("channel to be open"); - }); + }) + .persist(); drpc.on_error(move |err| { - if err - .event - .get("error_message") - .and_then(serde_json::value::Value::as_str) - .map(|str| str == "Io Error") - .unwrap_or_default() - { - event_tx2 - .try_send(ServiceEvent::Error(err.event.to_string())) - .expect("channel to be open"); + if let EventData::Error(err) = err.event { + let msg = err.message.unwrap_or_default(); + if msg == "Io Err" { + event_tx2 + .try_send(ServiceEvent::Error(msg)) + .expect("channel to be open"); + } } - }); + }) + .persist(); let album_art_client = AlbumArtClient::new(); Self { @@ -136,7 +136,7 @@ impl<'a> Service<'a> { self.drpc.start(); } - async fn update_state(&mut self, mpd: &MultiHostClient<'a>, status: &Status) { + async fn update_state(&mut self, mpd: &MultiHostClient, status: &Status) { // https://discord.com/developers/docs/rich-presence/how-to#updating-presence-update-presence-payload const MAX_BYTES: usize = 128; @@ -192,7 +192,12 @@ impl<'a> Service<'a> { }); if let Err(why) = res { - error!("Failed to set activity: {why:?}"); + // api returns a bogus error about missing buttons but succeeds anyway + // so don't log it + if !matches!(&why, DiscordError::JsonError(err) if err.to_string().starts_with("missing field `buttons`")) + { + error!("Failed to set activity: {why:?}"); + } }; } } else if let Err(why) = self.drpc.clear_activity() {