chore: update gpui

This commit is contained in:
2025-03-25 20:53:22 +07:00
parent 4c9533bfe4
commit 42d6328d82
28 changed files with 255 additions and 211 deletions

View File

@@ -1,8 +1,8 @@
[package]
name = "coop"
version = "0.1.4"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[[bin]]
name = "coop"

View File

@@ -283,7 +283,7 @@ impl ChatSpace {
Ok(())
});
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
if reset.await.is_ok() {
cx.update(|_, cx| {
Account::global(cx).update(cx, |this, cx| {

View File

@@ -219,7 +219,7 @@ fn main() {
// Initialize account state
account::init(cx);
// Spawn a task to handle events from nostr channel
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
let chats = cx.update(|_, cx| ChatRegistry::global(cx)).unwrap();
while let Ok(signal) = event_rx.recv().await {

View File

@@ -188,9 +188,9 @@ impl Chat {
let room = model.read(cx);
let task = room.verify_inbox_relays(cx);
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(result) = task.await {
_ = cx.update(|cx| {
cx.update(|cx| {
_ = this.update(cx, |this, cx| {
result.into_iter().for_each(|item| {
if !item.1 {
@@ -205,7 +205,8 @@ impl Chat {
}
});
});
});
})
.ok();
}
})
.detach();
@@ -219,13 +220,15 @@ impl Chat {
let room = model.read(cx);
let task = room.load_messages(cx);
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(events) = task.await {
_ = cx.update(|cx| {
_ = this.update(cx, |this, cx| {
cx.update(|cx| {
this.update(cx, |this, cx| {
this.push_messages(events, cx);
});
})
.ok();
})
.ok();
}
})
.detach();
@@ -352,12 +355,11 @@ impl Chat {
let room = model.read(cx);
let task = room.send_message(content, cx);
let window_handle = window.window_handle();
cx.spawn(|this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if let Ok(msgs) = task.await {
_ = cx.update_window(window_handle, |_, window, cx| {
_ = this.update(cx, |this, cx| {
cx.update(|window, cx| {
this.update(cx, |this, cx| {
// Reset message input
cx.update_entity(&this.input, |this, cx| {
this.set_loading(false, window, cx);
@@ -365,7 +367,8 @@ impl Chat {
this.set_text("", window, cx);
cx.notify();
});
});
})
.ok();
for item in msgs.into_iter() {
window.push_notification(
@@ -373,7 +376,8 @@ impl Chat {
cx,
);
}
});
})
.ok();
}
})
.detach();
@@ -392,7 +396,7 @@ impl Chat {
self.set_loading(true, cx);
// TODO: support multiple upload
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
match Flatten::flatten(paths.await.map_err(|e| e.into())) {
Ok(Some(mut paths)) => {
let path = paths.pop().unwrap();

View File

@@ -33,7 +33,7 @@ impl Contacts {
let contacts = cx.new(|_| None);
let async_contact = contacts.clone();
cx.spawn(|mut cx| async move {
cx.spawn(async move |cx| {
let client = get_client();
let (tx, rx) = oneshot::channel::<Vec<NostrProfile>>();

View File

@@ -115,7 +115,7 @@ impl Login {
}),
);
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
cx.background_executor()
.timer(Duration::from_millis(500))
.await;

View File

@@ -122,7 +122,7 @@ impl NewAccount {
self.set_uploading(true, cx);
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
match Flatten::flatten(paths.await.map_err(|e| e.into())) {
Ok(Some(mut paths)) => {
let Some(path) = paths.pop() else {

View File

@@ -78,8 +78,8 @@ impl Profile {
focus_handle: cx.focus_handle(),
};
let client = get_client();
let task: Task<Result<Option<Metadata>, Error>> = cx.background_spawn(async move {
let client = get_client();
let signer = client.signer().await?;
let public_key = signer.get_public_key().await?;
let metadata = client
@@ -89,7 +89,7 @@ impl Profile {
Ok(metadata)
});
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(Some(metadata)) = task.await {
_ = cx.update_window(window_handle, |_, window, cx| {
_ = this.update(cx, |this: &mut Profile, cx| {
@@ -137,7 +137,7 @@ impl Profile {
// Show loading spinner
self.set_loading(true, cx);
cx.spawn(move |this, mut cx| async move {
cx.spawn(async move |this, cx| {
match Flatten::flatten(paths.await.map_err(|e| e.into())) {
Ok(Some(mut paths)) => {
let path = paths.pop().unwrap();
@@ -218,7 +218,7 @@ impl Profile {
let window_handle = window.window_handle();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
let client = get_client();
let (tx, rx) = oneshot::channel::<EventId>();

View File

@@ -65,14 +65,16 @@ impl Relays {
}
});
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(relays) = task.await {
_ = cx.update(|cx| {
_ = this.update(cx, |this: &mut Vec<RelayUrl>, cx| {
cx.update(|cx| {
this.update(cx, |this: &mut Vec<RelayUrl>, cx| {
*this = relays;
cx.notify();
});
});
})
.ok();
})
.ok();
}
})
.detach();
@@ -170,13 +172,14 @@ impl Relays {
Ok(output.val)
});
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if task.await.is_ok() {
cx.update(|window, cx| {
_ = this.update(cx, |this, cx| {
this.update(cx, |this, cx| {
this.set_loading(false, cx);
cx.notify();
});
})
.ok();
window.close_modal(cx);
})

View File

@@ -95,16 +95,17 @@ impl Compose {
})
.detach();
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(contacts) = rx.await {
_ = cx.update(|cx| {
cx.update(|cx| {
this.update(cx, |this, cx| {
this.contacts.update(cx, |this, cx| {
this.extend(contacts);
cx.notify();
});
})
});
})
.ok();
}
})
.detach();
@@ -146,7 +147,6 @@ impl Compose {
}
let tags = Tags::from_list(tag_list);
let window_handle = window.window_handle();
let event: Task<Result<Event, anyhow::Error>> = cx.background_spawn(async move {
let client = get_client();
@@ -162,9 +162,9 @@ impl Compose {
Ok(event)
});
cx.spawn(|this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if let Ok(event) = event.await {
_ = cx.update_window(window_handle, |_, window, cx| {
cx.update(|window, cx| {
// Stop loading spinner
this.update(cx, |this, cx| {
this.set_submitting(false, cx);
@@ -187,7 +187,8 @@ impl Compose {
}
}
});
});
})
.ok();
}
})
.detach();
@@ -242,7 +243,7 @@ impl Compose {
})
};
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
match task.await {
Ok(profile) => {
let public_key = profile.public_key;
@@ -308,14 +309,16 @@ impl Compose {
});
// Dismiss error after 2 seconds
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
Timer::after(Duration::from_secs(2)).await;
_ = cx.update(|cx| {
cx.update(|cx| {
this.update(cx, |this, cx| {
this.set_error(None, cx);
})
});
.ok();
})
.ok();
})
.detach();
}