feat: improve ui
This commit is contained in:
@@ -155,55 +155,6 @@ pub async fn login(
|
||||
let hex = public_key.to_hex();
|
||||
let keyring = Entry::new(&id, "nostr_secret").expect("Unexpected.");
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let window = app.get_webview_window("main").expect("Window is terminated.");
|
||||
let state = window.state::<Nostr>();
|
||||
let client = &state.client;
|
||||
|
||||
client
|
||||
.handle_notifications(|notification| async {
|
||||
if let RelayPoolNotification::Message { message, relay_url } = notification {
|
||||
if let RelayMessage::Event { event, .. } = message {
|
||||
if event.kind == Kind::GiftWrap {
|
||||
if let Ok(UnwrappedGift { rumor, sender }) =
|
||||
client.unwrap_gift_wrap(&event).await
|
||||
{
|
||||
window
|
||||
.emit(
|
||||
"event",
|
||||
Payload { event: rumor.as_json(), sender: sender.to_hex() },
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
} else if let RelayMessage::Auth { challenge } = message {
|
||||
match client.auth(challenge, relay_url.clone()).await {
|
||||
Ok(..) => {
|
||||
println!("Authenticated to {} relay.", relay_url);
|
||||
|
||||
if let Ok(relay) = client.relay(relay_url).await {
|
||||
let opts = RelaySendOptions::new().skip_send_confirmation(true);
|
||||
if let Err(e) = relay.resubscribe(opts).await {
|
||||
println!(
|
||||
"Impossible to resubscribe to '{}': {e}",
|
||||
relay.url()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Can't authenticate to '{relay_url}' relay: {e}");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("relay message: {}", message.as_json());
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
})
|
||||
.await
|
||||
});
|
||||
|
||||
let password = match keyring.get_password() {
|
||||
Ok(pw) => pw,
|
||||
Err(_) => return Err("Cancelled".into()),
|
||||
@@ -256,12 +207,41 @@ pub async fn login(
|
||||
|
||||
if client.reconcile_with(relays.clone(), old, NegentropyOptions::default()).await.is_ok() {
|
||||
handle.emit("synchronized", ()).unwrap();
|
||||
println!("synchronized");
|
||||
};
|
||||
|
||||
if client.subscribe_to(relays, vec![new], None).await.is_ok() {
|
||||
println!("Waiting for new message...")
|
||||
};
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let window = app.get_webview_window("main").expect("Window is terminated.");
|
||||
let state = window.state::<Nostr>();
|
||||
let client = &state.client;
|
||||
|
||||
// Workaround for https://github.com/rust-nostr/nostr/issues/509
|
||||
// TODO: remove
|
||||
let _ = client.get_events_of(vec![Filter::new().kind(Kind::TextNote).limit(0)], None).await;
|
||||
|
||||
client
|
||||
.handle_notifications(|notification| async {
|
||||
if let RelayPoolNotification::Event { event, .. } = notification {
|
||||
if event.kind == Kind::GiftWrap {
|
||||
if let Ok(UnwrappedGift { rumor, sender }) =
|
||||
client.unwrap_gift_wrap(&event).await
|
||||
{
|
||||
window
|
||||
.emit(
|
||||
"event",
|
||||
Payload { event: rumor.as_json(), sender: sender.to_hex() },
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
})
|
||||
.await
|
||||
});
|
||||
|
||||
Ok(hex)
|
||||
}
|
||||
|
||||
@@ -32,9 +32,9 @@ pub async fn get_chats(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
|
||||
|
||||
let uniqs = rumors
|
||||
.into_iter()
|
||||
.sorted_by_key(|ev| Reverse(ev.created_at))
|
||||
.filter(|ev| ev.pubkey != public_key)
|
||||
.unique_by(|ev| ev.pubkey)
|
||||
.sorted_by_key(|ev| Reverse(ev.created_at))
|
||||
.map(|ev| ev.as_json())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@@ -76,9 +76,8 @@ fn main() {
|
||||
// Config
|
||||
let opts = Options::new()
|
||||
.autoconnect(true)
|
||||
.automatic_authentication(false)
|
||||
.timeout(Duration::from_secs(5))
|
||||
.send_timeout(Some(Duration::from_secs(50)))
|
||||
.send_timeout(Some(Duration::from_secs(5)))
|
||||
.connection_timeout(Some(Duration::from_secs(20)));
|
||||
|
||||
// Setup nostr client
|
||||
@@ -98,6 +97,7 @@ fn main() {
|
||||
Ok(())
|
||||
})
|
||||
.enable_macos_default_menu(false)
|
||||
.plugin(tauri_plugin_prevent_default::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_clipboard_manager::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
|
||||
Reference in New Issue
Block a user