wip: refactor

This commit is contained in:
2025-01-02 09:58:42 +07:00
parent d53e75b775
commit 51b392a845
11 changed files with 94 additions and 188 deletions

View File

@@ -4,8 +4,9 @@ use serde::Deserialize;
use std::sync::Arc;
use ui::{
dock::{DockArea, DockItem, DockPlacement},
indicator::Indicator,
theme::Theme,
Root, TitleBar,
Root, Sizable, TitleBar,
};
use super::{
@@ -143,10 +144,20 @@ impl Render for AppView {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let modal_layer = Root::render_modal_layer(cx);
let notification_layer = Root::render_notification_layer(cx);
let state = cx.global::<AccountRegistry>();
let mut content = div().size_full().flex().flex_col();
if cx.global::<AccountRegistry>().is_user_logged_in() {
if state.is_loading {
content = content.child(div()).child(
div()
.flex_1()
.flex()
.items_center()
.justify_center()
.child(Indicator::new().small()),
)
} else if state.is_user_logged_in() {
content = content
.child(
TitleBar::new()

View File

@@ -1,6 +1,4 @@
use async_utility::task::spawn;
use gpui::*;
use keyring::Entry;
use nostr_sdk::prelude::*;
use ui::{
input::{InputEvent, TextInput},
@@ -34,26 +32,30 @@ impl Onboarding {
fn save_keys(content: &str, cx: &mut ViewContext<Self>) -> anyhow::Result<(), anyhow::Error> {
let keys = Keys::parse(content)?;
let public_key = keys.public_key();
let bech32 = public_key.to_bech32().unwrap();
let bech32 = public_key.to_bech32()?;
let secret = keys.secret_key().to_secret_hex();
let entry = Entry::new(KEYRING_SERVICE, &bech32).unwrap();
let mut async_cx = cx.to_async();
let view_id = cx.entity_id();
// Save secret key to keyring
entry.set_password(&secret)?;
cx.foreground_executor()
.spawn({
let client = get_client();
let task = cx.write_credentials(KEYRING_SERVICE, &bech32, secret.as_bytes());
// Update signer
spawn(async move {
get_client().set_signer(keys).await;
});
// Update globals state
cx.update_global::<AccountRegistry, _>(|state, cx| {
state.set_user(Some(public_key));
cx.notify();
});
async move {
if task.await.is_ok() {
_ = client.set_signer(keys).await;
// Update global state
_ = async_cx.update_global::<AccountRegistry, _>(|state, cx| {
state.set_user(Some(public_key));
cx.notify(Some(view_id));
});
}
}
})
.detach();
Ok(())
}