feat: simple login process

This commit is contained in:
2025-12-19 10:09:29 +07:00
parent d6504a8170
commit a0820a9187
14 changed files with 864 additions and 93 deletions

163
Cargo.lock generated
View File

@@ -197,7 +197,7 @@ dependencies = [
"url", "url",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-protocols 0.32.9", "wayland-protocols",
"zbus", "zbus",
] ]
@@ -1050,9 +1050,9 @@ dependencies = [
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.56" version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b042e5d8a74ae91bb0961acd039822472ec99f8ab0948cbf6d1369588f8be586" checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d"
dependencies = [ dependencies = [
"cc", "cc",
] ]
@@ -1131,7 +1131,7 @@ dependencies = [
[[package]] [[package]]
name = "collections" name = "collections"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
@@ -1520,7 +1520,7 @@ dependencies = [
[[package]] [[package]]
name = "derive_refineable" name = "derive_refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1684,7 +1684,7 @@ dependencies = [
"cc", "cc",
"memchr", "memchr",
"rustc_version", "rustc_version",
"toml 0.9.8", "toml 0.9.10+spec-1.1.0",
"vswhom", "vswhom",
"winreg", "winreg",
] ]
@@ -2402,7 +2402,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui" name = "gpui"
version = "0.2.2" version = "0.2.2"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"as-raw-xcb-connection", "as-raw-xcb-connection",
@@ -2484,7 +2484,7 @@ dependencies = [
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-cursor", "wayland-cursor",
"wayland-protocols 0.31.2", "wayland-protocols",
"wayland-protocols-plasma", "wayland-protocols-plasma",
"wayland-protocols-wlr", "wayland-protocols-wlr",
"windows 0.61.3", "windows 0.61.3",
@@ -2502,7 +2502,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui-component" name = "gpui-component"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/longbridge/gpui-component#749c69c159edff3a7f5f216647816f9ebb1ce970" source = "git+https://github.com/longbridge/gpui-component#88fda3635111d9e9928d3838fea71852e137bda5"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"anyhow", "anyhow",
@@ -2540,7 +2540,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui-component-macros" name = "gpui-component-macros"
version = "0.5.0" version = "0.5.0"
source = "git+https://github.com/longbridge/gpui-component#749c69c159edff3a7f5f216647816f9ebb1ce970" source = "git+https://github.com/longbridge/gpui-component#88fda3635111d9e9928d3838fea71852e137bda5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2562,7 +2562,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui_macros" name = "gpui_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",
@@ -2573,7 +2573,7 @@ dependencies = [
[[package]] [[package]]
name = "gpui_tokio" name = "gpui_tokio"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"gpui", "gpui",
@@ -2800,7 +2800,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client" name = "http_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-compression", "async-compression",
@@ -2825,7 +2825,7 @@ dependencies = [
[[package]] [[package]]
name = "http_client_tls" name = "http_client_tls"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"rustls", "rustls",
"rustls-platform-verifier", "rustls-platform-verifier",
@@ -3522,6 +3522,7 @@ dependencies = [
"nostr-connect", "nostr-connect",
"nostr-sdk", "nostr-sdk",
"person", "person",
"qrcode",
"reqwest_client", "reqwest_client",
"serde", "serde",
"serde_json", "serde_json",
@@ -3529,6 +3530,7 @@ dependencies = [
"smol", "smol",
"state", "state",
"tracing-subscriber", "tracing-subscriber",
"webbrowser",
] ]
[[package]] [[package]]
@@ -3666,7 +3668,7 @@ dependencies = [
[[package]] [[package]]
name = "media" name = "media"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bindgen", "bindgen",
@@ -3828,6 +3830,12 @@ dependencies = [
"tempfile", "tempfile",
] ]
[[package]]
name = "ndk-context"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b"
[[package]] [[package]]
name = "negentropy" name = "negentropy"
version = "0.5.0" version = "0.5.0"
@@ -3902,7 +3910,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr" name = "nostr"
version = "0.44.1" version = "0.44.1"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"aes", "aes",
"base64", "base64",
@@ -3915,7 +3923,7 @@ dependencies = [
"hex", "hex",
"instant", "instant",
"once_cell", "once_cell",
"rand 0.8.5", "rand 0.9.2",
"scrypt", "scrypt",
"secp256k1", "secp256k1",
"serde", "serde",
@@ -3927,7 +3935,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-connect" name = "nostr-connect"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"nostr", "nostr",
@@ -3939,7 +3947,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-database" name = "nostr-database"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"btreecap", "btreecap",
"flatbuffers", "flatbuffers",
@@ -3951,7 +3959,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-gossip" name = "nostr-gossip"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"nostr", "nostr",
] ]
@@ -3959,7 +3967,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-gossip-memory" name = "nostr-gossip-memory"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"lru", "lru",
@@ -3971,7 +3979,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-lmdb" name = "nostr-lmdb"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"flume 0.11.1", "flume 0.11.1",
@@ -3985,7 +3993,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-relay-pool" name = "nostr-relay-pool"
version = "0.44.0" version = "0.44.0"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"async-wsocket", "async-wsocket",
@@ -4002,7 +4010,7 @@ dependencies = [
[[package]] [[package]]
name = "nostr-sdk" name = "nostr-sdk"
version = "0.44.1" version = "0.44.1"
source = "git+https://github.com/rust-nostr/nostr#577390dd1ffd7bc1fc577a96b9334b7894212dea" source = "git+https://github.com/rust-nostr/nostr#8eafecf1151110b698a51c674caa3d23ddd61368"
dependencies = [ dependencies = [
"async-utility", "async-utility",
"nostr", "nostr",
@@ -4545,7 +4553,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]] [[package]]
name = "perf" name = "perf"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"collections", "collections",
"serde", "serde",
@@ -4787,7 +4795,7 @@ version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983"
dependencies = [ dependencies = [
"toml_edit 0.23.9", "toml_edit 0.23.10+spec-1.0.0",
] ]
[[package]] [[package]]
@@ -4868,6 +4876,15 @@ dependencies = [
"bytemuck", "bytemuck",
] ]
[[package]]
name = "qrcode"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec"
dependencies = [
"image",
]
[[package]] [[package]]
name = "quick-error" name = "quick-error"
version = "2.0.1" version = "2.0.1"
@@ -5186,7 +5203,7 @@ dependencies = [
[[package]] [[package]]
name = "refineable" name = "refineable"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"derive_refineable", "derive_refineable",
] ]
@@ -5267,7 +5284,7 @@ dependencies = [
[[package]] [[package]]
name = "reqwest_client" name = "reqwest_client"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@@ -5508,9 +5525,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.13.1" version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "708c0f9d5f54ba0272468c1d306a52c495b31fa155e91bc25371e6df7996908c" checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282"
dependencies = [ dependencies = [
"web-time", "web-time",
"zeroize", "zeroize",
@@ -5878,9 +5895,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_spanned" name = "serde_spanned"
version = "1.0.3" version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392" checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"
dependencies = [ dependencies = [
"serde_core", "serde_core",
] ]
@@ -6245,7 +6262,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "sum_tree" name = "sum_tree"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"log", "log",
@@ -6741,14 +6758,14 @@ dependencies = [
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.9.8" version = "0.9.10+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8" checksum = "0825052159284a1a8b4d6c0c86cbc801f2da5afd2b225fa548c72f2e74002f48"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"serde_core", "serde_core",
"serde_spanned 1.0.3", "serde_spanned 1.0.4",
"toml_datetime 0.7.3", "toml_datetime 0.7.5+spec-1.1.0",
"toml_parser", "toml_parser",
"toml_writer", "toml_writer",
"winnow", "winnow",
@@ -6765,9 +6782,9 @@ dependencies = [
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.7.3" version = "0.7.5+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"
dependencies = [ dependencies = [
"serde_core", "serde_core",
] ]
@@ -6788,21 +6805,21 @@ dependencies = [
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.23.9" version = "0.23.10+spec-1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d7cbc3b4b49633d57a0509303158ca50de80ae32c265093b24c414705807832" checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"toml_datetime 0.7.3", "toml_datetime 0.7.5+spec-1.1.0",
"toml_parser", "toml_parser",
"winnow", "winnow",
] ]
[[package]] [[package]]
name = "toml_parser" name = "toml_parser"
version = "1.0.4" version = "1.0.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44"
dependencies = [ dependencies = [
"winnow", "winnow",
] ]
@@ -6815,9 +6832,9 @@ checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
[[package]] [[package]]
name = "toml_writer" name = "toml_writer"
version = "1.0.4" version = "1.0.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2" checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"
[[package]] [[package]]
name = "tower" name = "tower"
@@ -6866,9 +6883,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.43" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [ dependencies = [
"log", "log",
"pin-project-lite", "pin-project-lite",
@@ -6889,9 +6906,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.35" version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable", "valuable",
@@ -7201,7 +7218,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]] [[package]]
name = "util" name = "util"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-fs", "async-fs",
@@ -7237,7 +7254,7 @@ dependencies = [
[[package]] [[package]]
name = "util_macros" name = "util_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"perf", "perf",
"quote", "quote",
@@ -7490,18 +7507,6 @@ dependencies = [
"xcursor", "xcursor",
] ]
[[package]]
name = "wayland-protocols"
version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4"
dependencies = [
"bitflags 2.10.0",
"wayland-backend",
"wayland-client",
"wayland-scanner",
]
[[package]] [[package]]
name = "wayland-protocols" name = "wayland-protocols"
version = "0.32.9" version = "0.32.9"
@@ -7516,14 +7521,14 @@ dependencies = [
[[package]] [[package]]
name = "wayland-protocols-plasma" name = "wayland-protocols-plasma"
version = "0.2.0" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" checksum = "a07a14257c077ab3279987c4f8bb987851bf57081b93710381daea94f2c2c032"
dependencies = [ dependencies = [
"bitflags 2.10.0", "bitflags 2.10.0",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-protocols 0.31.2", "wayland-protocols",
"wayland-scanner", "wayland-scanner",
] ]
@@ -7536,7 +7541,7 @@ dependencies = [
"bitflags 2.10.0", "bitflags 2.10.0",
"wayland-backend", "wayland-backend",
"wayland-client", "wayland-client",
"wayland-protocols 0.32.9", "wayland-protocols",
"wayland-scanner", "wayland-scanner",
] ]
@@ -7583,6 +7588,22 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "webbrowser"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00f1243ef785213e3a32fa0396093424a3a6ea566f9948497e5a2309261a4c97"
dependencies = [
"core-foundation 0.10.0",
"jni",
"log",
"ndk-context",
"objc2",
"objc2-foundation",
"url",
"web-sys",
]
[[package]] [[package]]
name = "webpki-root-certs" name = "webpki-root-certs"
version = "0.26.11" version = "0.26.11"
@@ -8720,7 +8741,7 @@ dependencies = [
[[package]] [[package]]
name = "zlog" name = "zlog"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@@ -8731,7 +8752,7 @@ dependencies = [
[[package]] [[package]]
name = "ztracing" name = "ztracing"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
dependencies = [ dependencies = [
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
@@ -8742,7 +8763,7 @@ dependencies = [
[[package]] [[package]]
name = "ztracing_macro" name = "ztracing_macro"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/zed-industries/zed#975a76bbf09e2b3b0207c2d02947851591500c2f" source = "git+https://github.com/zed-industries/zed#6976208e21436e88a4a5a094b440d41c482c5c84"
[[package]] [[package]]
name = "zune-core" name = "zune-core"

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M3 12L21 12M21 12L12.5 3.5M21 12L12.5 20.5" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 321 B

View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M9.17218 14.8284L12.0006 12M14.829 9.17157L12.0006 12M12.0006 12L9.17218 9.17157M12.0006 12L14.829 14.8284" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 599 B

1
assets/icons/close.svg Normal file
View File

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M6.75827 17.2426L12.0009 12M17.2435 6.75736L12.0009 12M12.0009 12L6.75827 6.75736M12.0009 12L17.2435 17.2426" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 387 B

View File

@@ -112,6 +112,12 @@ impl Account {
self._tasks.push(task); self._tasks.push(task);
} }
/// Set the public key of the account
pub fn set_public_key(&mut self, public_key: PublicKey, cx: &mut Context<Self>) {
self.public_key = Some(public_key);
cx.notify();
}
/// Check if the account entity has a public key /// Check if the account entity has a public key
pub fn has_account(&self) -> bool { pub fn has_account(&self) -> bool {
self.public_key.is_some() self.public_key.is_some()

View File

@@ -16,5 +16,8 @@ pub const BOOTSTRAP_RELAYS: [&str; 5] = [
/// Default relay for Nostr Connect /// Default relay for Nostr Connect
pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app"; pub const NOSTR_CONNECT_RELAY: &str = "wss://relay.nsec.app";
/// Default timeout for Nostr Connect (seconds)
pub const NOSTR_CONNECT_TIMEOUT: u64 = 30;
/// Default width of the sidebar. /// Default width of the sidebar.
pub const DEFAULT_SIDEBAR_WIDTH: f32 = 240.; pub const DEFAULT_SIDEBAR_WIDTH: f32 = 240.;

View File

@@ -34,3 +34,5 @@ futures.workspace = true
flume.workspace = true flume.workspace = true
tracing-subscriber = { version = "0.3.18", features = ["fmt"] } tracing-subscriber = { version = "0.3.18", features = ["fmt"] }
qrcode = "0.14.1"
webbrowser = "1.0.6"

View File

@@ -1,9 +1,24 @@
use std::sync::Mutex; use std::sync::Mutex;
use gpui::{actions, App}; use gpui::{actions, App};
use nostr_connect::prelude::*;
actions!(lume, [Quit, About, Open]); actions!(lume, [Quit, About, Open]);
#[derive(Debug, Clone)]
pub struct LumeAuthUrlHandler;
impl AuthUrlHandler for LumeAuthUrlHandler {
#[allow(mismatched_lifetime_syntaxes)]
fn on_auth_url(&self, auth_url: Url) -> BoxedFuture<Result<()>> {
Box::pin(async move {
log::info!("Received Auth URL: {auth_url}");
webbrowser::open(auth_url.as_str())?;
Ok(())
})
}
}
pub fn load_embedded_fonts(cx: &App) { pub fn load_embedded_fonts(cx: &App) {
let asset_source = cx.asset_source(); let asset_source = cx.asset_source();
let font_paths = asset_source.list("fonts").unwrap(); let font_paths = asset_source.list("fonts").unwrap();

View File

@@ -0,0 +1,384 @@
use std::time::Duration;
use account::Account;
use anyhow::{anyhow, Error};
use common::NOSTR_CONNECT_TIMEOUT;
use gpui::prelude::FluentBuilder;
use gpui::{
div, relative, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Window,
};
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::input::{Input, InputEvent, InputState};
use gpui_component::notification::Notification;
use gpui_component::{v_flex, ActiveTheme, Disableable, StyledExt, WindowExt};
use nostr_connect::prelude::*;
use smallvec::{smallvec, SmallVec};
use state::client;
use crate::actions::LumeAuthUrlHandler;
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Login> {
cx.new(|cx| Login::new(window, cx))
}
pub struct Login {
focus_handle: FocusHandle,
/// Input for nsec for bunker uri
key_input: Entity<InputState>,
/// Input for decryption password when available
pass_input: Entity<InputState>,
/// Error message
error: Entity<Option<SharedString>>,
/// Timeout countdown
countdown: Entity<Option<u64>>,
/// Whether password is required
require_password: bool,
/// Whether logging in is in progress
logging_in: bool,
/// Event subscriptions
_subscriptions: SmallVec<[Subscription; 1]>,
}
impl Login {
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let key_input = cx.new(|cx| InputState::new(window, cx));
let pass_input = cx.new(|cx| InputState::new(window, cx).masked(true));
let error = cx.new(|_| None);
let countdown = cx.new(|_| None);
let mut subscriptions = smallvec![];
subscriptions.push(
// Subscribe to key input events and process login when the user presses enter
cx.subscribe_in(&key_input, window, |this, input, event, window, cx| {
match event {
InputEvent::PressEnter { .. } => {
this.login(window, cx);
}
InputEvent::Change => {
if input.read(cx).value().starts_with("ncryptsec1") {
this.require_password = true;
cx.notify();
}
}
_ => {}
};
}),
);
Self {
focus_handle: cx.focus_handle(),
key_input,
pass_input,
error,
countdown,
logging_in: false,
require_password: false,
_subscriptions: subscriptions,
}
}
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.logging_in {
return;
};
// Prevent duplicate login requests
self.set_logging_in(true, cx);
let value = self.key_input.read(cx).value();
let password = self.pass_input.read(cx).value();
if value.starts_with("bunker://") {
self.login_with_bunker(&value, window, cx);
} else if value.starts_with("ncryptsec1") {
self.login_with_password(&value, &password, cx);
} else if value.starts_with("nsec1") {
if let Ok(secret) = SecretKey::parse(&value) {
let keys = Keys::new(secret);
self.login_with_keys(keys, cx);
} else {
self.set_error("Invalid", cx);
}
} else {
self.set_error("Invalid", cx);
}
}
fn login_with_bunker(&mut self, content: &str, window: &mut Window, cx: &mut Context<Self>) {
let Ok(uri) = NostrConnectUri::parse(content) else {
self.set_error("Bunker URI is not valid", cx);
return;
};
let app_keys = Keys::generate();
let timeout = Duration::from_secs(NOSTR_CONNECT_TIMEOUT);
let mut signer = NostrConnect::new(uri, app_keys.clone(), timeout, None).unwrap();
// Handle auth url with the default browser
signer.auth_url_handler(LumeAuthUrlHandler);
// Start countdown
cx.spawn_in(window, async move |this, cx| {
for i in (0..=NOSTR_CONNECT_TIMEOUT).rev() {
if i == 0 {
this.update(cx, |this, cx| {
this.set_countdown(None, cx);
})
.ok();
} else {
this.update(cx, |this, cx| {
this.set_countdown(Some(i), cx);
})
.ok();
}
cx.background_executor().timer(Duration::from_secs(1)).await;
}
})
.detach();
// Handle connection
cx.spawn_in(window, async move |this, cx| {
let result: Result<PublicKey, Error> = cx
.background_executor()
.await_on_background(async move {
let client = client();
let public_key = signer.get_public_key().await?;
// Update the signer
client.set_signer(signer).await;
// Return the URI for storing the connection
Ok(public_key)
})
.await;
this.update_in(cx, |_this, window, cx| {
match result {
Ok(public_key) => {
let account = Account::global(cx);
account.update(cx, |this, cx| {
this.set_public_key(public_key, cx);
})
}
Err(e) => {
window.push_notification(Notification::error(e.to_string()), cx);
}
};
})
.ok();
})
.detach();
}
fn login_with_password(&mut self, content: &str, pwd: &str, cx: &mut Context<Self>) {
if pwd.is_empty() {
self.set_error("Password is required", cx);
return;
}
let Ok(enc) = EncryptedSecretKey::from_bech32(content) else {
self.set_error("Secret Key is invalid", cx);
return;
};
let password = pwd.to_owned();
// Decrypt in the background to ensure it doesn't block the UI
let task = cx.background_spawn(async move {
if let Ok(content) = enc.decrypt(&password) {
Ok(Keys::new(content))
} else {
Err(anyhow!("Invalid password"))
}
});
cx.spawn(async move |this, cx| {
let result = task.await;
this.update(cx, |this, cx| {
match result {
Ok(keys) => {
this.login_with_keys(keys, cx);
}
Err(e) => {
this.set_error(e.to_string(), cx);
}
};
})
.ok();
})
.detach();
}
fn login_with_keys(&mut self, keys: Keys, cx: &mut Context<Self>) {
let public_key = keys.public_key();
cx.spawn(async move |this, cx| {
cx.background_executor()
.await_on_background(async move {
let client = client();
client.set_signer(keys).await;
})
.await;
this.update(cx, |_this, cx| {
let account = Account::global(cx);
account.update(cx, |this, cx| {
this.set_public_key(public_key, cx);
});
})
.ok();
})
.detach();
}
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
where
S: Into<SharedString>,
{
// Reset the log in state
self.set_logging_in(false, cx);
// Reset the countdown
self.set_countdown(None, cx);
// Update error message
self.error.update(cx, |this, cx| {
*this = Some(message.into());
cx.notify();
});
// Clear the error message after 3 secs
cx.spawn(async move |this, cx| {
cx.background_executor().timer(Duration::from_secs(3)).await;
this.update(cx, |this, cx| {
this.error.update(cx, |this, cx| {
*this = None;
cx.notify();
});
})
.ok();
})
.detach();
}
fn set_logging_in(&mut self, status: bool, cx: &mut Context<Self>) {
self.logging_in = status;
cx.notify();
}
fn set_countdown(&mut self, i: Option<u64>, cx: &mut Context<Self>) {
self.countdown.update(cx, |this, cx| {
*this = i;
cx.notify();
});
}
}
impl Panel for Login {
fn panel_name(&self) -> &'static str {
"Login"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
SharedString::from("Login")
}
}
impl EventEmitter<PanelEvent> for Login {}
impl Focusable for Login {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for Login {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
v_flex()
.relative()
.size_full()
.items_center()
.justify_center()
.child(
v_flex()
.w_96()
.gap_10()
.child(
div()
.text_center()
.text_lg()
.font_semibold()
.line_height(relative(1.3))
.child(SharedString::from("Continue with Private Key or Bunker")),
)
.child(
v_flex()
.gap_3()
.text_sm()
.child(
v_flex()
.gap_1()
.text_sm()
.text_color(cx.theme().muted_foreground)
.child("nsec or bunker://")
.child(Input::new(&self.key_input)),
)
.when(self.require_password, |this| {
this.child(
v_flex()
.gap_1()
.text_sm()
.text_color(cx.theme().muted_foreground)
.child("Password:")
.child(Input::new(&self.pass_input)),
)
})
.child(
Button::new("login")
.label("Continue")
.primary()
.loading(self.logging_in)
.disabled(self.logging_in)
.on_click(cx.listener(move |this, _, window, cx| {
this.login(window, cx);
})),
)
.when_some(self.countdown.read(cx).as_ref(), |this, i| {
let msg = format!(
"Approve connection request from your signer in {} seconds",
i
);
this.child(
div()
.text_xs()
.text_center()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(msg)),
)
})
.when_some(self.error.read(cx).as_ref(), |this, error| {
this.child(
div()
.text_xs()
.text_center()
.text_color(cx.theme().danger_foreground)
.child(error.clone()),
)
}),
),
)
}
}

View File

@@ -1,3 +1,5 @@
pub mod feed; pub mod feed;
pub mod login;
pub mod new_account;
pub mod onboarding; pub mod onboarding;
pub mod startup; pub mod startup;

View File

@@ -0,0 +1,45 @@
use gpui::{
div, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
ParentElement, Render, SharedString, Window,
};
use gpui_component::dock::{Panel, PanelEvent};
pub fn init(window: &mut Window, cx: &mut App) -> Entity<NewAccount> {
cx.new(|cx| NewAccount::new(window, cx))
}
pub struct NewAccount {
focus_handle: FocusHandle,
}
impl NewAccount {
fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
Self {
focus_handle: cx.focus_handle(),
}
}
}
impl Panel for NewAccount {
fn panel_name(&self) -> &'static str {
"New Account"
}
fn title(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
SharedString::from("New Account")
}
}
impl EventEmitter<PanelEvent> for NewAccount {}
impl Focusable for NewAccount {
fn focus_handle(&self, _cx: &App) -> FocusHandle {
self.focus_handle.clone()
}
}
impl Render for NewAccount {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div().child("New Account")
}
}

View File

@@ -1,23 +1,180 @@
use std::sync::Arc;
use std::time::Duration;
use account::Account;
use anyhow::Error;
use common::{CLIENT_NAME, NOSTR_CONNECT_RELAY, NOSTR_CONNECT_TIMEOUT};
use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
div, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement, div, img, px, relative, App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable,
ParentElement, Render, SharedString, Window, Image, InteractiveElement, IntoElement, ParentElement, Render, SharedString,
StatefulInteractiveElement, Styled, Task, Window,
}; };
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::divider::Divider;
use gpui_component::dock::{Panel, PanelEvent}; use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::notification::Notification;
use gpui_component::{h_flex, v_flex, ActiveTheme, Icon, IconName, Sizable, StyledExt, WindowExt};
use nostr_connect::prelude::*;
use qrcode::render::svg;
use qrcode::QrCode;
use smallvec::{smallvec, SmallVec};
use state::client;
use crate::workspace::OpenPanel;
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Onboarding> { pub fn init(window: &mut Window, cx: &mut App) -> Entity<Onboarding> {
cx.new(|cx| Onboarding::new(window, cx)) cx.new(|cx| Onboarding::new(window, cx))
} }
#[derive(Debug, Clone)]
pub enum NostrConnectApp {
Nsec(String),
Amber(String),
Aegis(String),
}
impl NostrConnectApp {
pub fn all() -> Vec<Self> {
vec![
NostrConnectApp::Nsec("https://nsec.app".to_string()),
NostrConnectApp::Amber("https://github.com/greenart7c3/Amber".to_string()),
NostrConnectApp::Aegis("https://github.com/ZharlieW/Aegis".to_string()),
]
}
pub fn url(&self) -> &str {
match self {
Self::Nsec(url) | Self::Amber(url) | Self::Aegis(url) => url,
}
}
pub fn as_str(&self) -> String {
match self {
NostrConnectApp::Nsec(_) => "nsec.app (Desktop)".into(),
NostrConnectApp::Amber(_) => "Amber (Android)".into(),
NostrConnectApp::Aegis(_) => "Aegis (iOS)".into(),
}
}
}
/// Onboarding
pub struct Onboarding { pub struct Onboarding {
focus_handle: FocusHandle, focus_handle: FocusHandle,
#[allow(dead_code)]
/// App keys for communicating with the remote signer
app_keys: Keys,
/// QR code for logging in with Nostr Connect
qr_code: Option<Arc<Image>>,
/// Background tasks
_tasks: SmallVec<[Task<()>; 1]>,
} }
impl Onboarding { impl Onboarding {
fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self { fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let app_keys = Keys::generate();
let timeout = Duration::from_secs(NOSTR_CONNECT_TIMEOUT);
let relay = RelayUrl::parse(NOSTR_CONNECT_RELAY).unwrap();
let uri = NostrConnectUri::client(app_keys.public_key(), vec![relay], CLIENT_NAME);
let qr_code = Self::generate_qr(uri.to_string().as_ref());
// NIP46: https://github.com/nostr-protocol/nips/blob/master/46.md
//
// Direct connection initiated by the client
let signer = NostrConnect::new(uri, app_keys.clone(), timeout, None).unwrap();
let mut tasks = smallvec![];
tasks.push(
// Wait for nostr connect
cx.spawn_in(window, async move |this, cx| {
let result: Result<PublicKey, Error> = cx
.background_executor()
.await_on_background(async move {
let client = client();
let public_key = signer.get_public_key().await?;
// Update the signer
client.set_signer(signer).await;
// Return the URI for storing the connection
Ok(public_key)
})
.await;
this.update_in(cx, |_this, window, cx| {
match result {
Ok(public_key) => {
let account = Account::global(cx);
account.update(cx, |this, cx| {
this.set_public_key(public_key, cx);
})
}
Err(e) => {
window.push_notification(Notification::error(e.to_string()), cx);
}
};
})
.ok();
}),
);
Self { Self {
focus_handle: cx.focus_handle(), focus_handle: cx.focus_handle(),
qr_code,
app_keys,
_tasks: tasks,
} }
} }
fn generate_qr(value: &str) -> Option<Arc<Image>> {
let code = QrCode::new(value).unwrap();
let svg = code
.render()
.min_dimensions(256, 256)
.dark_color(svg::Color("#000000"))
.light_color(svg::Color("#FFFFFF"))
.build();
Some(Arc::new(Image::from_bytes(
gpui::ImageFormat::Svg,
svg.into_bytes(),
)))
}
fn render_app<T>(&self, ix: usize, label: T, url: &str, cx: &Context<Self>) -> impl IntoElement
where
T: Into<SharedString>,
{
div()
.id(ix)
.flex_1()
.rounded_md()
.py_0p5()
.px_2()
.bg(cx.theme().list)
.child(label.into())
.on_click({
let url = url.to_owned();
move |_e, _window, cx| {
cx.open_url(&url);
}
})
}
fn render_apps(&self, cx: &Context<Self>) -> impl IntoIterator<Item = impl IntoElement> {
let all_apps = NostrConnectApp::all();
let mut items = Vec::with_capacity(all_apps.len());
for (ix, item) in all_apps.into_iter().enumerate() {
items.push(self.render_app(ix, item.as_str(), item.url(), cx));
}
items
}
} }
impl Panel for Onboarding { impl Panel for Onboarding {
@@ -32,14 +189,118 @@ impl Panel for Onboarding {
impl EventEmitter<PanelEvent> for Onboarding {} impl EventEmitter<PanelEvent> for Onboarding {}
impl EventEmitter<OpenPanel> for Onboarding {}
impl Focusable for Onboarding { impl Focusable for Onboarding {
fn focus_handle(&self, _cx: &App) -> FocusHandle { fn focus_handle(&self, _: &App) -> gpui::FocusHandle {
self.focus_handle.clone() self.focus_handle.clone()
} }
} }
impl Render for Onboarding { impl Render for Onboarding {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
div().child("Onboarding") h_flex()
.size_full()
.child(
v_flex()
.flex_1()
.h_full()
.gap_10()
.items_center()
.justify_center()
.child(
v_flex()
.items_center()
.text_center()
.child(
div()
.text_xl()
.font_semibold()
.line_height(relative(1.3))
.child(SharedString::from("Welcome to Lume")),
)
.child(
div()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from("An unambitious Nostr client")),
),
)
.child(
v_flex()
.w_80()
.gap_3()
.child(
Button::new("continue")
.icon(Icon::new(IconName::ArrowRight))
.label("Start Browsing")
.primary()
.on_click(cx.listener(move |_this, _ev, _window, cx| {
cx.emit(OpenPanel::Signup);
})),
)
.child(
Divider::horizontal()
.label("Already have an account? Continue with")
.text_xs(),
)
.child(
Button::new("key")
.label("Secret Key or Bunker")
.large()
.link()
.small()
.on_click(cx.listener(move |_this, _ev, _window, cx| {
cx.emit(OpenPanel::Login);
})),
),
),
)
.child(
v_flex()
.flex_1()
.size_full()
.items_center()
.justify_center()
.gap_5()
.bg(cx.theme().muted)
.when_some(self.qr_code.as_ref(), |this, qr| {
this.child(
img(qr.clone())
.size(px(256.))
.rounded_xl()
.shadow_lg()
.border_1()
.border_color(cx.theme().primary_active),
)
})
.child(
v_flex()
.justify_center()
.items_center()
.text_center()
.child(
div()
.font_semibold()
.line_height(relative(1.3))
.child(SharedString::from("Continue with Nostr Connect")),
)
.child(
div()
.text_sm()
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(
"Use Nostr Connect apps to scan the code",
)),
)
.child(
h_flex()
.mt_2()
.gap_1()
.text_xs()
.justify_center()
.children(self.render_apps(cx)),
),
),
)
} }
} }

View File

@@ -10,7 +10,7 @@ use gpui_component::{h_flex, v_flex, ActiveTheme, StyledExt};
use nostr_sdk::prelude::*; use nostr_sdk::prelude::*;
use person::PersonRegistry; use person::PersonRegistry;
use crate::workspace::WorkspaceEvent; use crate::workspace::OpenPanel;
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Sidebar> { pub fn init(window: &mut Window, cx: &mut App) -> Entity<Sidebar> {
cx.new(|cx| Sidebar::new(window, cx)) cx.new(|cx| Sidebar::new(window, cx))
@@ -35,7 +35,7 @@ impl Panel for Sidebar {
} }
impl EventEmitter<PanelEvent> for Sidebar {} impl EventEmitter<PanelEvent> for Sidebar {}
impl EventEmitter<WorkspaceEvent> for Sidebar {} impl EventEmitter<OpenPanel> for Sidebar {}
impl Focusable for Sidebar { impl Focusable for Sidebar {
fn focus_handle(&self, _cx: &App) -> FocusHandle { fn focus_handle(&self, _cx: &App) -> FocusHandle {
@@ -80,7 +80,7 @@ impl Render for Sidebar {
.child(div().text_sm().child(SharedString::from(relay))) .child(div().text_sm().child(SharedString::from(relay)))
.on_click(cx.listener(move |_this, _ev, _window, cx| { .on_click(cx.listener(move |_this, _ev, _window, cx| {
if let Ok(url) = RelayUrl::parse(relay) { if let Ok(url) = RelayUrl::parse(relay) {
cx.emit(WorkspaceEvent::OpenRelay(url)); cx.emit(OpenPanel::Relay(url));
} }
})), })),
) )
@@ -117,9 +117,7 @@ impl Render for Sidebar {
.hover(|this| this.bg(cx.theme().list_hover)) .hover(|this| this.bg(cx.theme().list_hover))
.child(div().text_sm().child(name.clone())) .child(div().text_sm().child(name.clone()))
.on_click(cx.listener(move |_this, _ev, _window, cx| { .on_click(cx.listener(move |_this, _ev, _window, cx| {
cx.emit(WorkspaceEvent::OpenPublicKey( cx.emit(OpenPanel::PublicKey(profile.public_key()));
profile.public_key(),
));
})), })),
) )
} }

View File

@@ -12,14 +12,16 @@ use nostr_sdk::prelude::*;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use crate::panels::feed::Feed; use crate::panels::feed::Feed;
use crate::panels::{onboarding, startup}; use crate::panels::{login, new_account, onboarding, startup};
use crate::sidebar; use crate::sidebar;
use crate::title_bar::AppTitleBar; use crate::title_bar::AppTitleBar;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum WorkspaceEvent { pub enum OpenPanel {
OpenPublicKey(PublicKey), PublicKey(PublicKey),
OpenRelay(RelayUrl), Relay(RelayUrl),
Signup,
Login,
} }
#[derive(Debug)] #[derive(Debug)]
@@ -36,18 +38,19 @@ pub struct Workspace {
impl Workspace { impl Workspace {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self { pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let account = Account::global(cx);
let onboarding = Arc::new(onboarding::init(window, cx));
// App's title bar // App's title bar
let title_bar = cx.new(|cx| AppTitleBar::new(CLIENT_NAME, window, cx)); let title_bar = cx.new(|cx| AppTitleBar::new(CLIENT_NAME, window, cx));
// Dock area for the workspace. // Dock area for the workspace.
let dock = cx.new(|cx| { let dock = cx.new(|cx| {
let startup = Arc::new(onboarding::init(window, cx));
let mut this = DockArea::new("dock", None, window, cx).panel_style(PanelStyle::TabBar); let mut this = DockArea::new("dock", None, window, cx).panel_style(PanelStyle::TabBar);
this.set_center(DockItem::panel(startup), window, cx); this.set_center(DockItem::panel(onboarding.clone()), window, cx);
this this
}); });
let account = Account::global(cx);
let mut subscriptions = smallvec![]; let mut subscriptions = smallvec![];
// Observe account entity changes // Observe account entity changes
@@ -59,6 +62,31 @@ impl Workspace {
}), }),
); );
// Observe onboarding panel events
subscriptions.push(cx.subscribe_in(
&onboarding,
window,
|this, _sidebar, event: &OpenPanel, window, cx| {
match event {
OpenPanel::Login => {
let view = login::init(window, cx);
this.dock.update(cx, |this, cx| {
this.set_center(DockItem::panel(Arc::new(view)), window, cx);
});
}
OpenPanel::Signup => {
let view = new_account::init(window, cx);
this.dock.update(cx, |this, cx| {
this.set_center(DockItem::panel(Arc::new(view)), window, cx);
});
}
_ => {}
};
},
));
// Automatically sync theme with system appearance // Automatically sync theme with system appearance
subscriptions.push(window.observe_window_appearance(|window, cx| { subscriptions.push(window.observe_window_appearance(|window, cx| {
Theme::sync_system_appearance(Some(window), cx); Theme::sync_system_appearance(Some(window), cx);
@@ -80,20 +108,23 @@ impl Workspace {
self._subscriptions.push(cx.subscribe_in( self._subscriptions.push(cx.subscribe_in(
&sidebar, &sidebar,
window, window,
|this, _sidebar, event: &WorkspaceEvent, window, cx| { |this, _sidebar, event: &OpenPanel, window, cx| {
match event { match event {
WorkspaceEvent::OpenPublicKey(public_key) => { OpenPanel::PublicKey(public_key) => {
let view = cx.new(|cx| Feed::new(Some(*public_key), None, window, cx)); let view = cx.new(|cx| Feed::new(Some(*public_key), None, window, cx));
this.dock.update(cx, |this, cx| { this.dock.update(cx, |this, cx| {
this.add_panel(Arc::new(view), DockPlacement::Center, None, window, cx); this.add_panel(Arc::new(view), DockPlacement::Center, None, window, cx);
}); });
} }
WorkspaceEvent::OpenRelay(relay) => { OpenPanel::Relay(relay) => {
let view = cx.new(|cx| Feed::new(None, Some(relay.to_owned()), window, cx)); let view = cx.new(|cx| Feed::new(None, Some(relay.to_owned()), window, cx));
this.dock.update(cx, |this, cx| { this.dock.update(cx, |this, cx| {
this.add_panel(Arc::new(view), DockPlacement::Center, None, window, cx); this.add_panel(Arc::new(view), DockPlacement::Center, None, window, cx);
}); });
} }
_ => {}
}; };
}, },
)); ));