feat: improve startup screen
This commit is contained in:
17
Cargo.lock
generated
17
Cargo.lock
generated
@@ -1118,6 +1118,7 @@ dependencies = [
|
|||||||
"gpui_tokio",
|
"gpui_tokio",
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"log",
|
"log",
|
||||||
|
"nostr-connect",
|
||||||
"nostr-sdk",
|
"nostr-sdk",
|
||||||
"reqwest_client",
|
"reqwest_client",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
@@ -2850,7 +2851,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"windows-targets 0.52.6",
|
"windows-targets 0.48.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3215,6 +3216,18 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nostr-connect"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "git+https://github.com/rust-nostr/nostr#dda112c89422cda6740fdae404e09a227a0f79ce"
|
||||||
|
dependencies = [
|
||||||
|
"async-utility",
|
||||||
|
"nostr",
|
||||||
|
"nostr-relay-pool",
|
||||||
|
"tokio",
|
||||||
|
"tracing",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nostr-database"
|
name = "nostr-database"
|
||||||
version = "0.39.0"
|
version = "0.39.0"
|
||||||
@@ -6274,7 +6287,7 @@ version = "0.1.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ reqwest_client = { git = "https://github.com/zed-industries/zed" }
|
|||||||
|
|
||||||
# Nostr
|
# Nostr
|
||||||
nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr" }
|
nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
|
nostr-connect = { git = "https://github.com/rust-nostr/nostr" }
|
||||||
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [
|
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [
|
||||||
"lmdb",
|
"lmdb",
|
||||||
"all-nips",
|
"all-nips",
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ gpui_tokio.workspace = true
|
|||||||
reqwest_client.workspace = true
|
reqwest_client.workspace = true
|
||||||
|
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
|
nostr-connect.workspace = true
|
||||||
nostr-sdk.workspace = true
|
nostr-sdk.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ use nostr_sdk::prelude::*;
|
|||||||
use state::{get_client, initialize_client};
|
use state::{get_client, initialize_client};
|
||||||
use std::{borrow::Cow, collections::HashSet, ops::Deref, str::FromStr, sync::Arc, time::Duration};
|
use std::{borrow::Cow, collections::HashSet, ops::Deref, str::FromStr, sync::Arc, time::Duration};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use ui::Root;
|
use ui::{theme::Theme, Root};
|
||||||
use views::{app::AppView, onboarding::Onboarding, startup::Startup};
|
use views::{app::AppView, onboarding, startup::Startup};
|
||||||
|
|
||||||
mod asset;
|
mod asset;
|
||||||
mod views;
|
mod views;
|
||||||
@@ -254,6 +254,11 @@ fn main() {
|
|||||||
.open_window(opts, |window, cx| {
|
.open_window(opts, |window, cx| {
|
||||||
window.set_window_title(APP_NAME);
|
window.set_window_title(APP_NAME);
|
||||||
window.set_app_id(APP_ID);
|
window.set_app_id(APP_ID);
|
||||||
|
window
|
||||||
|
.observe_window_appearance(|window, cx| {
|
||||||
|
Theme::sync_system_appearance(Some(window), cx);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
let root = cx.new(|cx| {
|
let root = cx.new(|cx| {
|
||||||
Root::new(cx.new(|cx| Startup::new(window, cx)).into(), window, cx)
|
Root::new(cx.new(|cx| Startup::new(window, cx)).into(), window, cx)
|
||||||
@@ -321,10 +326,7 @@ fn main() {
|
|||||||
cx.update_global::<AppRegistry, _>(|this, cx| {
|
cx.update_global::<AppRegistry, _>(|this, cx| {
|
||||||
if let Some(root) = this.root() {
|
if let Some(root) = this.root() {
|
||||||
cx.update_entity(&root, |this: &mut Root, cx| {
|
cx.update_entity(&root, |this: &mut Root, cx| {
|
||||||
this.set_view(
|
this.set_view(onboarding::init(window, cx).into(), cx);
|
||||||
cx.new(|cx| Onboarding::new(window, cx)).into(),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
use super::{
|
|
||||||
chat, contacts, onboarding::Onboarding, profile, settings, sidebar::Sidebar,
|
|
||||||
welcome::WelcomePanel,
|
|
||||||
};
|
|
||||||
use app_state::registry::AppRegistry;
|
use app_state::registry::AppRegistry;
|
||||||
use chat_state::registry::ChatRegistry;
|
use chat_state::registry::ChatRegistry;
|
||||||
use common::profile::NostrProfile;
|
use common::profile::NostrProfile;
|
||||||
@@ -20,6 +16,10 @@ use ui::{
|
|||||||
Icon, IconName, Root, Sizable, TitleBar,
|
Icon, IconName, Root, Sizable, TitleBar,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
chat, contacts, onboarding, profile, settings, sidebar::Sidebar, welcome::WelcomePanel,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Clone, PartialEq, Eq, Deserialize)]
|
||||||
pub enum PanelKind {
|
pub enum PanelKind {
|
||||||
Room(u64),
|
Room(u64),
|
||||||
@@ -170,7 +170,7 @@ impl AppView {
|
|||||||
// Update root view
|
// Update root view
|
||||||
if let Some(root) = this.root() {
|
if let Some(root) = this.root() {
|
||||||
cx.update_entity(&root, |this: &mut Root, cx| {
|
cx.update_entity(&root, |this: &mut Root, cx| {
|
||||||
this.set_view(cx.new(|cx| Onboarding::new(window, cx)).into(), cx);
|
this.set_view(onboarding::init(window, cx).into(), cx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,121 +1,265 @@
|
|||||||
use app_state::registry::AppRegistry;
|
use app_state::registry::AppRegistry;
|
||||||
use common::{constants::KEYRING_SERVICE, profile::NostrProfile};
|
use common::profile::NostrProfile;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, AppContext, BorrowAppContext, Context, Entity, IntoElement, ParentElement, Render, Styled,
|
div, relative, svg, App, AppContext, BorrowAppContext, Context, Entity, IntoElement,
|
||||||
Window,
|
ParentElement, Render, Styled, Window,
|
||||||
};
|
};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_connect::prelude::*;
|
||||||
use state::get_client;
|
use state::get_client;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::sync::oneshot;
|
||||||
use ui::{
|
use ui::{
|
||||||
|
button::{Button, ButtonVariants},
|
||||||
input::{InputEvent, TextInput},
|
input::{InputEvent, TextInput},
|
||||||
Root,
|
notification::NotificationType,
|
||||||
|
prelude::FluentBuilder,
|
||||||
|
theme::{scale::ColorScaleStep, ActiveTheme},
|
||||||
|
ContextModal, Root, Size, StyledExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::app::AppView;
|
use super::app::AppView;
|
||||||
|
|
||||||
|
const ALPHA_MESSAGE: &str = "Coop is in the alpha stage; it does not store any credentials. You will need to log in again when you reopen the app.";
|
||||||
|
const JOIN_URL: &str = "https://start.njump.me/";
|
||||||
|
|
||||||
|
pub fn init(window: &mut Window, cx: &mut App) -> Entity<Onboarding> {
|
||||||
|
Onboarding::new(window, cx)
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Onboarding {
|
pub struct Onboarding {
|
||||||
input: Entity<TextInput>,
|
input: Entity<TextInput>,
|
||||||
|
use_connect: bool,
|
||||||
|
use_privkey: bool,
|
||||||
|
is_loading: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Onboarding {
|
impl Onboarding {
|
||||||
pub fn new(window: &mut Window, cx: &mut Context<'_, Self>) -> Self {
|
pub fn new(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
||||||
let input = cx.new(|cx| {
|
let input = cx.new(|cx| {
|
||||||
let mut input = TextInput::new(window, cx);
|
TextInput::new(window, cx)
|
||||||
input.set_size(ui::Size::Medium, window, cx);
|
.text_size(Size::XSmall)
|
||||||
input
|
.placeholder("nsec...")
|
||||||
});
|
});
|
||||||
|
|
||||||
cx.subscribe_in(
|
cx.new(|cx| {
|
||||||
&input,
|
cx.subscribe_in(
|
||||||
window,
|
&input,
|
||||||
move |_, text_input, input_event, window, cx| {
|
window,
|
||||||
if let InputEvent::PressEnter = input_event {
|
move |this: &mut Self, _, input_event, window, cx| {
|
||||||
let content = text_input.read(cx).text().to_string();
|
if let InputEvent::PressEnter = input_event {
|
||||||
_ = Self::save_keys(&content, window, cx);
|
this.login(window, cx);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
Self { input }
|
Self {
|
||||||
|
input,
|
||||||
|
use_connect: false,
|
||||||
|
use_privkey: false,
|
||||||
|
is_loading: false,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_keys(
|
fn use_connect(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
content: &str,
|
self.use_connect = true;
|
||||||
window: &mut Window,
|
cx.notify();
|
||||||
cx: &mut Context<Self>,
|
}
|
||||||
) -> anyhow::Result<(), anyhow::Error> {
|
|
||||||
let keys = Keys::parse(content)?;
|
fn use_privkey(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
let public_key = keys.public_key();
|
self.use_privkey = true;
|
||||||
let bech32 = public_key.to_bech32()?;
|
cx.notify();
|
||||||
let secret = keys.secret_key().to_secret_hex();
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self, _window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.use_privkey = false;
|
||||||
|
self.use_connect = false;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
|
self.is_loading = status;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn login(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
let value = self.input.read(cx).text().to_string();
|
||||||
|
|
||||||
|
if !value.starts_with("nsec") || value.is_empty() {
|
||||||
|
window.push_notification((NotificationType::Warning, "Private Key is required"), cx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show loading spinner
|
||||||
|
self.set_loading(true, cx);
|
||||||
|
|
||||||
let window_handle = window.window_handle();
|
let window_handle = window.window_handle();
|
||||||
let task = cx.write_credentials(KEYRING_SERVICE, &bech32, secret.as_bytes());
|
let keys = if let Ok(keys) = Keys::parse(&value) {
|
||||||
|
keys
|
||||||
|
} else {
|
||||||
|
// TODO: handle error
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
let client = get_client();
|
let client = get_client();
|
||||||
|
let (tx, rx) = oneshot::channel::<NostrProfile>();
|
||||||
|
|
||||||
if task.await.is_ok() {
|
cx.background_executor()
|
||||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<NostrProfile>(1);
|
.spawn(async move {
|
||||||
|
let public_key = keys.get_public_key().await.unwrap();
|
||||||
|
let metadata = client
|
||||||
|
.fetch_metadata(public_key, Duration::from_secs(3))
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.unwrap_or(Metadata::new());
|
||||||
|
let profile = NostrProfile::new(public_key, metadata);
|
||||||
|
|
||||||
cx.background_executor()
|
_ = tx.send(profile);
|
||||||
.spawn(async move {
|
_ = client.set_signer(keys).await;
|
||||||
// Update signer
|
})
|
||||||
_ = client.set_signer(keys).await;
|
.detach();
|
||||||
|
|
||||||
// Get metadata
|
if let Ok(profile) = rx.await {
|
||||||
let metadata = if let Ok(Some(metadata)) =
|
cx.update_window(window_handle, |_, window, cx| {
|
||||||
client.database().metadata(public_key).await
|
cx.update_global::<AppRegistry, _>(|this, cx| {
|
||||||
{
|
this.set_user(Some(profile.clone()));
|
||||||
metadata
|
|
||||||
} else {
|
|
||||||
Metadata::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = tx.send(NostrProfile::new(public_key, metadata)).await;
|
if let Some(root) = this.root() {
|
||||||
})
|
cx.update_entity(&root, |this: &mut Root, cx| {
|
||||||
.await;
|
this.set_view(
|
||||||
|
cx.new(|cx| AppView::new(profile, window, cx)).into(),
|
||||||
while let Some(profile) = rx.recv().await {
|
cx,
|
||||||
cx.update_window(window_handle, |_, window, cx| {
|
);
|
||||||
cx.update_global::<AppRegistry, _>(|this, cx| {
|
});
|
||||||
this.set_user(Some(profile.clone()));
|
}
|
||||||
|
});
|
||||||
if let Some(root) = this.root() {
|
})
|
||||||
cx.update_entity(&root, |this: &mut Root, cx| {
|
.unwrap();
|
||||||
this.set_view(
|
|
||||||
cx.new(|cx| AppView::new(profile, window, cx)).into(),
|
|
||||||
cx,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
div()
|
||||||
.size_full()
|
.size_full()
|
||||||
|
.relative()
|
||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.size_1_3()
|
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.gap_1()
|
.items_center()
|
||||||
.child(div().child("Private Key").text_sm())
|
.gap_6()
|
||||||
.child(self.input.clone()),
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.gap_4()
|
||||||
|
.child(
|
||||||
|
svg()
|
||||||
|
.path("brand/coop.svg")
|
||||||
|
.size_12()
|
||||||
|
.text_color(cx.theme().base.step(cx, ColorScaleStep::THREE)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_align(gpui::TextAlign::Center)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_lg()
|
||||||
|
.font_semibold()
|
||||||
|
.line_height(relative(1.2))
|
||||||
|
.child("Welcome to Coop!"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_sm()
|
||||||
|
.text_color(
|
||||||
|
cx.theme().base.step(cx, ColorScaleStep::ELEVEN),
|
||||||
|
)
|
||||||
|
.child("A Nostr client for secure communication."),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(div().w_72().map(|this| {
|
||||||
|
if self.use_privkey {
|
||||||
|
this.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap_1()
|
||||||
|
.text_xs()
|
||||||
|
.child("Private Key:")
|
||||||
|
.child(self.input.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("login")
|
||||||
|
.label("Login")
|
||||||
|
.primary()
|
||||||
|
.w_full()
|
||||||
|
.loading(self.is_loading)
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.login(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("cancel")
|
||||||
|
.label("Cancel")
|
||||||
|
.ghost()
|
||||||
|
.w_full()
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.reset(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
this.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
Button::new("login_btn")
|
||||||
|
.label("Login with Private Key")
|
||||||
|
.primary()
|
||||||
|
.w_full()
|
||||||
|
.on_click(cx.listener(move |this, _, window, cx| {
|
||||||
|
this.use_privkey(window, cx);
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("join_btn")
|
||||||
|
.label("Join Nostr")
|
||||||
|
.ghost()
|
||||||
|
.w_full()
|
||||||
|
.on_click(|_, _, cx| {
|
||||||
|
cx.open_url(JOIN_URL);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.bottom_2()
|
||||||
|
.w_full()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(cx.theme().base.step(cx, ColorScaleStep::ELEVEN))
|
||||||
|
.text_align(gpui::TextAlign::Center)
|
||||||
|
.child(ALPHA_MESSAGE),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
pub const KEYRING_SERVICE: &str = "Coop Safe Storage";
|
pub const KEYRING_SERVICE: &str = "Coop Safe Storage";
|
||||||
pub const APP_NAME: &str = "Coop";
|
pub const APP_NAME: &str = "Coop";
|
||||||
pub const APP_ID: &str = "su.reya.coop";
|
pub const APP_ID: &str = "su.reya.coop";
|
||||||
|
|
||||||
pub const FAKE_SIG: &str = "f9e79d141c004977192d05a86f81ec7c585179c371f7350a5412d33575a2a356433f58e405c2296ed273e2fe0aafa25b641e39cc4e1f3f261ebf55bce0cbac83";
|
pub const FAKE_SIG: &str = "f9e79d141c004977192d05a86f81ec7c585179c371f7350a5412d33575a2a356433f58e405c2296ed273e2fe0aafa25b641e39cc4e1f3f261ebf55bce0cbac83";
|
||||||
pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwrap";
|
|
||||||
|
/// Subscriptions
|
||||||
|
pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps";
|
||||||
pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps";
|
pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps";
|
||||||
pub const METADATA_DELAY: u64 = 200;
|
|
||||||
|
|
||||||
/// Image Resizer Service
|
/// Image Resizer Service
|
||||||
pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
|
pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
|
||||||
|
|||||||
Reference in New Issue
Block a user