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 = "account"
version = "0.0.0"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[dependencies]
ui = { path = "../ui" }

View File

@@ -54,24 +54,22 @@ impl Account {
Ok(NostrProfile::new(public_key, metadata))
});
cx.spawn_in(window, |this, mut cx| async move {
match task.await {
Ok(profile) => {
cx.update(|_, cx| {
this.update(cx, |this, cx| {
this.profile = Some(profile);
this.subscribe(cx);
cx.notify();
})
cx.spawn_in(window, async move |this, cx| match task.await {
Ok(profile) => {
cx.update(|_, cx| {
this.update(cx, |this, cx| {
this.profile = Some(profile);
this.subscribe(cx);
cx.notify();
})
.ok();
}
Err(e) => {
cx.update(|window, cx| {
window.push_notification(Notification::error(e.to_string()), cx)
})
.ok();
}
})
.ok();
}
Err(e) => {
cx.update(|window, cx| {
window.push_notification(Notification::error(e.to_string()), cx)
})
.ok();
}
})
.detach();
@@ -91,7 +89,7 @@ impl Account {
Ok(NostrProfile::new(public_key, metadata))
});
cx.spawn_in(window, |this, mut cx| async move {
cx.spawn_in(window, async move |this, cx| {
if let Ok(profile) = task.await {
cx.update(|_, cx| {
this.update(cx, |this, cx| {
@@ -156,7 +154,7 @@ impl Account {
Ok(())
});
cx.spawn(|_, _| async move {
cx.spawn(async move |_, _| {
if let Err(e) = task.await {
log::error!("Error: {}", e);
}

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();
}

View File

@@ -1,8 +1,8 @@
[package]
name = "chats"
version = "0.0.0"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[dependencies]
common = { path = "../common" }

View File

@@ -73,10 +73,10 @@ impl ChatRegistry {
Ok(result)
});
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| {
if !events.is_empty() {
let current_ids = this.current_rooms_ids(cx);
let items: Vec<Entity<Room>> = events
@@ -93,7 +93,6 @@ impl ChatRegistry {
.collect();
this.is_loading = false;
this.rooms.extend(items);
this.rooms
.sort_by_key(|room| Reverse(room.read(cx).last_seen()));
@@ -102,8 +101,10 @@ impl ChatRegistry {
}
cx.notify();
});
});
})
.ok();
})
.ok();
}
})
.detach();

View File

@@ -44,7 +44,7 @@ impl Room {
// Create a task for loading metadata
let load_metadata = Self::load_metadata(event, cx);
let room = cx.new(|cx| {
cx.new(|cx| {
let this = Self {
id,
last_seen,
@@ -52,7 +52,7 @@ impl Room {
members: smallvec![],
};
cx.spawn(|this, cx| async move {
cx.spawn(async move |this, cx| {
if let Ok(profiles) = load_metadata.await {
_ = cx.update(|cx| {
_ = this.update(cx, |this: &mut Room, cx| {
@@ -82,9 +82,7 @@ impl Room {
.detach();
this
});
room
})
}
pub fn id(&self) -> u64 {

View File

@@ -1,8 +1,8 @@
[package]
name = "common"
version = "0.0.0"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[dependencies]
global = { path = "../global" }

View File

@@ -1,8 +1,8 @@
[package]
name = "global"
version = "0.0.0"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[dependencies]
nostr-sdk.workspace = true

View File

@@ -1,8 +1,8 @@
[package]
name = "ui"
version = "0.0.0"
edition = "2021"
publish = false
edition.workspace = true
publish.workspace = true
[dependencies]
gpui.workspace = true

View File

@@ -115,9 +115,8 @@ impl Element for Clipboard {
*copied.borrow_mut() = true;
let copied = copied.clone();
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
cx.background_executor().timer(Duration::from_secs(2)).await;
*copied.borrow_mut() = false;
})
.detach();

View File

@@ -574,8 +574,8 @@ impl DockArea {
window,
move |_, _, event, window, cx| {
if let PanelEvent::LayoutChanged = event {
cx.spawn_in(window, |view, mut window| async move {
_ = view.update_in(&mut window, |view, window, cx| {
cx.spawn_in(window, async move |view, window| {
_ = view.update_in(window, |view, window, cx| {
view.update_toggle_button_tab_panels(window, cx)
});
})
@@ -609,8 +609,8 @@ impl DockArea {
move |_, panel, event, window, cx| match event {
PanelEvent::ZoomIn => {
let panel = panel.clone();
cx.spawn_in(window, |view, mut window| async move {
_ = view.update_in(&mut window, |view, window, cx| {
cx.spawn_in(window, async move |view, window| {
_ = view.update_in(window, |view, window, cx| {
view.set_zoomed_in(panel, window, cx);
cx.notify();
});
@@ -618,15 +618,15 @@ impl DockArea {
.detach();
}
PanelEvent::ZoomOut => cx
.spawn_in(window, |view, mut window| async move {
_ = view.update_in(&mut window, |view, window, cx| {
.spawn_in(window, async move |view, window| {
_ = view.update_in(window, |view, window, cx| {
view.set_zoomed_out(window, cx);
});
})
.detach(),
PanelEvent::LayoutChanged => {
cx.spawn_in(window, |view, mut window| async move {
_ = view.update_in(&mut window, |view, window, cx| {
cx.spawn_in(window, async move |view, window| {
_ = view.update_in(window, |view, window, cx| {
view.update_toggle_button_tab_panels(window, cx)
});
})

View File

@@ -181,7 +181,7 @@ impl TabPanel {
self.focus_active_panel(window, cx);
// Sync the active state to all panels
cx.spawn(|view, cx| async move {
cx.spawn(async move |view, cx| {
_ = cx.update(|cx| {
_ = view.update(cx, |view, cx| {
if let Some(last_active) = view.panels.get(last_active_ix) {
@@ -255,7 +255,7 @@ impl TabPanel {
window: &mut Window,
cx: &mut Context<Self>,
) {
cx.spawn_in(window, |view, mut cx| async move {
cx.spawn_in(window, async move |view, cx| {
cx.update(|window, cx| {
view.update(cx, |view, cx| {
view.will_split_placement = Some(placement);
@@ -986,7 +986,7 @@ impl TabPanel {
});
}
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
cx.update(|window, cx| {
tab_panel.update(cx, |view, cx| view.remove_self_if_empty(window, cx))
})
@@ -1021,9 +1021,9 @@ impl TabPanel {
self.is_zoomed = !self.is_zoomed;
cx.spawn(|view, cx| {
cx.spawn({
let is_zoomed = self.is_zoomed;
async move {
async move |view, cx| {
_ = cx.update(|cx| {
_ = view.update(cx, |view, cx| {
view.set_zoomed(is_zoomed, cx);

View File

@@ -50,10 +50,10 @@ impl BlinkCursor {
// Schedule the next blink
let epoch = self.next_epoch();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
Timer::after(INTERVAL).await;
if let Some(this) = this.upgrade() {
this.update(&mut cx, |this, cx| this.blink(epoch, cx)).ok();
this.update(cx, |this, cx| this.blink(epoch, cx)).ok();
}
})
.detach();
@@ -71,11 +71,11 @@ impl BlinkCursor {
// delay 500ms to start the blinking
let epoch = self.next_epoch();
cx.spawn(|this, mut cx| async move {
cx.spawn(async move |this, cx| {
Timer::after(PAUSE_DELAY).await;
if let Some(this) = this.upgrade() {
this.update(&mut cx, |this, cx| {
this.update(cx, |this, cx| {
this.paused = false;
this.blink(epoch, cx);
})

View File

@@ -266,10 +266,10 @@ where
self.set_loading(true, window, cx);
let search = self.delegate.perform_search(&text, window, cx);
self._search_task = cx.spawn_in(window, |this, mut window| async move {
self._search_task = cx.spawn_in(window, async move |this, window| {
search.await;
_ = this.update_in(&mut window, |this, _, _| {
_ = this.update_in(window, |this, _, _| {
this.vertical_scroll_handle
.scroll_to_item(0, ScrollStrategy::Top);
this.last_query = Some(text);
@@ -277,7 +277,7 @@ where
// Always wait 100ms to avoid flicker
Timer::after(Duration::from_millis(100)).await;
_ = this.update_in(&mut window, |this, window, cx| {
_ = this.update_in(window, |this, window, cx| {
this.set_loading(false, window, cx);
});
});

View File

@@ -193,7 +193,7 @@ impl Notification {
cx.notify();
// Dismiss the notification after 0.15s to show the animation.
cx.spawn(|view, cx| async move {
cx.spawn(async move |view, cx| {
Timer::after(Duration::from_secs_f32(0.15)).await;
cx.update(|cx| {
if let Some(view) = view.upgrade() {
@@ -339,9 +339,9 @@ impl NotificationList {
self.notifications.push_back(notification.clone());
if autohide {
// Sleep for 3 seconds to autohide the notification
cx.spawn_in(window, |_, mut cx| async move {
cx.spawn_in(window, async move |_, cx| {
Timer::after(Duration::from_secs(3)).await;
_ = notification.update_in(&mut cx, |note, window, cx| {
_ = notification.update_in(cx, |note, window, cx| {
note.dismiss(&ClickEvent::default(), window, cx)
});
})

View File

@@ -164,9 +164,8 @@ impl Element for Switch {
.map_or(false, |prev| prev != checked)
{
let dur = Duration::from_secs_f64(0.15);
cx.spawn(|cx| async move {
cx.spawn(async move |cx| {
cx.background_executor().timer(dur).await;
*prev_checked.borrow_mut() = Some(checked);
})
.detach();