chore: rework login and identity (#129)
* . * redesign onboarding screen * . * add signer proxy * . * . * . * . * fix proxy * clean up * fix new account
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use global::{constants::KEYRING_URL, first_run};
|
||||
use global::constants::KEYRING_URL;
|
||||
use global::first_run;
|
||||
use gpui::{App, AppContext, Context, Entity, Global, Subscription, Window};
|
||||
use nostr_sdk::prelude::*;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
@@ -24,7 +25,7 @@ impl ClientKeys {
|
||||
}
|
||||
|
||||
/// Retrieve the Client Keys instance
|
||||
pub fn get_global(cx: &App) -> &Self {
|
||||
pub fn read_global(cx: &App) -> &Self {
|
||||
cx.global::<GlobalClientKeys>().0.read(cx)
|
||||
}
|
||||
|
||||
@@ -49,11 +50,20 @@ impl ClientKeys {
|
||||
}
|
||||
|
||||
pub fn load(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
// Prevent macOS from asking for password every time
|
||||
// Only for debug builds
|
||||
if cfg!(debug_assertions) && cfg!(target_os = "macos") {
|
||||
log::warn!("Running debug build on macOS");
|
||||
log::warn!("Skipping keychain access, generating new client keys");
|
||||
self.new_keys(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let read_client_keys = cx.read_credentials(KEYRING_URL);
|
||||
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
if let Ok(Some((_, secret))) = read_client_keys.await {
|
||||
// Update keys
|
||||
// Update the client keys with the stored secret key from the keychain
|
||||
this.update(cx, |this, cx| {
|
||||
let Ok(secret_key) = SecretKey::from_slice(&secret) else {
|
||||
this.set_keys(None, false, true, cx);
|
||||
@@ -64,7 +74,7 @@ impl ClientKeys {
|
||||
})
|
||||
.ok();
|
||||
} else if *first_run() {
|
||||
// Generate a new keys and update
|
||||
// If this is the first run, generate new keys and use them for the client keys
|
||||
this.update(cx, |this, cx| {
|
||||
this.new_keys(cx);
|
||||
})
|
||||
@@ -102,6 +112,7 @@ impl ClientKeys {
|
||||
}
|
||||
|
||||
self.keys = keys;
|
||||
|
||||
// Notify GPUI to reload UI
|
||||
if notify {
|
||||
cx.notify();
|
||||
@@ -118,8 +129,7 @@ impl ClientKeys {
|
||||
|
||||
pub fn keys(&self) -> Keys {
|
||||
self.keys
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.clone()
|
||||
.expect("Keys should always be initialized")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user