From 43e8f86a5dd6d36d9c25d27d06eb1c888114c096 Mon Sep 17 00:00:00 2001 From: Yuriy Panov Date: Thu, 15 Oct 2026 14:25:45 +0600 Subject: [PATCH] feat: Yandex sign-in with device code, keychain storage and account status - ym-api wraps yamuse: device-code flow, token refresh, account status, and its own Error type that the UI acts on (expired, denied, network) - Credentials live in the system keychain, never print their tokens, and refresh when within a week of expiry; a rejected token is forgotten - Sign-in screen with code, QR, copy/open-in-browser, countdown and a pasted-token fallback; restoring/unreachable screens on startup - Sidebar account chip and Settings account card with Plus status and sign-out; Settings re-reads the account when opened - Live device-code test behind --ignored --- Cargo.lock | 1449 ++++++++++++++++++++++++++- README.md | 15 +- crates/musyx/Cargo.toml | 9 +- crates/musyx/src/app.rs | 155 ++- crates/musyx/src/main.rs | 1 + crates/musyx/src/route.rs | 3 - crates/musyx/src/screens/mod.rs | 202 ++-- crates/musyx/src/screens/sign_in.rs | 500 +++++++++ crates/musyx/src/session.rs | 110 ++ crates/musyx/src/snapshot.rs | 26 +- crates/musyx/src/widgets/sidebar.rs | 39 +- crates/ym-api/Cargo.toml | 7 + crates/ym-api/src/auth.rs | 207 ++++ crates/ym-api/src/client.rs | 113 +++ crates/ym-api/src/error.rs | 76 ++ crates/ym-api/src/lib.rs | 11 +- crates/ym-api/tests/live.rs | 15 + 17 files changed, 2811 insertions(+), 127 deletions(-) create mode 100644 crates/musyx/src/screens/sign_in.rs create mode 100644 crates/musyx/src/session.rs create mode 100644 crates/ym-api/src/auth.rs create mode 100644 crates/ym-api/src/client.rs create mode 100644 crates/ym-api/src/error.rs create mode 100644 crates/ym-api/tests/live.rs diff --git a/Cargo.lock b/Cargo.lock index 4e02371..b6ae164 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,28 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher 0.4.4", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32" +dependencies = [ + "cipher 0.5.2", + "cpubits", + "cpufeatures 0.3.1", +] + [[package]] name = "ahash" version = "0.8.12" @@ -37,6 +59,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + [[package]] name = "aligned" version = "0.4.3" @@ -104,6 +135,17 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "apple-native-keyring-store" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b350bfd03649e07aa05c0a81b3e15934374e585c98204a57e20b9d49f49bb9a" +dependencies = [ + "keyring-core", + "log", + "security-framework", +] + [[package]] name = "arbitrary" version = "1.5.0" @@ -349,6 +391,12 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + [[package]] name = "bit-set" version = "0.8.0" @@ -397,6 +445,33 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "block-padding" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b" +dependencies = [ + "hybrid-array", +] + [[package]] name = "block2" version = "0.5.1" @@ -460,6 +535,12 @@ dependencies = [ "syn 3.0.9", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -522,6 +603,15 @@ dependencies = [ "wayland-client", ] +[[package]] +name = "cbc" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2dc9ee5f88d11e0beb842c88b33c8a5cf0d1329c4b19494af42b07dbfe8896" +dependencies = [ + "cipher 0.5.2", +] + [[package]] name = "cc" version = "1.8.0" @@ -546,6 +636,37 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core 0.10.1", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common 0.1.7", + "inout 0.1.4", +] + +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "crypto-common 0.2.2", + "inout 0.2.3", +] + [[package]] name = "clipboard-win" version = "5.4.1" @@ -585,6 +706,12 @@ dependencies = [ "x11rb", ] +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "codespan-reporting" version = "0.12.0" @@ -621,6 +748,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "core-foundation" version = "0.9.4" @@ -682,6 +815,12 @@ dependencies = [ "libc", ] +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + [[package]] name = "core_maths" version = "0.1.1" @@ -715,6 +854,30 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -768,6 +931,25 @@ dependencies = [ "wgpu", ] +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + [[package]] name = "ctor" version = "0.10.1" @@ -777,6 +959,24 @@ dependencies = [ "dtor", ] +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher 0.4.4", +] + +[[package]] +name = "ctutils" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03bb0e1cc970d482d121d9a1744999169b69a07470b3d644a7894e53fcaf4574" +dependencies = [ + "cmov", +] + [[package]] name = "cursor-icon" version = "1.2.0" @@ -789,6 +989,29 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common 0.1.7", + "subtle", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid", + "crypto-common 0.2.2", + "ctutils", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -805,6 +1028,17 @@ dependencies = [ "objc2 0.6.5", ] +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "dlib" version = "0.5.3" @@ -847,6 +1081,20 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" +[[package]] +name = "encoding_rs" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + [[package]] name = "endi" version = "1.1.1" @@ -1016,6 +1264,18 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +[[package]] +name = "float_next_after" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foldhash" version = "0.1.5" @@ -1096,6 +1356,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.34" @@ -1197,6 +1466,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "gethostname" version = "1.1.0" @@ -1207,6 +1486,19 @@ dependencies = [ "windows-link", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -1226,8 +1518,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 6.0.0", + "rand_core 0.10.1", + "wasm-bindgen", ] [[package]] @@ -1349,6 +1644,25 @@ dependencies = [ "svg_fmt", ] +[[package]] +name = "h2" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d29020232d6aa3fb1daca64c1127cf662cf97f254ae16c18c05b8ab635fc118" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "half" version = "2.7.1" @@ -1416,6 +1730,142 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "hkdf" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018" +dependencies = [ + "hmac 0.13.0", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + +[[package]] +name = "hyper" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff" +dependencies = [ + "base64 0.23.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + [[package]] name = "iced" version = "0.14.0" @@ -1492,6 +1942,7 @@ dependencies = [ "image", "kamadak-exif", "log", + "lyon_path", "raw-window-handle", "rustc-hash 2.1.3", "thiserror 2.0.21", @@ -1567,6 +2018,7 @@ dependencies = [ "iced_debug", "iced_graphics", "log", + "lyon", "resvg", "rustc-hash 2.1.3", "thiserror 2.0.21", @@ -1582,6 +2034,7 @@ dependencies = [ "iced_renderer", "log", "num-traits", + "qrcode", "rustc-hash 2.1.3", "thiserror 2.0.21", "unicode-segmentation", @@ -1606,6 +2059,110 @@ dependencies = [ "winit", ] +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27bbb9d3abbefac45d55f647c9de1d44aafcd1186eb91879afef17c396c3e73" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "image" version = "0.25.10" @@ -1662,6 +2219,25 @@ dependencies = [ "hashbrown 0.17.1", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "inout" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8c0d789294fb457b791f7797a04478704788f30b407e5d0b01deaa846572d9f" +dependencies = [ + "block-padding", + "hybrid-array", +] + [[package]] name = "interpolate_name" version = "0.2.4" @@ -1673,6 +2249,31 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + +[[package]] +name = "is-docker" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" +dependencies = [ + "once_cell", +] + +[[package]] +name = "is-wsl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" +dependencies = [ + "is-docker", + "once_cell", +] + [[package]] name = "itertools" version = "0.14.0" @@ -1682,6 +2283,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + [[package]] name = "jni" version = "0.22.4" @@ -1770,6 +2377,27 @@ dependencies = [ "mutate_once", ] +[[package]] +name = "keyring" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2270074a3d26bcac93c1dc5d2845eb4c089e8d761ccf6e0ea266a16004640627" +dependencies = [ + "apple-native-keyring-store", + "keyring-core", + "windows-native-keyring-store", + "zbus-secret-service-keyring-store", +] + +[[package]] +name = "keyring-core" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29fbf4b551298c67925f38cf341a1ada797a75f1837bdf8ae1fc8e2ebc6efb59" +dependencies = [ + "log", +] + [[package]] name = "khronos-egl" version = "6.0.0" @@ -1885,6 +2513,12 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + [[package]] name = "litrs" version = "1.0.1" @@ -1921,6 +2555,64 @@ version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39" +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + +[[package]] +name = "lyon" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0578bdecb7d6d88987b8b2b1e3a4e2f81df9d0ece1078623324a567904e7b7" +dependencies = [ + "lyon_algorithms", + "lyon_tessellation", +] + +[[package]] +name = "lyon_algorithms" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdfa8785f95e57914ddb35e3b59994aeba6f5e79e9cfd03da1c269f010f36009" +dependencies = [ + "lyon_path", + "num-traits", +] + +[[package]] +name = "lyon_geom" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4336502e29e32af93cf2dad2214ed6003c17ceb5bd499df77b1de663b9042b92" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "lyon_path" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c463f9c428b7fc5ec885dcd39ce4aa61e29111d0e33483f6f98c74e89d8621e" +dependencies = [ + "lyon_geom", + "num-traits", +] + +[[package]] +name = "lyon_tessellation" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b8dcf906637ecef61b3c0740c7a4e7f27caeb31257cfac0cc579ce15be6005" +dependencies = [ + "float_next_after", + "lyon_path", + "num-traits", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -1940,6 +2632,16 @@ dependencies = [ "rayon", ] +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest 0.10.7", +] + [[package]] name = "memchr" version = "2.8.3" @@ -1979,6 +2681,12 @@ dependencies = [ "paste", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -1999,6 +2707,17 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mio" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + [[package]] name = "moxcms" version = "0.8.1" @@ -2009,6 +2728,12 @@ dependencies = [ "pxfm", ] +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + [[package]] name = "mundy" version = "0.2.3" @@ -2039,7 +2764,10 @@ name = "musyx" version = "0.1.0" dependencies = [ "iced", + "keyring", + "open", "png 0.18.1", + "serde_json", "tokio", "ym-api", ] @@ -2136,6 +2864,20 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.8" @@ -2176,6 +2918,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-rational" version = "0.4.2" @@ -2584,6 +3336,16 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "open" +version = "5.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa576c76302b7b808eecc68061e67336c47833ef9d22caa74dda10fa9675eebc" +dependencies = [ + "is-wsl", + "libc", +] + [[package]] name = "orbclient" version = "0.3.55" @@ -2785,6 +3547,15 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -2875,6 +3646,12 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "qrcode" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "166f136dfdb199f98186f3649cf7a0536534a61417a1a30221b492b4fb60ce3f" + [[package]] name = "quick-error" version = "2.0.1" @@ -2890,6 +3667,62 @@ dependencies = [ "memchr", ] +[[package]] +name = "quinn" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.1.3", + "rustls", + "socket2", + "thiserror 2.0.21", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand 0.10.3", + "rand_pcg", + "ring", + "rustc-hash 2.1.3", + "rustls", + "rustls-pki-types", + "slab", + "thiserror 2.0.21", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "quote" version = "1.0.47" @@ -2918,7 +3751,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core 0.10.1", ] [[package]] @@ -2928,7 +3772,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.5", ] [[package]] @@ -2940,6 +3784,21 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + [[package]] name = "range-alloc" version = "0.1.5" @@ -2979,7 +3838,7 @@ dependencies = [ "num-traits", "paste", "profiling", - "rand", + "rand 0.9.5", "rand_chacha", "simd_helpers", "thiserror 2.0.21", @@ -3092,12 +3951,85 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + [[package]] name = "renderdoc-sys" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", + "webpki-roots", +] + [[package]] name = "resvg" version = "0.45.1" @@ -3124,6 +4056,20 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "roxmltree" version = "0.20.0" @@ -3177,6 +4123,41 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.23" @@ -3201,6 +4182,12 @@ dependencies = [ "unicode-script", ] +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "same-file" version = "1.0.6" @@ -3235,6 +4222,48 @@ dependencies = [ "tiny-skia", ] +[[package]] +name = "secret-service" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5107b24b91445dd2aa449a258a1807b63240942157292354dc5bfdbeb8bc6db8" +dependencies = [ + "aes 0.9.3", + "cbc", + "futures-util", + "getrandom 0.4.3", + "hkdf", + "hybrid-array", + "num", + "once_cell", + "serde", + "sha2 0.11.1", + "zbus", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "self_cell" version = "1.3.0" @@ -3277,6 +4306,30 @@ dependencies = [ "syn 3.0.9", ] +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + [[package]] name = "serde_repr" version = "0.1.21" @@ -3288,6 +4341,40 @@ dependencies = [ "syn 3.0.9", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", +] + [[package]] name = "shlex" version = "2.0.1" @@ -3463,6 +4550,16 @@ dependencies = [ "serde", ] +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "softbuffer" version = "0.4.8" @@ -3524,6 +4621,12 @@ dependencies = [ "float-cmp", ] +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "svg_fmt" version = "0.4.5" @@ -3573,6 +4676,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "sys-locale" version = "0.3.2" @@ -3697,6 +4820,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.13.3" @@ -3709,7 +4842,48 @@ version = "1.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce3335fa71841cda333a58d7615b03901380ecf09d59b3296d21f8bbac0dde4e" dependencies = [ + "bytes", + "libc", + "mio", "pin-project-lite", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "libc", + "pin-project-lite", + "tokio", ] [[package]] @@ -3742,6 +4916,51 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.44" @@ -3774,6 +4993,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "ttf-parser" version = "0.25.1" @@ -3783,6 +5008,12 @@ dependencies = [ "core_maths", ] +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "uds_windows" version = "1.2.1" @@ -3854,13 +5085,31 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + [[package]] name = "usvg" version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80be9b06fbae3b8b303400ab20778c80bbaf338f563afe567cf3c9eea17b47ef" dependencies = [ - "base64", + "base64 0.22.1", "data-url", "flate2", "fontdb", @@ -3881,6 +5130,12 @@ dependencies = [ "xmlwriter", ] +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "uuid" version = "1.28.0" @@ -3919,6 +5174,21 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.4+wasi-0.2.12" @@ -3984,6 +5254,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-streams" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "wasmtimer" version = "0.4.3" @@ -4153,6 +5436,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "weezl" version = "0.1.12" @@ -4451,6 +5743,19 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-native-keyring-store" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063426e76fdec7438d56bb777f67e318a84a25c707b07e575cb8b78e10c028f8" +dependencies = [ + "byteorder", + "keyring-core", + "regex", + "windows-sys 0.61.2", + "zeroize", +] + [[package]] name = "windows-numerics" version = "0.3.1" @@ -4665,6 +5970,12 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + [[package]] name = "x11-dl" version = "2.21.0" @@ -4740,6 +6051,29 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448" +[[package]] +name = "yamuse" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef7a0cad9194ce07be43eb1bd45584808dfdd3888b6841d457befc0722ddeee" +dependencies = [ + "aes 0.8.4", + "base64 0.22.1", + "ctr", + "futures-util", + "hex", + "hmac 0.12.1", + "md-5", + "rand 0.9.5", + "reqwest", + "serde", + "serde_json", + "serde_path_to_error", + "sha2 0.10.9", + "thiserror 2.0.21", + "tokio", +] + [[package]] name = "yazi" version = "0.2.1" @@ -4749,6 +6083,36 @@ checksum = "e01738255b5a16e78bbb83e7fbba0a1e7dd506905cfc53f4622d89015a03fbb5" [[package]] name = "ym-api" version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "thiserror 2.0.21", + "tokio", + "yamuse", +] + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] [[package]] name = "zbus" @@ -4785,6 +6149,17 @@ dependencies = [ "zvariant", ] +[[package]] +name = "zbus-secret-service-keyring-store" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74801d001b9e7729adb4f1825b67b398185fed424749aa3d8bacf70417137d9a" +dependencies = [ + "keyring-core", + "secret-service", + "zbus", +] + [[package]] name = "zbus_macros" version = "5.19.0" @@ -4846,12 +6221,78 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0464e17806c1d976d5cba29399c7f08e516e279e2ba493f63123b5fca67dd8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34df6fc39dbd26ddc9c10e6a2984476e13acce22e64e4487636ef494369225da" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "zlib-rs" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + [[package]] name = "zune-core" version = "0.4.12" diff --git a/README.md b/README.md index ec3dcb6..b486979 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,18 @@ and it isn't affiliated with or endorsed by Yandex. cargo run -p musyx ``` +### Sign-in + +Musyx signs in with Yandex's device flow. It shows a code, you confirm it at the page Yandex +names (or scan the QR code), and the app picks up the token on its own. You can also paste an +existing OAuth token. The token is kept in the system keychain (service `musyx`, account +`yandex-music`) and refreshed when it is within a week of expiring. Signing out deletes it. + +Sign-in uses the public OAuth client id of the official Android app (through +[`yamuse`](https://crates.io/crates/yamuse)), because the music API doesn't accept +third-party apps. On macOS an unsigned dev build may ask for keychain access again after +each rebuild, because the keychain ties access to the binary's signature. + ## Check ```sh @@ -32,7 +44,8 @@ MUSYX_SNAPSHOT=design/shots/home.png MUSYX_SNAPSHOT_ROUTE=home MUSYX_SNAPSHOT_TH cargo run -p musyx --features snapshot ``` -`MUSYX_SNAPSHOT_ROUTE` takes home, wave, search, collection, podcasts, settings or signin. +`MUSYX_SNAPSHOT_ROUTE` takes home, wave, search, collection, podcasts, settings or signin. Every +route except signin renders with a sample signed-in account, so no network or keychain is needed. `MUSYX_SNAPSHOT_DRAWER` takes queue or lyrics. `MUSYX_SNAPSHOT_THEME` takes light or dark. ## Licences diff --git a/crates/musyx/Cargo.toml b/crates/musyx/Cargo.toml index fdb6c0a..5541c8b 100644 --- a/crates/musyx/Cargo.toml +++ b/crates/musyx/Cargo.toml @@ -8,13 +8,16 @@ publish.workspace = true [dependencies] ym-api = { path = "../ym-api" } -iced = { version = "0.14.0", features = ["svg", "image", "tokio", "advanced"] } +iced = { version = "0.14.0", features = ["svg", "image", "tokio", "advanced", "qr_code"] } +keyring = "4.2.0" +open = "5.4.4" +serde_json = "1" +tokio = { version = "1", features = ["time", "rt"] } png = { version = "0.18.1", optional = true } -tokio = { version = "1", features = ["time"], optional = true } [features] # `MUSYX_SNAPSHOT=out.png cargo run --features snapshot` renders one screen to a PNG and exits. -snapshot = ["dep:png", "dep:tokio"] +snapshot = ["dep:png"] [lints] workspace = true diff --git a/crates/musyx/src/app.rs b/crates/musyx/src/app.rs index c09f54f..fce2d13 100644 --- a/crates/musyx/src/app.rs +++ b/crates/musyx/src/app.rs @@ -3,18 +3,33 @@ use iced::theme::Mode; use iced::widget::{column, container, row, scrollable, space}; use iced::{Element, Fill, Subscription, Task, Theme}; +use ym_api::auth::Credentials; +use ym_api::{Account, Error, YmClient}; use crate::route::{Navigator, Route}; -use crate::screens; +use crate::screens::{self, sign_in}; +use crate::session::{self, Restored}; use crate::ui::theme::{self, shell}; use crate::widgets::drawer::{self, Panel}; use crate::widgets::player_bar::{self, PlayerUi}; use crate::widgets::{sidebar, topbar}; +/// Where sign-in stands. Everything but `SignedIn` takes the whole window. +pub enum Session { + /// Reading the keychain and checking the stored token. + Restoring, + SignedOut(Box), + /// Fresh credentials are being checked. `pasted` picks the error wording if they fail. + Connecting { pasted: bool }, + Unreachable, + SignedIn { client: YmClient, account: Account }, +} + pub struct App { theme: Theme, /// Set by a snapshot run so the system appearance can't override it. forced_mode: Option, + session: Session, nav: Navigator, search: String, drawer: Option, @@ -24,6 +39,13 @@ pub struct App { #[derive(Debug, Clone)] pub enum Message { ThemeChanged(Mode), + Restore, + Restored(Restored), + SignIn(sign_in::Msg), + Connected(Result<(YmClient, Account), Error>), + AccountRefreshed(Result), + SignOut, + SignedOut, Navigate(Route), Back, SearchChanged(String), @@ -38,16 +60,18 @@ impl App { let app = Self { theme: theme::for_mode(Mode::Dark), forced_mode: None, + session: Session::Restoring, nav: Navigator::new(Route::Home), search: String::new(), drawer: None, player: PlayerUi::default(), }; - let boot = iced::system::theme().map(Message::ThemeChanged); + let appearance = iced::system::theme().map(Message::ThemeChanged); #[cfg(feature = "snapshot")] if let Some(config) = crate::snapshot::Config::from_env() { let mut app = app; + app.session = config.session(); if let Some(route) = config.route { app.nav = Navigator::new(route); } @@ -56,16 +80,18 @@ impl App { if let Some(mode) = config.mode { app.theme = theme::for_mode(mode); } - return (app, Task::batch([boot, config.capture()])); + return (app, Task::batch([appearance, config.capture()])); } - (app, boot) + (app, Task::batch([appearance, restore()])) } pub fn title(&self) -> String { - match self.nav.current() { - Route::Home => "Musyx".into(), - route => format!("{} · Musyx", route.label()), + match (&self.session, self.nav.current()) { + (Session::SignedIn { .. }, route) if route != Route::Home => { + format!("{} · Musyx", route.label()) + } + _ => "Musyx".into(), } } @@ -74,7 +100,13 @@ impl App { } pub fn subscription(&self) -> Subscription { - iced::system::theme_changes().map(Message::ThemeChanged) + let appearance = iced::system::theme_changes().map(Message::ThemeChanged); + match &self.session { + Session::SignedOut(sign_in) => { + Subscription::batch([appearance, sign_in.subscription().map(Message::SignIn)]) + } + _ => appearance, + } } pub fn update(&mut self, message: Message) -> Task { @@ -82,7 +114,77 @@ impl App { Message::ThemeChanged(mode) => { self.theme = theme::for_mode(self.forced_mode.unwrap_or(mode)); } - Message::Navigate(route) => self.nav.go(route), + Message::Restore => { + self.session = Session::Restoring; + return restore(); + } + Message::Restored(restored) => { + self.session = match restored { + Restored::SignedIn(client, account) => Session::SignedIn { client, account }, + Restored::SignedOut => Session::SignedOut(Box::default()), + Restored::Unreachable => Session::Unreachable, + }; + } + Message::SignIn(msg) => { + let Session::SignedOut(sign_in) = &mut self.session else { + return Task::none(); + }; + match sign_in.update(msg) { + sign_in::Outcome::Continue(task) => return task.map(Message::SignIn), + sign_in::Outcome::Granted(credentials) => { + let pasted = credentials.refresh_token.is_none(); + self.session = Session::Connecting { pasted }; + return connect(credentials); + } + } + } + Message::Connected(Ok((client, account))) => { + self.nav = Navigator::new(Route::Home); + self.session = Session::SignedIn { client, account }; + } + Message::Connected(Err(e)) => { + eprintln!("sign-in: {e}"); + let pasted = matches!(self.session, Session::Connecting { pasted: true }); + self.session = Session::SignedOut(Box::new(match &e { + Error::Unauthorized(_) if pasted => sign_in::SignIn::rejected_token(), + _ => sign_in::SignIn::with_error(&e), + })); + // Don't keep credentials that just failed. + return Task::future(session::clear()).discard(); + } + Message::SignOut => { + return Task::future(session::clear()).map(|result| { + if let Err(e) = result { + eprintln!("keychain: {e}"); + } + Message::SignedOut + }); + } + Message::SignedOut => { + self.session = Session::SignedOut(Box::default()); + self.nav = Navigator::new(Route::Home); + self.drawer = None; + self.player = PlayerUi::default(); + } + Message::Navigate(route) => { + self.nav.go(route); + // Settings shows the subscription, which can change outside the app. + if let (Route::Settings, Session::SignedIn { client, .. }) = (route, &self.session) { + let client = client.clone(); + return Task::future(async move { client.account().await }) + .map(Message::AccountRefreshed); + } + } + Message::AccountRefreshed(Ok(fresh)) => { + if let Session::SignedIn { account, .. } = &mut self.session { + *account = fresh; + } + } + Message::AccountRefreshed(Err(Error::Unauthorized(e))) => { + eprintln!("token rejected: {e}"); + return self.update(Message::SignOut); + } + Message::AccountRefreshed(Err(e)) => eprintln!("account refresh: {e}"), Message::Back => self.nav.back(), Message::SearchChanged(query) => self.search = query, Message::SearchSubmitted => self.nav.go(Route::Search), @@ -97,23 +199,29 @@ impl App { pub fn view(&self) -> Element<'_, Message> { let t = theme::tokens(&self.theme); + let page = match &self.session { + Session::Restoring => screens::connecting(t, "Checking your sign-in…"), + Session::Connecting { .. } => screens::connecting(t, "Signing in…"), + Session::Unreachable => screens::unreachable(t), + Session::SignedOut(sign_in) => sign_in.view(t).map(Message::SignIn), + Session::SignedIn { account, .. } => return self.shell(t, account), + }; + container(page).width(Fill).height(Fill).style(theme::app).into() + } + + fn shell<'a>(&'a self, t: &'static theme::Tokens, account: &'a Account) -> Element<'a, Message> { let route = self.nav.current(); let content = column![ topbar::view(t, self.nav.can_go_back(), &self.search), - scrollable(screens::view(t, route, &self.search)) + scrollable(screens::view(t, route, &self.search, account)) .height(Fill) .style(theme::scroll), ] .width(Fill) .height(Fill); - let mut body = row![ - sidebar::view(t, route), - vline(), - content, - ] - .height(Fill); + let mut body = row![sidebar::view(t, route, account), vline(), content].height(Fill); if let Some(panel) = self.drawer { body = body.push(vline()).push(drawer::view(t, panel)); @@ -131,6 +239,21 @@ impl App { } } +fn restore() -> Task { + Task::future(session::restore()).map(Message::Restored) +} + +/// Save first so a crash right after sign-in doesn't lose it, then check the token. +fn connect(credentials: Credentials) -> Task { + Task::future(async move { + if let Err(e) = session::save(credentials.clone()).await { + eprintln!("keychain: {e}"); + } + YmClient::connect(&credentials).await + }) + .map(Message::Connected) +} + fn vline<'a>() -> Element<'a, Message> { container(space()).width(1).height(Fill).style(theme::divider).into() } diff --git a/crates/musyx/src/main.rs b/crates/musyx/src/main.rs index 2fd8e6f..c9746b6 100644 --- a/crates/musyx/src/main.rs +++ b/crates/musyx/src/main.rs @@ -1,6 +1,7 @@ mod app; mod route; mod screens; +mod session; #[cfg(feature = "snapshot")] mod snapshot; mod ui; diff --git a/crates/musyx/src/route.rs b/crates/musyx/src/route.rs index 3531a3f..9f2a389 100644 --- a/crates/musyx/src/route.rs +++ b/crates/musyx/src/route.rs @@ -11,7 +11,6 @@ pub enum Route { Collection, Podcasts, Settings, - SignIn, } impl Route { @@ -27,7 +26,6 @@ impl Route { Route::Collection => "Collection", Route::Podcasts => "Podcasts", Route::Settings => "Settings", - Route::SignIn => "Sign in", } } @@ -39,7 +37,6 @@ impl Route { Route::Collection => Icon::Library, Route::Podcasts => Icon::Podcast, Route::Settings => Icon::Settings, - Route::SignIn => Icon::LogOut, } } } diff --git a/crates/musyx/src/screens/mod.rs b/crates/musyx/src/screens/mod.rs index 361c18d..06c71b9 100644 --- a/crates/musyx/src/screens/mod.rs +++ b/crates/musyx/src/screens/mod.rs @@ -1,34 +1,27 @@ -//! Content for each route. Until sign-in exists every screen shows its -//! signed-out state, which is also what a signed-out user will see later. +//! Content for each route, plus the full-window screens shown outside a session. + +pub mod sign_in; use iced::widget::{Column, button, column, container, row, space}; use iced::{Alignment, Element, Fill, Padding}; +use ym_api::Account; use crate::app::Message; use crate::route::Route; use crate::ui::icons::{Icon, icon, sized}; use crate::ui::theme::{self, Tokens, radius, size, space as sp}; use crate::ui::{line, para}; +use crate::widgets::sidebar; -pub fn view<'a>(t: &'static Tokens, route: Route, query: &str) -> Element<'a, Message> { +pub fn view<'a>(t: &'static Tokens, route: Route, query: &str, me: &'a Account) -> Element<'a, Message> { let content: Column<'a, Message> = match route { Route::Home => column![ wave_hero(t), - signed_out( - t, - Icon::Library, - "Your music, picked for you", - "Sign in to see your daily playlists, the chart and albums picked from what you play.", - ), + upcoming(t, Icon::Library, "Made for you", "Daily playlists, the chart and albums picked from what you play."), ], Route::Wave => column![ title(t, "My Wave"), - signed_out( - t, - Icon::Wave, - "An endless stream that learns from you", - "Sign in to start My Wave. Every like, skip and full listen steers what comes next.", - ), + upcoming(t, Icon::Wave, "An endless stream that learns from you", "Every like, skip and full listen steers what comes next."), ], Route::Search => column![ title(t, if query.trim().is_empty() { @@ -36,41 +29,17 @@ pub fn view<'a>(t: &'static Tokens, route: Route, query: &str) -> Element<'a, Me } else { format!("Results for “{}”", query.trim()) }), - signed_out( - t, - Icon::Search, - "Search the whole catalogue", - "Sign in to search tracks, albums, artists, playlists and podcasts.", - ), + upcoming(t, Icon::Search, "Search the whole catalogue", "Tracks, albums, artists, playlists and podcasts."), ], Route::Collection => column![ title(t, "Collection"), - signed_out( - t, - Icon::HeartFilled, - "Everything you've liked", - "Your liked tracks, albums, artists and playlists appear here after you sign in.", - ), + upcoming(t, Icon::HeartFilled, "Everything you've liked", "Liked tracks, albums, artists and playlists."), ], Route::Podcasts => column![ title(t, "Podcasts and books"), - signed_out( - t, - Icon::Podcast, - "Pick up where you left off", - "Podcasts and audiobooks you follow appear here after you sign in.", - ), + upcoming(t, Icon::Podcast, "Pick up where you left off", "Podcasts and audiobooks you follow."), ], - Route::Settings => column![ - title(t, "Settings"), - signed_out( - t, - Icon::Settings, - "Account and playback", - "Sign in to choose streaming quality and manage your Yandex account.", - ), - ], - Route::SignIn => column![sign_in(t)], + Route::Settings => column![title(t, "Settings"), account_card(t, me)], }; content @@ -84,24 +53,17 @@ fn title<'a>(t: &'static Tokens, text: impl Into) -> Element<'a, Message line(text.into(), theme::DISPLAY, size::DISPLAY_S, t.fg).into() } -fn signed_out<'a>( - t: &'static Tokens, - glyph: Icon, - heading: &'a str, - body: &'a str, -) -> Element<'a, Message> { +/// A section whose content arrives in a later build. +fn upcoming<'a>(t: &'static Tokens, glyph: Icon, heading: &'a str, body: &'a str) -> Element<'a, Message> { container( column![ sized(glyph, 28.0, t.accent), column![ line(heading, theme::SEMIBOLD, size::SECTION, t.fg), container(para(body, size::BODY, t.muted)).max_width(460), + line("Arrives in the next Musyx update.", theme::MEDIUM, size::META, t.muted), ] .spacing(6), - button(line("Sign in", theme::SEMIBOLD, size::BODY, t.accent_ink)) - .padding([11, 18]) - .style(theme::primary) - .on_press(Message::Navigate(Route::SignIn)), ] .spacing(18), ) @@ -111,6 +73,60 @@ fn signed_out<'a>( .into() } +fn account_card<'a>(t: &'static Tokens, me: &'a Account) -> Element<'a, Message> { + let avatar = container(line(me.initial().to_string(), theme::SEMIBOLD, 22.0, iced::Color::from_rgb8(0x1C, 0x1A, 0x22))) + .center(56) + .style(theme::avatar); + + let plan = match (me.has_plus, me.subscription_end.as_deref().and_then(human_date)) { + (true, Some(end)) => format!("Yandex Plus until {end}"), + (true, None) => "Yandex Plus".to_owned(), + (false, _) => "No Plus subscription. Tracks play as 30-second previews.".to_owned(), + }; + + container( + row![ + avatar, + column![ + line(&me.name, theme::SEMIBOLD, size::SECTION, t.fg), + line(&me.login, theme::BODY, size::BODY, t.muted), + line(plan, theme::MEDIUM, size::META, if me.has_plus { t.ok } else { t.muted }), + ] + .spacing(4) + .width(Fill), + button( + row![icon(Icon::LogOut, t.fg), line("Sign out", theme::MEDIUM, size::BODY, t.fg)] + .spacing(8) + .align_y(Alignment::Center), + ) + .padding([9, 16]) + .style(theme::ghost) + .on_press(Message::SignOut), + ] + .spacing(18) + .align_y(Alignment::Center), + ) + .padding(24) + .width(Fill) + .style(theme::card) + .into() +} + +/// `2027-01-05T00:00:00+03:00` → `5 January 2027`. +pub fn human_date(iso: &str) -> Option { + const MONTHS: [&str; 12] = [ + "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December", + ]; + let date = iso.get(..10)?; + let mut parts = date.split('-'); + let (y, m, d) = (parts.next()?, parts.next()?, parts.next()?); + let month = MONTHS.get(m.parse::().ok()?.checked_sub(1)?)?; + let day: u32 = d.parse().ok()?; + y.parse::().ok()?; + Some(format!("{day} {month} {y}")) +} + /// Static version of the My Wave hero; the animated wave arrives with playback. fn wave_hero<'a>(t: &'static Tokens) -> Element<'a, Message> { container( @@ -153,29 +169,61 @@ fn wave_hero<'a>(t: &'static Tokens) -> Element<'a, Message> { .into() } -fn sign_in<'a>(t: &'static Tokens) -> Element<'a, Message> { - column![ - container(line("Sign in with your Yandex account", theme::DISPLAY, size::DISPLAY_M, t.fg)), - container(para( - "Musyx plays your Yandex Music library, My Wave and playlists. You confirm sign-in \ - on Yandex's own page, so your password never passes through this app.", - 15.0, - t.muted, - )) - .max_width(520), - button(line("Get sign-in code", theme::SEMIBOLD, size::BODY, t.muted)) - .padding([11, 18]) - .style(theme::primary), - space().height(8), - container(para( - "Musyx is an unofficial client and isn't affiliated with Yandex. Your sign-in token \ - is kept in the system keychain.", - size::SMALL, - t.muted, - )) - .max_width(520), - ] - .spacing(22) - .padding(Padding::default().top(24)) +/// Full-window holding screen while the stored session is checked or a new one connects. +pub fn connecting<'a>(t: &'static Tokens, label: &'a str) -> Element<'a, Message> { + container( + column![ + sidebar::wordmark(t), + line(label, theme::BODY, size::BODY, t.muted), + ] + .spacing(14) + .align_x(Alignment::Center), + ) + .center(Fill) .into() } + +/// Full-window screen when stored credentials exist but Yandex can't be reached. +pub fn unreachable<'a>(t: &'static Tokens) -> Element<'a, Message> { + container( + column![ + sidebar::wordmark(t), + line("Can't reach Yandex Music", theme::DISPLAY, size::DISPLAY_S, t.fg), + container(para( + "You're still signed in. Check your internet connection, then try again.", + 15.0, + t.muted, + )) + .max_width(440), + row![ + button(line("Try again", theme::SEMIBOLD, size::BODY, t.accent_ink)) + .padding([11, 18]) + .style(theme::primary) + .on_press(Message::Restore), + button(line("Sign out", theme::MEDIUM, size::BODY, t.fg)) + .padding([11, 18]) + .style(theme::ghost) + .on_press(Message::SignOut), + ] + .spacing(10), + space().height(40), + ] + .spacing(18) + .align_x(Alignment::Center), + ) + .center(Fill) + .into() +} + +#[cfg(test)] +mod tests { + use super::human_date; + + #[test] + fn dates_read_naturally() { + assert_eq!(human_date("2027-01-05T00:00:00+03:00").as_deref(), Some("5 January 2027")); + assert_eq!(human_date("2026-12-31").as_deref(), Some("31 December 2026")); + assert_eq!(human_date("2026-13-01"), None); + assert_eq!(human_date("soon"), None); + } +} diff --git a/crates/musyx/src/screens/sign_in.rs b/crates/musyx/src/screens/sign_in.rs new file mode 100644 index 0000000..e46ca00 --- /dev/null +++ b/crates/musyx/src/screens/sign_in.rs @@ -0,0 +1,500 @@ +//! Device-code sign-in: get a code, the user confirms it on Yandex's page +//! (or scans the QR), we poll until a token arrives. A pasted token is the +//! fallback for people who already have one. + +use std::time::{Duration, Instant}; + +use iced::widget::{button, column, container, qr_code, row, space, text_input}; +use iced::{Alignment, Element, Fill, Length, Padding, Subscription, Task}; +use ym_api::Error; +use ym_api::auth::{Auth, Credentials, DeviceCode, Poll}; + +use crate::ui::icons::{Icon, icon}; +use crate::ui::theme::{self, Tokens, radius, size}; +use crate::ui::{line, para}; +use crate::widgets::sidebar; + +#[derive(Debug, Clone)] +pub enum Msg { + GetCode, + CodeReady(Result), + Tick(Instant), + Polled(Result), + CopyCode, + OpenPage, + ToggleToken, + TokenChanged(String), + UseToken, + Cancel, +} + +enum Stage { + Idle, + Requesting, + Waiting(Box), +} + +struct Waiting { + code: DeviceCode, + qr: Option, + started: Instant, + now: Instant, + next_poll: Instant, + polling: bool, + copied_at: Option, +} + +impl Waiting { + fn remaining(&self) -> Duration { + self.code.expires_in.saturating_sub(self.now.duration_since(self.started)) + } +} + +pub struct SignIn { + stage: Stage, + error: Option, + token_open: bool, + token: String, +} + +impl Default for SignIn { + fn default() -> Self { + Self { stage: Stage::Idle, error: None, token_open: false, token: String::new() } + } +} + +/// What the app should do after a sign-in message. +pub enum Outcome { + Continue(Task), + /// Credentials from Yandex (or pasted); the app saves them and connects. + Granted(Credentials), +} + +impl SignIn { + /// Shown after a pasted token turned out to be invalid. + pub fn rejected_token() -> Self { + Self { + error: Some("Yandex didn't accept that token. Check it and paste it again.".into()), + token_open: true, + ..Self::default() + } + } + + /// Shown when connecting with fresh credentials failed. + pub fn with_error(error: &Error) -> Self { + Self { error: Some(describe(error).into()), ..Self::default() } + } + + pub fn update(&mut self, msg: Msg) -> Outcome { + match msg { + Msg::GetCode => { + self.error = None; + self.stage = Stage::Requesting; + return Outcome::Continue(Task::future(async { + match Auth::new() { + Ok(auth) => auth.request_code().await, + Err(e) => Err(e), + } + }).map(Msg::CodeReady)); + } + Msg::CodeReady(Ok(code)) => { + let now = Instant::now(); + let qr = qr_code::Data::new(code.verification_url.as_bytes()).ok(); + self.stage = Stage::Waiting(Box::new(Waiting { + next_poll: now + code.interval, + code, + qr, + started: now, + now, + polling: false, + copied_at: None, + })); + } + Msg::CodeReady(Err(e)) => self.fail(&e), + Msg::Tick(now) => { + let Stage::Waiting(w) = &mut self.stage else { + return Outcome::Continue(Task::none()); + }; + w.now = now; + if w.remaining().is_zero() { + self.fail(&Error::CodeExpired); + } else if !w.polling && now >= w.next_poll { + w.polling = true; + let code = w.code.clone(); + return Outcome::Continue( + Task::future(async move { + match Auth::new() { + Ok(auth) => auth.poll(&code).await, + Err(e) => Err(e), + } + }) + .map(Msg::Polled), + ); + } + } + Msg::Polled(result) => { + let Stage::Waiting(w) = &mut self.stage else { + return Outcome::Continue(Task::none()); + }; + w.polling = false; + match result { + Ok(Poll::Pending) => w.next_poll = Instant::now() + w.code.interval, + // A dropped poll isn't fatal: try again next interval. + Err(e) if e.is_retryable() => w.next_poll = Instant::now() + w.code.interval, + Ok(Poll::Granted(credentials)) => { + self.stage = Stage::Idle; + return Outcome::Granted(credentials); + } + Err(e) => self.fail(&e), + } + } + Msg::CopyCode => { + if let Stage::Waiting(w) = &mut self.stage { + w.copied_at = Some(w.now); + return Outcome::Continue(iced::clipboard::write(w.code.user_code.clone())); + } + } + Msg::OpenPage => { + if let Stage::Waiting(w) = &self.stage + && open::that_detached(&w.code.verification_url).is_err() + { + self.error = Some(format!( + "Couldn't open your browser. Go to {} yourself.", + w.code.verification_url + )); + } + } + Msg::ToggleToken => self.token_open = !self.token_open, + Msg::TokenChanged(token) => self.token = token, + Msg::UseToken => { + let credentials = Credentials::from_token(&self.token); + if !credentials.access_token.is_empty() { + self.token.clear(); + self.stage = Stage::Idle; + return Outcome::Granted(credentials); + } + } + Msg::Cancel => { + self.stage = Stage::Idle; + self.error = None; + } + } + Outcome::Continue(Task::none()) + } + + fn fail(&mut self, error: &Error) { + self.stage = Stage::Idle; + self.error = Some(describe(error).into()); + } + + /// Ticks once a second while a code is on screen: drives the countdown and polling. + pub fn subscription(&self) -> Subscription { + match self.stage { + Stage::Waiting(_) => iced::time::every(Duration::from_secs(1)).map(Msg::Tick), + _ => Subscription::none(), + } + } + + pub fn view<'a>(&'a self, t: &'static Tokens) -> Element<'a, Msg> { + let left = column![ + sidebar::wordmark(t), + container( + iced::widget::text("Sign in with your Yandex account") + .font(theme::DISPLAY) + .size(size::DISPLAY_M) + .line_height(1.12) + .color(t.fg), + ) + .max_width(520), + container(para( + "Musyx plays your Yandex Music library, My Wave and playlists. You confirm sign-in \ + on Yandex's own page, so your password never passes through this app.", + 15.0, + t.muted, + )) + .max_width(500), + self.body(t), + self.token_fallback(t), + space().height(Fill), + container(para( + "Musyx is an unofficial client and isn't affiliated with Yandex. Your sign-in \ + token is kept in the system keychain.", + size::SMALL, + t.muted, + )) + .max_width(520), + ] + .spacing(26) + .padding(Padding::from([44, 56])) + .width(Length::FillPortion(21)) + .clip(true) + .height(Fill); + + let right = container(self.qr_card(t)) + .center(Fill) + .width(Length::FillPortion(20)) + .style(move |th| { + let mut s = theme::panel(th); + s.background = Some(iced::Background::Gradient( + iced::gradient::Linear::new(0.4) + .add_stop(0.0, t.panel) + .add_stop(1.0, theme::mix(t.panel, t.accent, 0.14)) + .into(), + )); + s + }); + + row![left, container(space()).width(1).height(Fill).style(theme::divider), right] + .height(Fill) + .into() + } + + fn body<'a>(&'a self, t: &'static Tokens) -> Element<'a, Msg> { + let error = self.error.as_deref().map(|e| { + container(para(e, size::BODY, t.like)).max_width(500) + }); + + let content: Element<'a, Msg> = match &self.stage { + Stage::Idle => column![ + primary(t, "Get sign-in code", Some(Msg::GetCode)), + ] + .into(), + Stage::Requesting => column![primary(t, "Getting a code…", None)].into(), + Stage::Waiting(w) => self.steps(t, w), + }; + + column![content].push(error).spacing(16).into() + } + + fn steps<'a>(&'a self, t: &'static Tokens, w: &'a Waiting) -> Element<'a, Msg> { + let host = w + .code + .verification_url + .trim_start_matches("https://") + .trim_start_matches("http://") + .trim_end_matches('/') + .to_owned(); + + let copied = w.copied_at.is_some_and(|at| w.now.duration_since(at) < Duration::from_secs(2)); + let code_box = row![ + container(line(spaced(&w.code.user_code), theme::DISPLAY, 30.0, t.fg)) + .padding([14, 18]) + .style(theme::card), + ghost(t, Icon::Copy, if copied { "Copied" } else { "Copy code" }, Msg::CopyCode), + ] + .spacing(14) + .align_y(Alignment::Center); + + let remaining = w.remaining().as_secs(); + let status = row![ + container(space()).width(9).height(9).style(theme::accent_dot), + line( + format!("Waiting for confirmation · code expires in {}:{:02}", remaining / 60, remaining % 60), + theme::BODY, + 13.5, + t.muted, + ), + space().width(12), + button(line("Cancel", theme::MEDIUM, 13.5, t.muted)) + .padding(0) + .style(theme::tab(false)) + .on_press(Msg::Cancel), + ] + .spacing(10) + .align_y(Alignment::Center); + + column![ + step(t, 1, column![ + line(format!("Open {host}"), theme::MEDIUM, size::BODY, t.fg), + para("On this computer or your phone. You can also scan the QR code.", 13.5, t.muted), + ghost(t, Icon::Globe, "Open in browser", Msg::OpenPage), + ].spacing(6)), + step(t, 2, column![ + line("Enter this code", theme::MEDIUM, size::BODY, t.fg), + code_box, + ].spacing(10)), + step(t, 3, column![ + line("Come back here", theme::MEDIUM, size::BODY, t.fg), + para("Musyx signs you in as soon as you allow access.", 13.5, t.muted), + ].spacing(4)), + status, + ] + .spacing(20) + .into() + } + + fn token_fallback<'a>(&'a self, t: &'static Tokens) -> Element<'a, Msg> { + let toggle = button(line( + if self.token_open { "Hide token sign-in" } else { "Sign in with an existing token instead" }, + theme::BODY, + 13.5, + t.muted, + )) + .padding(0) + .style(theme::tab(false)) + .on_press(Msg::ToggleToken); + + if !self.token_open { + return toggle.into(); + } + + let can_submit = !self.token.trim().is_empty(); + column![ + toggle, + row![ + text_input("Paste OAuth token", &self.token) + .id("token") + .secure(true) + .on_input(Msg::TokenChanged) + .on_submit_maybe(can_submit.then_some(Msg::UseToken)) + .padding([10, 14]) + .width(320) + .style(theme::search_field), + button(line("Sign in", theme::MEDIUM, size::BODY, t.fg)) + .padding([10, 18]) + .style(theme::ghost) + .on_press_maybe(can_submit.then_some(Msg::UseToken)), + ] + .spacing(8) + .align_y(Alignment::Center), + ] + .spacing(10) + .into() + } + + fn qr_card<'a>(&'a self, t: &'static Tokens) -> Element<'a, Msg> { + let qr = match &self.stage { + Stage::Waiting(w) => w.qr.as_ref(), + _ => None, + }; + let (code, caption): (Element<'a, Msg>, &str) = match qr { + Some(data) => ( + qr_code(data) + .total_size(200) + .style(|_| qr_code::Style { + cell: iced::Color::from_rgb8(0x1C, 0x1A, 0x22), + background: iced::Color::WHITE, + }) + .into(), + "Scan to open the sign-in page", + ), + None => ( + container(icon(Icon::Lock, iced::Color::from_rgb8(0x68, 0x61, 0x78))) + .center(200) + .into(), + "A QR code appears with your sign-in code", + ), + }; + container( + column![ + code, + line(caption, theme::BODY, size::SMALL, iced::Color::from_rgb8(0x4A, 0x44, 0x58)), + ] + .spacing(10) + .align_x(Alignment::Center), + ) + .padding(18) + .style(move |_| iced::widget::container::Style { + background: Some(iced::Color::WHITE.into()), + border: iced::Border { radius: radius::HERO.into(), ..Default::default() }, + shadow: iced::Shadow { + color: iced::Color::BLACK.scale_alpha(if t == &theme::DARK { 0.45 } else { 0.14 }), + offset: iced::Vector::new(0.0, 18.0), + blur_radius: 50.0, + }, + ..Default::default() + }) + .into() + } +} + +/// The user's next step for each failure. Never shows the raw error. +fn describe(error: &Error) -> &'static str { + match error { + Error::CodeExpired => "The code expired before it was confirmed. Get a new code to try again.", + Error::Denied => "Access was declined on Yandex's page. Get a new code if that was a mistake.", + Error::Network(_) => "Can't reach Yandex. Check your connection and try again.", + Error::Unauthorized(_) => "Yandex didn't accept the sign-in. Get a new code to try again.", + Error::Api(_) => "Yandex sent an unexpected answer. Try again in a moment.", + } +} + +/// `ABCD1234` → `ABCD 1234` for easier reading; codes that already have separators stay as they are. +fn spaced(code: &str) -> String { + if code.len() == 8 && code.chars().all(|c| c.is_ascii_alphanumeric()) { + format!("{} {}", &code[..4], &code[4..]) + } else { + code.to_owned() + } +} + +fn step<'a>(t: &'static Tokens, n: u8, content: impl Into>) -> Element<'a, Msg> { + let badge = container(line(n.to_string(), theme::SEMIBOLD, size::BODY, t.muted)) + .center(30) + .style(move |_| iced::widget::container::Style { + border: iced::Border { color: t.line, width: 1.0, radius: radius::PILL.into() }, + ..Default::default() + }); + row![badge, container(content).padding(Padding::default().top(4))] + .spacing(14) + .into() +} + +fn primary<'a>(t: &'static Tokens, label: &'a str, msg: Option) -> Element<'a, Msg> { + let ink = if msg.is_some() { t.accent_ink } else { t.muted }; + button(line(label, theme::SEMIBOLD, size::BODY, ink)) + .padding([11, 18]) + .style(theme::primary) + .on_press_maybe(msg) + .into() +} + +fn ghost<'a>(t: &'static Tokens, glyph: Icon, label: &'a str, msg: Msg) -> Element<'a, Msg> { + button( + row![icon(glyph, t.fg), line(label, theme::MEDIUM, size::BODY, t.fg)] + .spacing(8) + .align_y(Alignment::Center), + ) + .padding([9, 16]) + .style(theme::ghost) + .on_press(msg) + .into() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn codes_are_split_for_reading() { + assert_eq!(spaced("QX7K29PM"), "QX7K 29PM"); + assert_eq!(spaced("QX7-K29"), "QX7-K29"); + assert_eq!(spaced("1234567"), "1234567"); + } + + #[test] + fn pasted_token_is_trimmed_and_granted() { + let mut s = SignIn::default(); + let _ = s.update(Msg::TokenChanged(" y0_token \n".into())); + match s.update(Msg::UseToken) { + Outcome::Granted(c) => assert_eq!(c.access_token, "y0_token"), + Outcome::Continue(_) => panic!("expected credentials"), + } + assert!(s.token.is_empty(), "token must not linger in UI state"); + } + + #[test] + fn blank_token_is_ignored() { + let mut s = SignIn::default(); + let _ = s.update(Msg::TokenChanged(" ".into())); + assert!(matches!(s.update(Msg::UseToken), Outcome::Continue(_))); + } + + #[test] + fn failures_leave_an_actionable_message() { + let mut s = SignIn::default(); + let _ = s.update(Msg::CodeReady(Err(Error::Network("dns".into())))); + assert!(matches!(s.stage, Stage::Idle)); + assert!(s.error.as_deref().unwrap().contains("connection")); + } +} diff --git a/crates/musyx/src/session.rs b/crates/musyx/src/session.rs new file mode 100644 index 0000000..4341260 --- /dev/null +++ b/crates/musyx/src/session.rs @@ -0,0 +1,110 @@ +//! Keeping the user signed in: credentials live in the system keychain, and +//! startup turns them back into a connected client. + +use std::time::SystemTime; + +use ym_api::auth::{Auth, Credentials}; +use ym_api::{Account, Error, YmClient}; + +const SERVICE: &str = "musyx"; +const ACCOUNT: &str = "yandex-music"; + +/// What startup found. +#[derive(Debug, Clone)] +pub enum Restored { + SignedIn(YmClient, Account), + /// Nothing stored, or the stored token was rejected (and has been removed). + SignedOut, + /// Credentials are stored but Yandex couldn't be reached; they're kept for a retry. + Unreachable, +} + +/// Keychain access is blocking (and may show a system prompt), so it runs off the UI thread. +async fn blocking(f: impl FnOnce() -> T + Send + 'static) -> T { + tokio::task::spawn_blocking(f).await.expect("keychain task panicked") +} + +fn entry() -> Result { + keyring::Entry::new(SERVICE, ACCOUNT).map_err(|e| e.to_string()) +} + +pub async fn load() -> Result, String> { + blocking(|| { + let raw = match entry()?.get_password() { + Ok(raw) => raw, + Err(keyring::Error::NoEntry) => return Ok(None), + Err(e) => return Err(e.to_string()), + }; + // An unreadable entry is treated as absent; the next sign-in overwrites it. + Ok(serde_json::from_str(&raw).ok()) + }) + .await +} + +pub async fn save(credentials: Credentials) -> Result<(), String> { + blocking(move || { + let json = serde_json::to_string(&credentials).map_err(|e| e.to_string())?; + entry()?.set_password(&json).map_err(|e| e.to_string()) + }) + .await +} + +pub async fn clear() -> Result<(), String> { + blocking(|| match entry()?.delete_credential() { + Ok(()) | Err(keyring::Error::NoEntry) => Ok(()), + Err(e) => Err(e.to_string()), + }) + .await +} + +/// Load stored credentials, refresh them if they're close to expiring, connect. +pub async fn restore() -> Restored { + let credentials = match load().await { + Ok(Some(c)) => c, + Ok(None) => return Restored::SignedOut, + Err(e) => { + eprintln!("keychain: {e}"); + return Restored::SignedOut; + } + }; + + let credentials = if credentials.needs_refresh(SystemTime::now()) { + match refresh(&credentials).await { + Some(fresh) => fresh, + None => credentials, + } + } else { + credentials + }; + + match YmClient::connect(&credentials).await { + Ok((client, account)) => Restored::SignedIn(client, account), + Err(Error::Unauthorized(_)) => match refresh(&credentials).await { + Some(fresh) => match YmClient::connect(&fresh).await { + Ok((client, account)) => Restored::SignedIn(client, account), + Err(e) => forget(e).await, + }, + None => forget(Error::Unauthorized("refresh failed".into())).await, + }, + Err(e) if e.is_retryable() => Restored::Unreachable, + Err(e) => forget(e).await, + } +} + +/// Refresh and persist; `None` when there is nothing to refresh with or Yandex said no. +async fn refresh(credentials: &Credentials) -> Option { + credentials.refresh_token.as_ref()?; + let fresh = Auth::new().ok()?.refresh(credentials).await.ok()?; + if let Err(e) = save(fresh.clone()).await { + eprintln!("keychain: {e}"); + } + Some(fresh) +} + +async fn forget(reason: Error) -> Restored { + eprintln!("stored sign-in rejected: {reason}"); + if let Err(e) = clear().await { + eprintln!("keychain: {e}"); + } + Restored::SignedOut +} diff --git a/crates/musyx/src/snapshot.rs b/crates/musyx/src/snapshot.rs index fb0da25..b06790a 100644 --- a/crates/musyx/src/snapshot.rs +++ b/crates/musyx/src/snapshot.rs @@ -13,12 +13,17 @@ use iced::Task; use iced::theme::Mode; use iced::window; +use ym_api::{Account, YmClient}; + +use crate::app::Session; use crate::route::Route; use crate::widgets::drawer::Panel; #[derive(Debug, Clone)] pub struct Config { pub out: PathBuf, + /// `MUSYX_SNAPSHOT_ROUTE=signin` shows the sign-in page instead of a signed-in shell. + pub signed_out: bool, pub route: Option, pub drawer: Option, pub mode: Option, @@ -28,6 +33,7 @@ impl Config { pub fn from_env() -> Option { let out = PathBuf::from(std::env::var_os("MUSYX_SNAPSHOT")?); let var = |k: &str| std::env::var(k).ok().map(|v| v.to_ascii_lowercase()); + let signed_out = var("MUSYX_SNAPSHOT_ROUTE").as_deref() == Some("signin"); let route = var("MUSYX_SNAPSHOT_ROUTE").and_then(|r| { Some(match r.as_str() { "home" => Route::Home, @@ -36,7 +42,6 @@ impl Config { "collection" => Route::Collection, "podcasts" => Route::Podcasts, "settings" => Route::Settings, - "signin" => Route::SignIn, _ => return None, }) }); @@ -50,7 +55,24 @@ impl Config { "dark" => Some(Mode::Dark), _ => None, }); - Some(Self { out, route, drawer, mode }) + Some(Self { out, signed_out, route, drawer, mode }) + } + + /// A made-up account so the shell renders without a network or keychain. + pub fn session(&self) -> Session { + if self.signed_out { + return Session::SignedOut(Box::default()); + } + Session::SignedIn { + client: YmClient::unauthenticated().expect("client"), + account: Account { + uid: 1, + login: "sample.listener".into(), + name: "Sample Listener".into(), + has_plus: true, + subscription_end: Some("2027-01-05T00:00:00+03:00".into()), + }, + } } /// Waits for fonts and the first frames, captures the window, writes the PNG, exits. diff --git a/crates/musyx/src/widgets/sidebar.rs b/crates/musyx/src/widgets/sidebar.rs index 4c8436c..c4b3e83 100644 --- a/crates/musyx/src/widgets/sidebar.rs +++ b/crates/musyx/src/widgets/sidebar.rs @@ -3,13 +3,15 @@ use iced::widget::{Column, button, column, container, row, space}; use iced::{Alignment, Element, Fill, Padding}; +use ym_api::Account; + use crate::app::Message; use crate::route::Route; use crate::ui::icons::{Icon, icon}; -use crate::ui::theme::{self, Tokens, radius, shell, size}; +use crate::ui::theme::{self, Tokens, shell, size}; use crate::ui::{line, para}; -pub fn view<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { +pub fn view<'a>(t: &'static Tokens, current: Route, me: &'a Account) -> Element<'a, Message> { let nav = Column::with_children(Route::NAV.map(|route| nav_item(t, route, route == current))) .spacing(2); @@ -24,7 +26,7 @@ pub fn view<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { .padding(Padding::default().left(10).right(2)); let playlists = container(para( - "Your playlists appear here after you sign in.", + "Your playlists will be listed here.", size::META, t.muted, )) @@ -35,7 +37,7 @@ pub fn view<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { nav, column![playlists_head, playlists].spacing(6), space().height(Fill), - account(t, current), + account(t, current, me), ] .spacing(22) .padding(Padding::default().top(18).bottom(12).left(12).right(12)) @@ -44,7 +46,7 @@ pub fn view<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { .into() } -pub fn wordmark<'a>(t: &'static Tokens) -> Element<'a, Message> { +pub fn wordmark<'a, M: 'a>(t: &'static Tokens) -> Element<'a, M> { row![ line("musyx", theme::DISPLAY, size::WORDMARK, t.fg), container(space()).width(7).height(7).style(theme::accent_dot), @@ -72,15 +74,16 @@ fn nav_item<'a>(t: &'static Tokens, route: Route, active: bool) -> Element<'a, M .into() } -/// Signed-out state; becomes the avatar, login and subscription once sign-in lands. -fn account<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { - let avatar = container(line("?", theme::SEMIBOLD, size::BODY, t.muted)) +fn account<'a>(t: &'static Tokens, current: Route, account: &'a Account) -> Element<'a, Message> { + let avatar = container(line(account.initial().to_string(), theme::SEMIBOLD, size::BODY, iced::Color::from_rgb8(0x1C, 0x1A, 0x22))) .center(32) - .style(move |_| iced::widget::container::Style { - background: Some(t.raised.into()), - border: iced::Border { radius: radius::PILL.into(), ..Default::default() }, - ..Default::default() - }); + .style(theme::avatar); + + let (plan, plan_colour) = if account.has_plus { + ("Plus subscription", t.ok) + } else { + ("No Plus: 30-second previews", t.muted) + }; let settings_active = current == Route::Settings; column![ @@ -88,14 +91,12 @@ fn account<'a>(t: &'static Tokens, current: Route) -> Element<'a, Message> { row![ avatar, column![ - line("Not signed in", theme::MEDIUM, 13.5, t.fg), - button(line("Sign in", theme::MEDIUM, size::SMALL, t.accent)) - .padding(0) - .style(theme::tab(false)) - .on_press(Message::Navigate(Route::SignIn)), + line(&account.name, theme::MEDIUM, 13.5, t.fg), + line(plan, theme::BODY, 12.0, plan_colour), ] .spacing(1) - .width(Fill), + .width(Fill) + .clip(true), button(icon(Icon::Settings, if settings_active { t.accent } else { t.muted })) .padding(8) .style(theme::icon_button(None)) diff --git a/crates/ym-api/Cargo.toml b/crates/ym-api/Cargo.toml index 883bae6..aab0dd5 100644 --- a/crates/ym-api/Cargo.toml +++ b/crates/ym-api/Cargo.toml @@ -7,6 +7,13 @@ license.workspace = true publish.workspace = true [dependencies] +yamuse = "0.3.2" +serde = { version = "1", features = ["derive"] } +thiserror = "2" + +[dev-dependencies] +serde_json = "1" +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } [lints] workspace = true diff --git a/crates/ym-api/src/auth.rs b/crates/ym-api/src/auth.rs new file mode 100644 index 0000000..43b488b --- /dev/null +++ b/crates/ym-api/src/auth.rs @@ -0,0 +1,207 @@ +//! Yandex OAuth device flow: show a code, the user confirms it on Yandex's +//! page, poll until a token arrives. +//! +//! Uses the official Android app's public client id (via `yamuse`), because +//! third parties can't register an app for the music API. + +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +use serde::{Deserialize, Serialize}; + +use crate::{Error, Result}; + +/// Shown on Yandex's list of signed-in devices. +const DEVICE_NAME: &str = "Musyx"; +/// Yandex rate-limits polling; faster than this turns a pending login into a rejected one. +const MIN_POLL: Duration = Duration::from_secs(3); +/// Refresh once less than this much lifetime is left. +const REFRESH_MARGIN: Duration = Duration::from_secs(7 * 24 * 3600); + +/// A pending sign-in: what to show the user and what to poll with. +#[derive(Clone, PartialEq, Eq)] +pub struct DeviceCode { + pub user_code: String, + pub verification_url: String, + pub expires_in: Duration, + pub interval: Duration, + device_code: String, +} + +impl std::fmt::Debug for DeviceCode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("DeviceCode") + .field("user_code", &self.user_code) + .field("verification_url", &self.verification_url) + .field("expires_in", &self.expires_in) + .field("interval", &self.interval) + .finish_non_exhaustive() + } +} + +/// What the keychain stores. `Debug` never prints the tokens. +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Credentials { + pub access_token: String, + #[serde(default)] + pub refresh_token: Option, + /// Unix seconds; `None` when Yandex didn't say (pasted tokens). + #[serde(default)] + pub expires_at: Option, +} + +impl std::fmt::Debug for Credentials { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Credentials") + .field("access_token", &"") + .field("refresh_token", &self.refresh_token.as_ref().map(|_| "")) + .field("expires_at", &self.expires_at) + .finish() + } +} + +impl Credentials { + /// A token the user pasted. Its lifetime is unknown, so it is never refreshed. + pub fn from_token(token: impl Into) -> Self { + Self { access_token: token.into().trim().to_owned(), refresh_token: None, expires_at: None } + } + + /// True when the token expires within a week and can be refreshed. + pub fn needs_refresh(&self, now: SystemTime) -> bool { + let (Some(_), Some(expires_at)) = (&self.refresh_token, self.expires_at) else { + return false; + }; + let now = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs(); + expires_at.saturating_sub(now) < REFRESH_MARGIN.as_secs() + } + + fn from_oauth(token: yamuse::models::OAuthToken, now: SystemTime) -> Result { + let access_token = token + .access_token + .filter(|t| !t.is_empty()) + .ok_or_else(|| Error::Api("token response carried no access token".into()))?; + let now = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs(); + Ok(Self { + access_token, + refresh_token: token.refresh_token.filter(|t| !t.is_empty()), + expires_at: token.expires_in.map(|s| now + s), + }) + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Poll { + /// The user hasn't confirmed yet. Keep polling at `DeviceCode::interval`. + Pending, + Granted(Credentials), +} + +/// Talks to oauth.yandex.ru. Cheap to clone. +#[derive(Debug, Clone)] +pub struct Auth { + client: yamuse::Client, + options: yamuse::DeviceAuthOptions, +} + +impl Auth { + pub fn new() -> Result { + Ok(Self { + client: yamuse::Client::anonymous()?, + options: yamuse::DeviceAuthOptions { + device_name: DEVICE_NAME.to_owned(), + ..Default::default() + }, + }) + } + + pub async fn request_code(&self) -> Result { + let code = self.client.request_device_code(&self.options).await?; + let missing = |what: &str| Error::Api(format!("device code response carried no {what}")); + Ok(DeviceCode { + device_code: code.device_code.ok_or_else(|| missing("device code"))?, + user_code: code.user_code.ok_or_else(|| missing("user code"))?, + verification_url: code + .verification_url + .unwrap_or_else(|| "https://ya.ru/device".to_owned()), + expires_in: Duration::from_secs(code.expires_in.unwrap_or(300)), + interval: Duration::from_secs(code.interval.unwrap_or(5)).max(MIN_POLL), + }) + } + + /// Poll once. `Pending` is the normal answer until the user confirms. + pub async fn poll(&self, code: &DeviceCode) -> Result { + match self.client.poll_device_token(&code.device_code, &self.options).await? { + None => Ok(Poll::Pending), + Some(token) => Ok(Poll::Granted(Credentials::from_oauth(token, SystemTime::now())?)), + } + } + + /// Swap a refresh token for a new pair. Store the result: Yandex rotates the refresh token. + pub async fn refresh(&self, credentials: &Credentials) -> Result { + let refresh = credentials + .refresh_token + .as_deref() + .ok_or_else(|| Error::Unauthorized("no refresh token".into()))?; + let token = self.client.refresh_token(refresh, &self.options).await?; + let mut fresh = Credentials::from_oauth(token, SystemTime::now())?; + // Keep the old refresh token if Yandex didn't rotate it. + if fresh.refresh_token.is_none() { + fresh.refresh_token = credentials.refresh_token.clone(); + } + Ok(fresh) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn at(secs: u64) -> SystemTime { + UNIX_EPOCH + Duration::from_secs(secs) + } + + #[test] + fn debug_never_prints_tokens() { + let c = Credentials { + access_token: "secret-access".into(), + refresh_token: Some("secret-refresh".into()), + expires_at: Some(10), + }; + let shown = format!("{c:?}"); + assert!(!shown.contains("secret"), "{shown}"); + } + + #[test] + fn credentials_round_trip_and_tolerate_old_shape() { + let c = Credentials { access_token: "a".into(), refresh_token: Some("r".into()), expires_at: Some(5) }; + let json = serde_json::to_string(&c).unwrap(); + assert_eq!(serde_json::from_str::(&json).unwrap(), c); + let bare: Credentials = serde_json::from_str(r#"{"access_token":"a"}"#).unwrap(); + assert_eq!(bare, Credentials::from_token("a")); + } + + #[test] + fn refresh_only_near_expiry_and_only_with_refresh_token() { + let week = 7 * 24 * 3600; + let c = Credentials { access_token: "a".into(), refresh_token: Some("r".into()), expires_at: Some(10 * week) }; + assert!(!c.needs_refresh(at(8 * week))); + assert!(c.needs_refresh(at(9 * week + 1))); + assert!(c.needs_refresh(at(11 * week))); + let pasted = Credentials::from_token(" a \n"); + assert_eq!(pasted.access_token, "a"); + assert!(!pasted.needs_refresh(at(u64::MAX / 2))); + } + + #[test] + fn oauth_token_converts_with_absolute_expiry() { + let token = yamuse::models::OAuthToken { + access_token: Some("a".into()), + refresh_token: Some(String::new()), + expires_in: Some(100), + token_type: Some("bearer".into()), + }; + let c = Credentials::from_oauth(token, at(1_000)).unwrap(); + assert_eq!(c.expires_at, Some(1_100)); + assert_eq!(c.refresh_token, None); + assert!(Credentials::from_oauth(Default::default(), at(0)).is_err()); + } +} diff --git a/crates/ym-api/src/client.rs b/crates/ym-api/src/client.rs new file mode 100644 index 0000000..7ddd3d9 --- /dev/null +++ b/crates/ym-api/src/client.rs @@ -0,0 +1,113 @@ +use crate::Result; +use crate::auth::Credentials; + +/// The signed-in user as the UI needs them. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Account { + pub uid: i64, + pub login: String, + /// Best human-readable name: display name, then full name, then login. + pub name: String, + /// Yandex Plus unlocks full-length tracks; without it the API serves 30-second previews. + pub has_plus: bool, + /// When the current subscription ends, as Yandex formats it (ISO 8601). + pub subscription_end: Option, +} + +impl Account { + /// One letter for the avatar. + pub fn initial(&self) -> char { + self.name.chars().find(|c| c.is_alphanumeric()).map_or('?', |c| { + c.to_uppercase().next().unwrap_or(c) + }) + } + + fn from_status(status: yamuse::models::Status) -> Option { + let account = status.account?; + let uid = account.uid?; + let login = account.login.unwrap_or_default(); + let non_empty = |s: Option| s.filter(|s| !s.trim().is_empty()); + let name = non_empty(account.display_name) + .or_else(|| non_empty(account.full_name)) + .unwrap_or_else(|| login.clone()); + Some(Self { + uid, + login, + name, + has_plus: status.plus.and_then(|p| p.has_plus).unwrap_or(false), + subscription_end: status.subscription.and_then(|s| { + s.end.or_else(|| s.auto_renewable.into_iter().find_map(|a| a.expires)) + }), + }) + } +} + +/// An authenticated API client. Cheap to clone. +#[derive(Debug, Clone)] +pub struct YmClient { + inner: yamuse::Client, +} + +impl YmClient { + /// Builds a client for `credentials` and loads the account. Fails with + /// [`crate::Error::Unauthorized`] when the token is no longer valid. + pub async fn connect(credentials: &Credentials) -> Result<(Self, Account)> { + let inner = yamuse::Client::builder().token(&credentials.access_token).build()?; + let status = inner.refresh_account().await?; + let account = Account::from_status(status) + .ok_or_else(|| crate::Error::Unauthorized("account status has no user".into()))?; + Ok((Self { inner }, account)) + } + + /// A client with no token, for previews and tests. Every account call fails. + pub fn unauthenticated() -> Result { + Ok(Self { inner: yamuse::Client::anonymous()? }) + } + + /// Re-reads the account, e.g. after a subscription may have changed. + pub async fn account(&self) -> Result { + let status = self.inner.refresh_account().await?; + Account::from_status(status) + .ok_or_else(|| crate::Error::Unauthorized("account status has no user".into())) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn status(json: &str) -> yamuse::models::Status { + serde_json::from_str(json).unwrap() + } + + #[test] + fn account_prefers_display_name_and_reads_plus() { + let a = Account::from_status(status( + r#"{"account":{"uid":42,"login":"yuriy.panov","displayName":"Юрий","fullName":"Юрий Панов"}, + "plus":{"hasPlus":true},"subscription":{"end":"2027-01-01T00:00:00+03:00"}}"#, + )) + .unwrap(); + assert_eq!(a.uid, 42); + assert_eq!(a.name, "Юрий"); + assert_eq!(a.initial(), 'Ю'); + assert!(a.has_plus); + assert_eq!(a.subscription_end.as_deref(), Some("2027-01-01T00:00:00+03:00")); + } + + #[test] + fn account_falls_back_to_login_and_no_plus() { + let a = Account::from_status(status( + r#"{"account":{"uid":7,"login":"listener","displayName":" "}}"#, + )) + .unwrap(); + assert_eq!(a.name, "listener"); + assert!(!a.has_plus); + assert_eq!(a.subscription_end, None); + } + + #[test] + fn anonymous_status_is_not_an_account() { + assert!(Account::from_status(status(r#"{"account":{"now":"2026-10-15"}}"#)).is_none()); + assert!(Account::from_status(status("{}")).is_none()); + } +} diff --git a/crates/ym-api/src/error.rs b/crates/ym-api/src/error.rs new file mode 100644 index 0000000..37bd8f2 --- /dev/null +++ b/crates/ym-api/src/error.rs @@ -0,0 +1,76 @@ +/// Errors the app can act on. Messages are for logs, not for display. +#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)] +pub enum Error { + /// The token is missing, revoked or expired. Sign in again. + #[error("unauthorized: {0}")] + Unauthorized(String), + /// The sign-in code ran out before the user confirmed it. + #[error("sign-in code expired")] + CodeExpired, + /// The user declined access on Yandex's page. + #[error("sign-in was declined")] + Denied, + /// No connection, DNS failure, timeout: worth retrying. + #[error("network: {0}")] + Network(String), + /// Anything else the server or the decoder rejected. + #[error("api: {0}")] + Api(String), +} + +pub type Result = std::result::Result; + +impl Error { + pub fn is_retryable(&self) -> bool { + matches!(self, Error::Network(_)) + } +} + +impl From for Error { + fn from(e: yamuse::Error) -> Self { + use yamuse::Error as Y; + match e { + Y::Unauthorized(m) => Error::Unauthorized(m), + Y::Network(m) => Error::Network(m), + Y::TimedOut => Error::Network("timed out".into()), + Y::RateLimited { message, .. } => Error::Network(message), + Y::DeviceAuth(m) => classify_oauth(&m), + other => Error::Api(other.to_string()), + } + } +} + +/// OAuth rejections arrive as free text carrying the RFC 8628 error code. +fn classify_oauth(message: &str) -> Error { + let m = message.to_ascii_lowercase(); + if m.contains("expired") || m.contains("timed out") { + Error::CodeExpired + } else if m.contains("denied") { + Error::Denied + } else if m.contains("invalid_grant") || m.contains("bad refresh") { + Error::Unauthorized(message.to_owned()) + } else { + Error::Api(message.to_owned()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn oauth_codes_map_to_actionable_errors() { + assert_eq!(classify_oauth("expired_token: code expired"), Error::CodeExpired); + assert_eq!(classify_oauth("device authorization timed out"), Error::CodeExpired); + assert_eq!(classify_oauth("access_denied"), Error::Denied); + assert!(matches!(classify_oauth("invalid_grant"), Error::Unauthorized(_))); + assert!(matches!(classify_oauth("something new"), Error::Api(_))); + } + + #[test] + fn only_network_errors_retry() { + assert!(Error::Network("dns".into()).is_retryable()); + assert!(!Error::Unauthorized(String::new()).is_retryable()); + assert!(!Error::CodeExpired.is_retryable()); + } +} diff --git a/crates/ym-api/src/lib.rs b/crates/ym-api/src/lib.rs index dbe0d20..57c5bc4 100644 --- a/crates/ym-api/src/lib.rs +++ b/crates/ym-api/src/lib.rs @@ -1,4 +1,11 @@ //! Client for the unofficial Yandex Music API. //! -//! Filled in by milestone 3 (sign-in) onwards; the app depends on this crate's -//! own types only, never on whichever upstream wrapper it uses internally. +//! Wraps [`yamuse`] so the app only ever sees this crate's own types: if the +//! upstream wrapper changes or is swapped out, the UI doesn't move. + +pub mod auth; +mod client; +mod error; + +pub use client::{Account, YmClient}; +pub use error::{Error, Result}; diff --git a/crates/ym-api/tests/live.rs b/crates/ym-api/tests/live.rs new file mode 100644 index 0000000..bda213d --- /dev/null +++ b/crates/ym-api/tests/live.rs @@ -0,0 +1,15 @@ +//! Talks to the real Yandex servers. Run with `cargo test -p ym-api -- --ignored`. + +use ym_api::auth::{Auth, Poll}; + +#[tokio::test] +#[ignore = "network"] +async fn device_code_is_issued_and_pending() { + let auth = Auth::new().unwrap(); + let code = auth.request_code().await.expect("device code"); + assert!(!code.user_code.is_empty()); + assert!(code.verification_url.starts_with("https://")); + assert!(code.interval.as_secs() >= 3); + // Nobody confirmed it, so the first poll must say "pending", not fail. + assert_eq!(auth.poll(&code).await.expect("poll"), Poll::Pending); +}