diff --git a/Cargo.toml b/Cargo.toml index 3939159..b154767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,8 @@ components = { package = "ui", git = "https://github.com/longbridgeapp/gpui-comp reqwest_client = { git = "https://github.com/huacnlee/zed.git", branch = "export-platform-window" } # Nostr -nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr", branch = "nip17" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", branch = "nip17", features = [ +nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr" } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [ "lmdb", "all-nips", ] } diff --git a/crates/client/src/state.rs b/crates/client/src/state.rs index d5fbd88..6331e81 100644 --- a/crates/client/src/state.rs +++ b/crates/client/src/state.rs @@ -23,7 +23,7 @@ pub async fn get_client() -> &'static Client { // Add some bootstrap relays let _ = client.add_relay("wss://relay.damus.io").await; let _ = client.add_relay("wss://relay.primal.net").await; - let _ = client.add_relay("wss://nostr.fmt.wiz.biz").await; + let _ = client.add_relay("wss://nos.lol").await; let _ = client.add_relay("wss://directory.yabu.me").await; let _ = client.add_discovery_relay("wss://user.kindpag.es/").await; diff --git a/crates/ui/src/constants.rs b/crates/ui/src/constants.rs new file mode 100644 index 0000000..828de55 --- /dev/null +++ b/crates/ui/src/constants.rs @@ -0,0 +1,2 @@ +pub const KEYRING_SERVICE: &str = "Coop Safe Storage"; +pub const APP_NAME: &str = "coop"; diff --git a/crates/ui/src/main.rs b/crates/ui/src/main.rs index ad47ab2..4cac3d0 100644 --- a/crates/ui/src/main.rs +++ b/crates/ui/src/main.rs @@ -1,12 +1,17 @@ use asset::Assets; use client::NostrClient; use components::theme::{Theme, ThemeColor, ThemeMode}; +use constants::{APP_NAME, KEYRING_SERVICE}; use gpui::*; +use keyring::Entry; +use nostr_sdk::prelude::*; use state::AppState; use std::sync::Arc; +use utils::get_all_accounts_from_keyring; use views::app::AppView; pub mod asset; +pub mod constants; pub mod state; pub mod utils; pub mod views; @@ -45,6 +50,33 @@ async fn main() { // Refresh cx.refresh(); + // Login + let async_cx = cx.to_async(); + cx.foreground_executor() + .spawn(async move { + let accounts = get_all_accounts_from_keyring(); + + if let Some(account) = accounts.first() { + let client = async_cx + .read_global(|nostr: &NostrClient, _cx| nostr.client) + .unwrap(); + let entry = + Entry::new(KEYRING_SERVICE, account.to_bech32().unwrap().as_ref()) + .unwrap(); + let password = entry.get_password().unwrap(); + let keys = Keys::parse(password).unwrap(); + + client.set_signer(keys).await; + + async_cx + .update_global(|app_state: &mut AppState, _cx| { + app_state.signer = Some(*account); + }) + .unwrap(); + } + }) + .detach(); + // Set window size let bounds = Bounds::centered(None, size(px(860.0), px(650.0)), cx); @@ -53,7 +85,7 @@ async fn main() { window_bounds: Some(WindowBounds::Windowed(bounds)), window_decorations: Some(WindowDecorations::Client), titlebar: Some(TitlebarOptions { - title: Some(SharedString::new_static("coop")), + title: Some(SharedString::new_static(APP_NAME)), appears_transparent: true, ..Default::default() }), diff --git a/crates/ui/src/state.rs b/crates/ui/src/state.rs index db72c9e..1c0e09e 100644 --- a/crates/ui/src/state.rs +++ b/crates/ui/src/state.rs @@ -3,6 +3,7 @@ use nostr_sdk::prelude::*; pub struct AppState { pub signer: Option, + // TODO: add more app state } impl Global for AppState {} diff --git a/crates/ui/src/views/onboarding.rs b/crates/ui/src/views/onboarding.rs index d019e6e..bb139ef 100644 --- a/crates/ui/src/views/onboarding.rs +++ b/crates/ui/src/views/onboarding.rs @@ -7,7 +7,7 @@ use gpui::*; use keyring::Entry; use nostr_sdk::prelude::*; -use crate::state::AppState; +use crate::{constants::KEYRING_SERVICE, state::AppState}; pub struct Onboarding { input: View, @@ -36,7 +36,7 @@ impl Onboarding { let secret = keys.secret_key().to_secret_hex(); let entry = - Entry::new("Coop Safe Storage", &public_key.to_bech32().unwrap()) + Entry::new(KEYRING_SERVICE, &public_key.to_bech32().unwrap()) .unwrap(); // Store private key to OS Keyring