diff --git a/Cargo.lock b/Cargo.lock index 68c82ab..10b68eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -679,9 +679,9 @@ dependencies = [ "log", "mint", "naga", - "objc2", + "objc2 0.5.2", "objc2-app-kit", - "objc2-foundation", + "objc2-foundation 0.2.2", "objc2-metal", "objc2-quartz-core", "objc2-ui-kit", @@ -742,7 +742,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" dependencies = [ - "objc2", + "objc2 0.5.2", ] [[package]] @@ -873,9 +873,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.20" +version = "1.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04da6a0d40b948dfc4fa8f5bbf402b0fc1a64a28dbf7d12ffd683550f2c1b63a" +checksum = "8691782945451c1c383942c4874dbe63814f61cb57ef773cda2972682b7bb3c0" dependencies = [ "jobserver", "libc", @@ -1136,7 +1136,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "indexmap", "rustc-hash 2.1.1", @@ -1242,6 +1242,7 @@ dependencies = [ "smol", "tracing-subscriber", "ui", + "webbrowser", ] [[package]] @@ -1525,7 +1526,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "proc-macro2", "quote", @@ -2316,7 +2317,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2408,7 +2409,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "proc-macro2", "quote", @@ -2632,7 +2633,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "bytes", @@ -2649,7 +2650,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "rustls", "rustls-platform-verifier", @@ -3213,9 +3214,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" +checksum = "a25169bd5913a4b437588a7e3d127cd6e90127b60e0ffbd834a38f1599e016b8" [[package]] name = "libredox" @@ -3390,7 +3391,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "bindgen 0.71.1", @@ -3538,6 +3539,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + [[package]] name = "negentropy" version = "0.5.0" @@ -3582,7 +3589,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "aes", "base64", @@ -3607,7 +3614,7 @@ dependencies = [ [[package]] name = "nostr-connect" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "async-utility", "nostr", @@ -3619,7 +3626,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "flatbuffers", "lru", @@ -3630,7 +3637,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "async-utility", "heed", @@ -3643,7 +3650,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "async-utility", "async-wsocket", @@ -3659,7 +3666,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.41.0" -source = "git+https://github.com/rust-nostr/nostr#5a2e66874c6e6cb0f5b8bcb50c1d37aecd7a5d90" +source = "git+https://github.com/rust-nostr/nostr?branch=nip46#63609d9c7e62b16c26fa59b255284f3a292bea24" dependencies = [ "async-utility", "nostr", @@ -3839,6 +3846,15 @@ dependencies = [ "objc2-encode", ] +[[package]] +name = "objc2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551" +dependencies = [ + "objc2-encode", +] + [[package]] name = "objc2-app-kit" version = "0.2.2" @@ -3848,10 +3864,10 @@ dependencies = [ "bitflags 2.9.0", "block2", "libc", - "objc2", + "objc2 0.5.2", "objc2-core-data", "objc2-core-image", - "objc2-foundation", + "objc2-foundation 0.2.2", "objc2-quartz-core", ] @@ -3863,9 +3879,9 @@ checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", + "objc2 0.5.2", "objc2-core-location", - "objc2-foundation", + "objc2-foundation 0.2.2", ] [[package]] @@ -3875,8 +3891,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" dependencies = [ "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -3887,8 +3903,8 @@ checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -3898,8 +3914,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" dependencies = [ "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", "objc2-metal", ] @@ -3910,9 +3926,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" dependencies = [ "block2", - "objc2", + "objc2 0.5.2", "objc2-contacts", - "objc2-foundation", + "objc2-foundation 0.2.2", ] [[package]] @@ -3930,7 +3946,17 @@ dependencies = [ "bitflags 2.9.0", "block2", "libc", - "objc2", + "objc2 0.5.2", +] + +[[package]] +name = "objc2-foundation" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c" +dependencies = [ + "bitflags 2.9.0", + "objc2 0.6.1", ] [[package]] @@ -3940,9 +3966,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" dependencies = [ "block2", - "objc2", + "objc2 0.5.2", "objc2-app-kit", - "objc2-foundation", + "objc2-foundation 0.2.2", ] [[package]] @@ -3953,8 +3979,8 @@ checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -3965,8 +3991,8 @@ checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", "objc2-metal", ] @@ -3976,8 +4002,8 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a684efe3dec1b305badae1a28f6555f6ddd3bb2c2267896782858d5a78404dc" dependencies = [ - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -3988,12 +4014,12 @@ checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", + "objc2 0.5.2", "objc2-cloud-kit", "objc2-core-data", "objc2-core-image", "objc2-core-location", - "objc2-foundation", + "objc2-foundation 0.2.2", "objc2-link-presentation", "objc2-quartz-core", "objc2-symbols", @@ -4008,8 +4034,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" dependencies = [ "block2", - "objc2", - "objc2-foundation", + "objc2 0.5.2", + "objc2-foundation 0.2.2", ] [[package]] @@ -4020,9 +4046,9 @@ checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" dependencies = [ "bitflags 2.9.0", "block2", - "objc2", + "objc2 0.5.2", "objc2-core-location", - "objc2-foundation", + "objc2-foundation 0.2.2", ] [[package]] @@ -4795,9 +4821,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.11" +version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f103c6d277498fbceb16e84d317e2a400f160f46904d5f5410848c829511a3" +checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" dependencies = [ "bitflags 2.9.0", ] @@ -4816,7 +4842,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "derive_refineable", "workspace-hack", @@ -4955,7 +4981,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "bytes", @@ -5425,7 +5451,7 @@ checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "serde", @@ -5748,7 +5774,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "arrayvec", "log", @@ -6658,7 +6684,7 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#afeb3d4fd94fae5cfc635e8a4f6eb56c8aae67fd" +source = "git+https://github.com/zed-industries/zed#45fe158bc9179d1357617f9fa2cc6c3c203daa6b" dependencies = [ "anyhow", "async-fs", @@ -7019,6 +7045,23 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webbrowser" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5df295f8451142f1856b1bd86a606dfe9587d439bc036e319c827700dbd555e" +dependencies = [ + "core-foundation 0.10.0", + "home", + "jni", + "log", + "ndk-context", + "objc2 0.6.1", + "objc2-foundation 0.3.1", + "url", + "web-sys", +] + [[package]] name = "webpki-root-certs" version = "0.26.10" @@ -7577,9 +7620,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb8234a863ea0e8cd7284fcdd4f145233eb00fee02bbdd9861aec44e6477bc5" +checksum = "d9fb597c990f03753e08d3c29efbfcf2019a003b4bf4ba19225c158e1549f0f3" dependencies = [ "memchr", ] @@ -7687,16 +7730,6 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" -[[package]] -name = "xdg-home" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1cdab258fb55c0da61328dc52c8764709b249011b2cad0454c72f0bf10a1f6" -dependencies = [ - "libc", - "windows-sys 0.59.0", -] - [[package]] name = "xim" version = "0.4.0" @@ -7793,13 +7826,12 @@ dependencies = [ [[package]] name = "zbus" -version = "5.5.0" +version = "5.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59c333f648ea1b647bc95dc1d34807c8e25ed7a6feff3394034dc4776054b236" +checksum = "2522b82023923eecb0b366da727ec883ace092e7887b61d3da5139f26b44da58" dependencies = [ "async-broadcast", "async-executor", - "async-fs", "async-io", "async-lock", "async-process", @@ -7816,12 +7848,10 @@ dependencies = [ "ordered-stream", "serde", "serde_repr", - "static_assertions", "tracing", "uds_windows", "windows-sys 0.59.0", "winnow", - "xdg-home", "zbus_macros", "zbus_names", "zvariant", @@ -7829,9 +7859,9 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "5.5.0" +version = "5.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f325ad10eb0d0a3eb060203494c3b7ec3162a01a59db75d2deee100339709fc0" +checksum = "05d2e12843c75108c00c618c2e8ef9675b50b6ec095b36dc965f2e5aed463c15" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -7989,14 +8019,13 @@ dependencies = [ [[package]] name = "zvariant" -version = "5.4.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2df9ee044893fcffbdc25de30546edef3e32341466811ca18421e3cd6c5a3ac" +checksum = "557e89d54880377a507c94cd5452f20e35d14325faf9d2958ebeadce0966c1b2" dependencies = [ "endi", "enumflags2", "serde", - "static_assertions", "url", "winnow", "zvariant_derive", @@ -8005,9 +8034,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "5.4.0" +version = "5.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74170caa85b8b84cc4935f2d56a57c7a15ea6185ccdd7eadb57e6edd90f94b2f" +checksum = "757779842a0d242061d24c28be589ce392e45350dfb9186dfd7a042a2e19870c" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index d826110..b702a6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,18 +16,10 @@ gpui = { git = "https://github.com/zed-industries/zed" } reqwest_client = { git = "https://github.com/zed-industries/zed" } # Nostr -nostr = { git = "https://github.com/rust-nostr/nostr", features = ["parser"] } -nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr" } -nostr-connect = { git = "https://github.com/rust-nostr/nostr" } -nostr-keyring = { git = "https://github.com/rust-nostr/nostr" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [ - "lmdb", - "nip96", - "nip59", - "nip49", - "nip44", - "nip05", -] } +nostr = { git = "https://github.com/rust-nostr/nostr", branch = "nip46", features = ["parser"] } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", branch = "nip46", features = ["lmdb", "nip96", "nip59", "nip49", "nip44", "nip05"] } +nostr-connect = { git = "https://github.com/rust-nostr/nostr", branch = "nip46" } +nostr-keyring = { git = "https://github.com/rust-nostr/nostr", branch = "nip46" } # Others emojis = "0.6.4" diff --git a/crates/account/src/lib.rs b/crates/account/src/lib.rs index 5ce961c..700015a 100644 --- a/crates/account/src/lib.rs +++ b/crates/account/src/lib.rs @@ -38,13 +38,10 @@ impl Account { { let task: Task> = cx.background_spawn(async move { let client = get_client(); - // Use user's signer for main signer - _ = client.set_signer(signer).await; - - // Verify nostr signer and get public key - let signer = client.signer().await?; let public_key = signer.get_public_key().await?; - log::info!("Logged in with public key: {:?}", public_key); + + // Update signer + client.set_signer(signer).await; // Fetch user's metadata let metadata = client diff --git a/crates/coop/Cargo.toml b/crates/coop/Cargo.toml index a97bfe8..fe25487 100644 --- a/crates/coop/Cargo.toml +++ b/crates/coop/Cargo.toml @@ -33,6 +33,7 @@ smallvec.workspace = true smol.workspace = true oneshot.workspace = true +webbrowser = "1.0.4" rustls = "0.23.23" futures = "0.3" tracing-subscriber = { version = "0.3.18", features = ["fmt"] } diff --git a/crates/coop/src/main.rs b/crates/coop/src/main.rs index cfa000a..549fcd0 100644 --- a/crates/coop/src/main.rs +++ b/crates/coop/src/main.rs @@ -110,7 +110,7 @@ fn main() { // Handle batch metadata app.background_executor() .spawn(async move { - const BATCH_SIZE: usize = 500; + const BATCH_SIZE: usize = 20; const BATCH_TIMEOUT: Duration = Duration::from_millis(300); let mut batch: HashSet = HashSet::new(); @@ -143,7 +143,7 @@ fn main() { // Handle notifications app.background_executor() .spawn(async move { - let rng_keys = Keys::generate(); + let keys = Keys::generate(); let all_id = SubscriptionId::new(ALL_MESSAGES_SUB_ID); let new_id = SubscriptionId::new(NEW_MESSAGE_SUB_ID); let mut notifications = client.notifications(); @@ -161,12 +161,12 @@ fn main() { Ok(event) => event, Err(_) => match client.unwrap_gift_wrap(&event).await { Ok(unwrap) => { - match unwrap.rumor.sign_with_keys(&rng_keys) { - Ok(ev) => { - set_unwrapped(event.id, &ev, &rng_keys) + match unwrap.rumor.sign_with_keys(&keys) { + Ok(unwrapped) => { + set_unwrapped(event.id, &unwrapped, &keys) .await .ok(); - ev + unwrapped } Err(_) => continue, } @@ -286,6 +286,7 @@ fn main() { // Open a window with default options cx.open_window(opts, |window, cx| { // Automatically sync theme with system appearance + #[cfg(not(target_os = "linux"))] window .observe_window_appearance(|window, cx| { Theme::sync_system_appearance(Some(window), cx); diff --git a/crates/coop/src/views/login.rs b/crates/coop/src/views/login.rs index 1ea2a3a..097b2c0 100644 --- a/crates/coop/src/views/login.rs +++ b/crates/coop/src/views/login.rs @@ -20,7 +20,17 @@ use ui::{ ContextModal, Disableable, Sizable, Size, StyledExt, }; -const INPUT_INVALID: &str = "You must provide a valid Private Key or Bunker."; +#[derive(Debug, Clone)] +struct CoopAuthUrlHandler; + +impl AuthUrlHandler for CoopAuthUrlHandler { + fn on_auth_url(&self, auth_url: Url) -> BoxedFuture> { + Box::pin(async move { + webbrowser::open(auth_url.as_str())?; + Ok(()) + }) + } +} pub fn init(window: &mut Window, cx: &mut App) -> Entity { Login::new(window, cx) @@ -29,19 +39,21 @@ pub fn init(window: &mut Window, cx: &mut App) -> Entity { pub struct Login { // Inputs key_input: Entity, - error_message: Entity>, + error: Entity>, is_logging_in: bool, // Nostr Connect - qr: Option>, + qr: Entity>>, connect_relay: Entity, connect_client: Entity>, + // Keep track of all signers created by nostr connect + signers: SmallVec<[NostrConnect; 3]>, // Panel name: SharedString, closable: bool, zoomable: bool, focus_handle: FocusHandle, #[allow(unused)] - subscriptions: SmallVec<[Subscription; 3]>, + subscriptions: SmallVec<[Subscription; 4]>, } impl Login { @@ -50,9 +62,12 @@ impl Login { } fn view(window: &mut Window, cx: &mut Context) -> Self { + let connect_client: Entity> = cx.new(|_| None); + let error = cx.new(|_| None); + let qr = cx.new(|_| None); + + let signers = smallvec![]; let mut subscriptions = smallvec![]; - let error_message = cx.new(|_| None); - let connect_client = cx.new(|_: &mut Context<'_, Option>| None); let key_input = cx.new(|cx| { TextInput::new(window, cx) @@ -61,7 +76,7 @@ impl Login { }); let connect_relay = cx.new(|cx| { - let mut input = TextInput::new(window, cx).text_size(Size::Small).small(); + let mut input = TextInput::new(window, cx).text_size(Size::XSmall).small(); input.set_text("wss://relay.nsec.app", window, cx); input }); @@ -89,17 +104,32 @@ impl Login { subscriptions.push( cx.observe_in(&connect_client, window, |this, uri, window, cx| { let keys = get_client_keys().to_owned(); - let account = Account::global(cx); if let Some(uri) = uri.read(cx).clone() { if let Ok(qr) = create_qr(uri.to_string().as_str()) { - this.qr = Some(qr); - cx.notify(); + this.qr.update(cx, |this, cx| { + *this = Some(qr); + cx.notify(); + }); } - match NostrConnect::new(uri, keys, Duration::from_secs(300), None) { - Ok(signer) => { - account.update(cx, |this, cx| { + // Shutdown all previous nostr connect clients + for client in std::mem::take(&mut this.signers).into_iter() { + cx.background_spawn(async move { + client.shutdown().await; + }) + .detach(); + } + + // Create a new nostr connect client + match NostrConnect::new(uri, keys, Duration::from_secs(200), None) { + Ok(mut signer) => { + // Handle auth url + signer.auth_url_handler(CoopAuthUrlHandler); + // Store this signer for further clean up + this.signers.push(signer.clone()); + + Account::global(cx).update(cx, |this, cx| { this.login(signer, window, cx); }); } @@ -111,27 +141,16 @@ impl Login { }), ); - cx.spawn(async move |this, cx| { + cx.spawn_in(window, async move |this, cx| { cx.background_executor() - .timer(Duration::from_millis(500)) + .timer(Duration::from_millis(300)) .await; - cx.update(|cx| { + cx.update(|window, cx| { this.update(cx, |this, cx| { - let Ok(relay_url) = - RelayUrl::parse(this.connect_relay.read(cx).text().to_string().as_str()) - else { - return; - }; - - let client_pubkey = get_client_keys().public_key(); - let uri = NostrConnectURI::client(client_pubkey, vec![relay_url], "Coop"); - - this.connect_client.update(cx, |this, cx| { - *this = Some(uri); - cx.notify(); - }); + this.change_relay(window, cx); }) + .ok(); }) .ok(); }) @@ -142,8 +161,9 @@ impl Login { connect_relay, connect_client, subscriptions, - error_message, - qr: None, + signers, + error, + qr, is_logging_in: false, name: "Login".into(), closable: true, @@ -172,33 +192,21 @@ impl Login { }); } Err(e) => { - self.set_error_message(e.to_string(), cx); - self.set_logging_in(false, cx); + self.set_error(e.to_string(), cx); } } } else if content.starts_with("bunker://") { - let keys = get_client_keys().to_owned(); - let Ok(uri) = NostrConnectURI::parse(content.as_ref()) else { - self.set_error_message("Bunker URL is not valid".to_owned(), cx); - self.set_logging_in(false, cx); + self.set_error("Bunker URL is not valid".to_owned(), cx); return; }; - match NostrConnect::new(uri, keys, Duration::from_secs(120), None) { - Ok(signer) => { - account.update(cx, |this, cx| { - this.login(signer, window, cx); - }); - } - Err(e) => { - self.set_error_message(e.to_string(), cx); - self.set_logging_in(false, cx); - } - } + self.connect_client.update(cx, |this, cx| { + *this = Some(uri); + cx.notify(); + }); } else { - window.push_notification(Notification::error(INPUT_INVALID), cx); - self.set_logging_in(false, cx); + self.set_error("You must provide a valid Private Key or Bunker.".into(), cx); }; } @@ -219,8 +227,9 @@ impl Login { }); } - fn set_error_message(&mut self, message: String, cx: &mut Context) { - self.error_message.update(cx, |this, cx| { + fn set_error(&mut self, message: String, cx: &mut Context) { + self.set_logging_in(false, cx); + self.error.update(cx, |this, cx| { *this = Some(SharedString::new(message)); cx.notify(); }); @@ -320,18 +329,15 @@ impl Render for Login { this.login(window, cx); })), ) - .when_some( - self.error_message.read(cx).clone(), - |this, error| { - this.child( - div() - .text_xs() - .text_center() - .text_color(cx.theme().danger) - .child(error), - ) - }, - ), + .when_some(self.error.read(cx).clone(), |this, error| { + this.child( + div() + .text_xs() + .text_center() + .text_color(cx.theme().danger) + .child(error), + ) + }), ), ), ) @@ -372,12 +378,12 @@ impl Render for Login { .child("Use Nostr Connect apps to scan the code"), ), ) - .when_some(self.qr.clone(), |this, qr| { + .when_some(self.qr.read(cx).clone(), |this, qr| { this.child( div() .mb_2() .p_2() - .size_64() + .size_72() .flex() .flex_col() .items_center() @@ -391,7 +397,7 @@ impl Render for Login { ) }) .bg(cx.theme().background) - .child(img(qr).h_56()), + .child(img(qr).h_64()), ) }) .child( @@ -406,7 +412,7 @@ impl Render for Login { Button::new("change") .label("Change") .ghost() - .small() + .xsmall() .on_click(cx.listener(move |this, _, window, cx| { this.change_relay(window, cx); })), diff --git a/crates/coop/src/views/profile.rs b/crates/coop/src/views/profile.rs index 195b989..f98f3a6 100644 --- a/crates/coop/src/views/profile.rs +++ b/crates/coop/src/views/profile.rs @@ -244,6 +244,7 @@ impl Render for Profile { .flex() .flex_col() .gap_3() + .px_3() .child( div() .w_full() @@ -313,7 +314,7 @@ impl Render for Profile { .child(self.bio_input.clone()), ) .child( - div().mt_2().w_full().child( + div().p_3().child( Button::new("submit") .label("Update") .primary()