From ad6e00b4b92ba8f3ab915b9204779531a21aa061 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Mon, 16 Nov 2026 20:52:32 +0700 Subject: [PATCH] Update nostr-sdk and adapt to new EventBuilder API --- Cargo.lock | 74 +++++------ crates/signed_app/src/app/mod.rs | 18 ++- crates/signed_app/src/repo/header.rs | 160 ++++++++++++----------- crates/signed_app/src/repo/mod.rs | 1 + crates/signed_app/src/titlebar/mod.rs | 101 +++++++++++--- crates/signed_core/src/announcement.rs | 4 +- crates/signed_core/src/filters.rs | 2 +- crates/signed_core/src/inbox/group.rs | 2 +- crates/signed_core/src/inbox/resolver.rs | 2 +- crates/signed_core/src/pull_request.rs | 10 +- crates/signed_core/src/status.rs | 4 +- crates/signed_state/src/inbox.rs | 3 +- crates/signed_state/src/local_repos.rs | 2 +- crates/signed_state/src/repo.rs | 7 +- crates/signed_state/src/state.rs | 2 +- 15 files changed, 234 insertions(+), 158 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61a7bb3..a86eda1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -932,7 +932,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "gpui_util", "indexmap", @@ -1341,7 +1341,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "proc-macro2", "quote", @@ -1579,7 +1579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -2391,7 +2391,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7518b930f6aeb75e871d32ce873c2ae46e35cef19b5a0b039d4337f651d897cd" dependencies = [ "bstr", - "hashbrown 0.16.1", + "hashbrown 0.17.1", ] [[package]] @@ -2988,7 +2988,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.2.2" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "accesskit", "anyhow", @@ -3167,7 +3167,7 @@ dependencies = [ [[package]] name = "gpui_apple" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "async-task", @@ -3206,7 +3206,7 @@ dependencies = [ [[package]] name = "gpui_ios" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "block2 0.6.2", @@ -3227,7 +3227,7 @@ dependencies = [ [[package]] name = "gpui_linux" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "accesskit", "anyhow", @@ -3254,7 +3254,7 @@ dependencies = [ [[package]] name = "gpui_macos" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "accesskit", "accesskit_macos", @@ -3295,7 +3295,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -3306,7 +3306,7 @@ dependencies = [ [[package]] name = "gpui_platform" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "console_error_panic_hook", @@ -3321,7 +3321,7 @@ dependencies = [ [[package]] name = "gpui_shared_string" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "schemars", "serde", @@ -3331,7 +3331,7 @@ dependencies = [ [[package]] name = "gpui_util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "log", @@ -3341,7 +3341,7 @@ dependencies = [ [[package]] name = "gpui_web" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "async-channel", @@ -3370,7 +3370,7 @@ dependencies = [ [[package]] name = "gpui_wgpu" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "bytemuck", @@ -3396,7 +3396,7 @@ dependencies = [ [[package]] name = "gpui_windows" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "accesskit", "accesskit_windows", @@ -3662,7 +3662,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "bytes", @@ -3679,7 +3679,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "log", "rustls", @@ -4730,7 +4730,7 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "nostr" version = "0.45.7" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "aes", "base64 0.22.1", @@ -4755,8 +4755,8 @@ dependencies = [ [[package]] name = "nostr-connect" -version = "0.45.2" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +version = "0.45.3" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "async-utility", "nostr", @@ -4769,7 +4769,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.45.2" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "nostr", "opaquerr", @@ -4778,7 +4778,7 @@ dependencies = [ [[package]] name = "nostr-gossip" version = "0.45.1" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "nostr", "opaquerr", @@ -4787,7 +4787,7 @@ dependencies = [ [[package]] name = "nostr-gossip-memory" version = "0.45.1" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "indexmap", "lru", @@ -4799,7 +4799,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.45.3" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "async-utility", "flatbuffers", @@ -4814,7 +4814,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.45.6" -source = "git+https://github.com/rust-nostr/nostr#4904ffb85f60178375a1dda659a61793f36f03b8" +source = "git+https://github.com/rust-nostr/nostr#8bb69e55bc8b5c6a52ffd09441824e65edb2e235" dependencies = [ "async-utility", "async-wsocket", @@ -5905,7 +5905,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -6178,7 +6178,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "derive_refineable", ] @@ -6261,7 +6261,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#053d91cb14b5fd138f221ec02bd76efb15e7b2af" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "anyhow", "bytes", @@ -6403,7 +6403,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -6471,7 +6471,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -6553,7 +6553,7 @@ dependencies = [ [[package]] name = "scheduler" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "async-task", "backtrace", @@ -7179,7 +7179,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "heapless 0.9.3", "rayon", @@ -7347,7 +7347,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -8540,7 +8540,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -9468,7 +9468,7 @@ dependencies = [ [[package]] name = "ztracing" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" dependencies = [ "tracing", "ztracing_macro", @@ -9477,7 +9477,7 @@ dependencies = [ [[package]] name = "ztracing_macro" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#99dd426cba792530d1b79ee0c4241c9076e7045f" +source = "git+https://github.com/zed-industries/zed#d39178f6c9e6adeb68e7a0df0b2a5b7d7bd35877" [[package]] name = "zune-core" diff --git a/crates/signed_app/src/app/mod.rs b/crates/signed_app/src/app/mod.rs index d9731f3..2ad9a25 100644 --- a/crates/signed_app/src/app/mod.rs +++ b/crates/signed_app/src/app/mod.rs @@ -36,7 +36,7 @@ pub struct AppRoot { impl AppRoot { pub fn new(window: &mut Window, cx: &mut Context) -> Self { let workspace = cx.new(|_| Workspace::new()); - let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), cx)); + let titlebar = cx.new(|cx| TitlebarView::new(workspace.downgrade(), window, cx)); let toasts = cx.new(|_| Toasts::default()); let sign_in = cx.new(|_| SignedOutView::new()); let empty = cx.new(|_| PlaceholderView::new("Select a repository")); @@ -94,14 +94,14 @@ impl Render for AppRoot { let titlebar_view = self.titlebar.read(cx); let mut titlebar = Titlebar::new("signed-titlebar"); - if let Some(menu) = titlebar_view.render_user_menu(cx) { - titlebar = titlebar.child(menu); + if let Some(actions) = titlebar_view.render_actions(cx) { + titlebar = titlebar.child(actions); } if let Some(tabs) = titlebar_view.render_tabs(cx) { titlebar = titlebar.tab_bar(tabs); } - if let Some(actions) = titlebar_view.render_actions(cx) { - titlebar = titlebar.suffix(actions); + if let Some(menu) = titlebar_view.render_user_menu(cx) { + titlebar = titlebar.suffix(menu); } let workspace = self.workspace.read(cx); @@ -118,7 +118,7 @@ impl Render for AppRoot { row = row.main(self.sign_in.clone()); } - div() + let mut root = div() .relative() .size_full() .font_family(".SystemUIFont") @@ -130,6 +130,10 @@ impl Render for AppRoot { .transparent(true) .toasts(self.toasts.clone()), ) - .child(self.dialogs.clone()) + .child(self.dialogs.clone()); + if is_signed_in { + root = root.child(titlebar_view.palette()); + } + root } } diff --git a/crates/signed_app/src/repo/header.rs b/crates/signed_app/src/repo/header.rs index b8bb372..8fca25f 100644 --- a/crates/signed_app/src/repo/header.rs +++ b/crates/signed_app/src/repo/header.rs @@ -168,7 +168,7 @@ impl RepoDetailView { .child( div() .min_w_0() - .typeset(TextRole::Body, cx) + .typeset(TextRole::Callout, cx) .text_color(cx.theme().colors.muted_foreground) .line_clamp(3) .child(description), @@ -180,79 +180,6 @@ impl RepoDetailView { .flex_none() .gap_2() .justify_end() - .child( - DropdownMenu::new("repo-menu") - .variant(ButtonVariant::Secondary) - .loading(pushing) - .disabled(pushing) - .open(self.repo_menu_open) - .on_open_change(move |open, _, cx| { - if let Err(error) = weak_menu_open.update(cx, |this, cx| { - this.repo_menu_open = open; - cx.notify(); - }) { - log::warn!("failed to update repo menu: {error}"); - } - }) - .items(move |_, cx| { - let owner = backend.read(cx).current_user() - == Some(announcement_for_menu.owner); - - let mut items = vec![MenuItem::new("About").handler({ - let weak = weak_menu_items.clone(); - let announcement = announcement_for_menu.clone(); - move |_, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - dialogs::about::open( - announcement.clone(), - this.directory.clone(), - cx, - ); - }) { - log::warn!("failed to open about: {error}"); - } - } - })]; - - if owner { - items.push(MenuItem::new("Republish").handler({ - let weak = weak_menu_items.clone(); - move |window, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - this.push_repository(window, cx); - }) { - log::warn!("failed to republish: {error}"); - } - } - })); - items.push(MenuItem::new("Reset remote to local").handler({ - let weak = weak_menu_items.clone(); - move |window, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - this.reset_remote(window, cx); - }) { - log::warn!("failed to reset remote: {error}"); - } - } - })); - items.push(MenuItem::separator()); - items.push(MenuItem::new("Delete").destructive(true).handler( - { - let weak = weak_menu_items.clone(); - move |window, cx| { - if let Err(error) = weak.update(cx, |this, cx| { - this.delete_repository(window, cx); - }) { - log::warn!("failed to delete: {error}"); - } - } - }, - )); - } - - items - }), - ) .when_some(self.render_sync_button(cx), |this, button| { this.child(button) }) @@ -341,6 +268,79 @@ impl RepoDetailView { ) .into_any_element() }), + ) + .child( + DropdownMenu::new("repo-menu") + .icon(CustomIconName::EllipsisVertical) + .variant(ButtonVariant::Ghost) + .disabled(pushing) + .open(self.repo_menu_open) + .on_open_change(move |open, _, cx| { + if let Err(error) = weak_menu_open.update(cx, |this, cx| { + this.repo_menu_open = open; + cx.notify(); + }) { + log::warn!("failed to update repo menu: {error}"); + } + }) + .items(move |_, cx| { + let owner = backend.read(cx).current_user() + == Some(announcement_for_menu.owner); + + let mut items = vec![MenuItem::new("About").handler({ + let weak = weak_menu_items.clone(); + let announcement = announcement_for_menu.clone(); + move |_, cx| { + if let Err(error) = weak.update(cx, |this, cx| { + dialogs::about::open( + announcement.clone(), + this.directory.clone(), + cx, + ); + }) { + log::warn!("failed to open about: {error}"); + } + } + })]; + + if owner { + items.push(MenuItem::new("Republish").handler({ + let weak = weak_menu_items.clone(); + move |window, cx| { + if let Err(error) = weak.update(cx, |this, cx| { + this.push_repository(window, cx); + }) { + log::warn!("failed to republish: {error}"); + } + } + })); + items.push(MenuItem::new("Reset remote to local").handler({ + let weak = weak_menu_items.clone(); + move |window, cx| { + if let Err(error) = weak.update(cx, |this, cx| { + this.reset_remote(window, cx); + }) { + log::warn!("failed to reset remote: {error}"); + } + } + })); + items.push(MenuItem::separator()); + items.push(MenuItem::new("Delete").destructive(true).handler( + { + let weak = weak_menu_items.clone(); + move |window, cx| { + if let Err(error) = weak.update(cx, |this, cx| { + this.delete_repository(window, cx); + }) { + log::warn!("failed to delete: {error}"); + } + } + }, + )); + } + + items + }), ), ) .into_any_element() @@ -365,7 +365,7 @@ impl RepoDetailView { v_flex() .flex_none() .p_6() - .h_24() + .h_32() .w_full() .items_center() .justify_center() @@ -374,8 +374,7 @@ impl RepoDetailView { Some(binding) => this.child(bound_repo_label(binding, &self.directory, cx)), None => this.child( Button::new("init") - .icon(Icon::named(CustomIconName::Init)) - .large() + .icon(Icon::named(CustomIconName::ArrowUp)) .label("Initialize on Nostr") .tooltip(Tooltip::text("Publish this repository to Nostr")) .on_click(cx.listener(|this, _, window, cx| { @@ -456,11 +455,13 @@ impl RepoDetailView { _ => None, }) .max_by_key(|(_, ahead)| *ahead)?; + let commits = if ahead == 1 { "1 commit".to_owned() } else { format!("{ahead} commits") }; + let path = checkout.path.clone(); ( Icon::named(IconRole::Refresh), @@ -583,11 +584,12 @@ impl RepoDetailView { .gap_2() .child( h_flex() - .gap_1() + .gap_2() .child( Avatar::new(announcement.owner) .name(owner_name.clone()) - .picture(owner.picture()), + .picture(owner.picture()) + .small(), ) .child( div() diff --git a/crates/signed_app/src/repo/mod.rs b/crates/signed_app/src/repo/mod.rs index 83981c1..0de592e 100644 --- a/crates/signed_app/src/repo/mod.rs +++ b/crates/signed_app/src/repo/mod.rs @@ -869,6 +869,7 @@ impl RepoDetailView { Sidebar::new("repo-sidebar") .selected(selected) .border_right(true) + .transparent(false) .on_change(move |index, _, cx| { let section = match (index, include_issues) { (Some(0), _) => RepoSection::Commits, diff --git a/crates/signed_app/src/titlebar/mod.rs b/crates/signed_app/src/titlebar/mod.rs index 50b0b86..18ea5d0 100644 --- a/crates/signed_app/src/titlebar/mod.rs +++ b/crates/signed_app/src/titlebar/mod.rs @@ -6,6 +6,7 @@ use gpui::{ }; use gpui_native_kit::avatar::Avatar; use gpui_native_kit::button::{Button, ButtonVariant}; +use gpui_native_kit::command_palette::{Command, CommandPalette, CommandPaletteState}; use gpui_native_kit::common::{Sizable as _, h_flex}; use gpui_native_kit::data::tabs::{Tab, Tabs, TabsVariant}; use gpui_native_kit::icons::{Icon, IconRole}; @@ -28,19 +29,24 @@ mod helpers; pub struct TitlebarView { weak: WeakEntity, workspace: WeakEntity, - scanning: bool, /// User's announced repositories. announcements: Arc>, /// Local repositories found by the scan that are not announced yet. local_repos: Arc>, /// Profiles rendered by the titlebar tabs. directory: gpui::Entity, + /// The command palette opened from the titlebar. + palette: gpui::Entity, user_menu_open: bool, _subscriptions: Vec, } impl TitlebarView { - pub fn new(workspace: WeakEntity, cx: &mut Context) -> Self { + pub fn new( + workspace: WeakEntity, + window: &mut Window, + cx: &mut Context, + ) -> Self { let backend = Backend::global(cx); let repos = RepoListStore::global(cx); let local = LocalReposStore::global(cx); @@ -68,25 +74,84 @@ impl TitlebarView { } })); - let mut this = Self { - weak: cx.entity().downgrade(), + let palette = Self::new_palette(workspace.clone(), window, cx); + + let entity = cx.entity(); + + let this = Self { + weak: entity.downgrade(), workspace, - scanning: false, announcements: Arc::new(Vec::new()), local_repos: Arc::new(Vec::new()), directory: ProfileDirectory::new(cx), + palette, user_menu_open: false, _subscriptions: subscriptions, }; - this.refresh(cx); + + cx.defer(move |cx| { + entity.update(cx, |this, cx| { + if this.refresh(cx) { + cx.notify(); + } + }); + }); + this } + fn new_palette( + workspace: WeakEntity, + window: &mut Window, + cx: &mut Context, + ) -> gpui::Entity { + cx.new(|cx| { + let matcher = |query: &str, commands: &[Command]| { + let needle = query.to_lowercase(); + commands + .iter() + .filter(|command| command.label.to_lowercase().contains(&needle)) + .cloned() + .collect() + }; + + CommandPaletteState::new( + CommandPalette::new("signed-command-palette", Self::palette_commands(), matcher) + .on_execute(move |command, window, cx| match command.id.as_ref() { + "create-repo" => dialogs::create::open(workspace.clone(), window, cx), + "rescan-repos" => { + let local_repos = LocalReposStore::global(cx); + local_repos.update(cx, |store, cx| store.rescan(cx)); + } + "open-settings" => settings::open(cx), + "exit" => identity::helpers::open_exit(cx), + _ => {} + }), + window, + cx, + ) + }) + } + + fn palette_commands() -> Vec { + vec![ + Command::new("create-repo", "Create repository").icon(Icon::named(IconRole::Plus)), + Command::new("rescan-repos", "Rescan for local repositories") + .icon(Icon::named(IconRole::Refresh)), + Command::new("open-settings", "Settings").icon(Icon::named(IconRole::Settings)), + Command::new("exit", "Exit"), + ] + } + + pub fn palette(&self) -> gpui::Entity { + self.palette.clone() + } + fn refresh(&mut self, cx: &mut Context) -> bool { let backend = Backend::global(cx); let user = backend.read(cx).current_user(); - let (announcements, local_repos, scanning) = { + let (announcements, local_repos) = { let repo_list = RepoListStore::global(cx).read(cx); let announcements = user @@ -98,16 +163,14 @@ impl TitlebarView { let local_repos = LocalReposStore::resolve(&local.repos, &repo_list.announcements, &announcements); - (announcements, local_repos, local.scanning) + (announcements, local_repos) }; let announcements_changed = *self.announcements != announcements; let local_changed = *self.local_repos != local_repos; - let scanning_changed = self.scanning != scanning; self.announcements = Arc::new(announcements); self.local_repos = Arc::new(local_repos); - self.scanning = scanning; let mut profiles: Vec = user.into_iter().collect(); let owners: Vec = self @@ -128,7 +191,7 @@ impl TitlebarView { directory.track(profiles, cx); }); - announcements_changed || local_changed || scanning_changed + announcements_changed || local_changed } pub fn render_tabs(&self, cx: &App) -> Option { @@ -348,15 +411,15 @@ impl TitlebarView { h_flex() .gap_1() .child( - Button::new("rescan-repos") - .icon(Icon::named(IconRole::Loader)) + Button::new("open-command-palette") + .icon(Icon::named(IconRole::Search)) .variant(ButtonVariant::Ghost) - .loading(self.scanning) - .disabled(self.scanning) - .tooltip(Tooltip::text("Rescan for local repositories")) - .on_click(|_, _, cx| { - let local_repos = LocalReposStore::global(cx); - local_repos.update(cx, |store, cx| store.rescan(cx)); + .tooltip(Tooltip::text("Command palette")) + .on_click({ + let palette = self.palette.clone(); + move |_, window, cx| { + palette.update(cx, |palette, cx| palette.toggle(window, cx)); + } }), ) .child( diff --git a/crates/signed_core/src/announcement.rs b/crates/signed_core/src/announcement.rs index 5c65db0..242cc77 100644 --- a/crates/signed_core/src/announcement.rs +++ b/crates/signed_core/src/announcement.rs @@ -171,7 +171,7 @@ mod tests { .map(|t| Tag::parse(t.to_vec()).expect("valid tag")) .collect(); - EventBuilder::new(Kind::GitRepoAnnouncement, "") + EventBuilder::new(Kind::GitRepoAnnouncement) .tags(tags) .finalize(&keys()) .expect("signed event") @@ -375,7 +375,7 @@ mod tests { .iter() .map(|t| Tag::parse(t.to_vec()).expect("valid tag")) .collect(); - EventBuilder::new(Kind::GitRepoAnnouncement, "") + EventBuilder::new(Kind::GitRepoAnnouncement) .tags(tags) .finalize(&keys) .expect("signed event") diff --git a/crates/signed_core/src/filters.rs b/crates/signed_core/src/filters.rs index 68b175d..bfcea1c 100644 --- a/crates/signed_core/src/filters.rs +++ b/crates/signed_core/src/filters.rs @@ -182,7 +182,7 @@ mod tests { } fn signed(author: &Keys, kind: Kind, tags: Vec) -> Event { - EventBuilder::new(kind, "") + EventBuilder::new(kind) .tags(tags) .finalize(author) .expect("signed event") diff --git a/crates/signed_core/src/inbox/group.rs b/crates/signed_core/src/inbox/group.rs index 8a1fb08..c301943 100644 --- a/crates/signed_core/src/inbox/group.rs +++ b/crates/signed_core/src/inbox/group.rs @@ -90,7 +90,7 @@ mod tests { /// Builds a signed event with a fixed timestamp. fn signed(author: &Keys, kind: Kind, tags: Vec, created_at: u64) -> Event { - EventBuilder::new(kind, "") + EventBuilder::new(kind) .tags(tags) .custom_created_at(Timestamp::from_secs(created_at)) .finalize(author) diff --git a/crates/signed_core/src/inbox/resolver.rs b/crates/signed_core/src/inbox/resolver.rs index 48e2918..e19a6f7 100644 --- a/crates/signed_core/src/inbox/resolver.rs +++ b/crates/signed_core/src/inbox/resolver.rs @@ -152,7 +152,7 @@ mod tests { /// Builds a signed event with a fixed timestamp. fn signed(author: &Keys, kind: Kind, tags: Vec, created_at: u64) -> Event { - EventBuilder::new(kind, "") + EventBuilder::new(kind) .tags(tags) .custom_created_at(Timestamp::from_secs(created_at)) .finalize(author) diff --git a/crates/signed_core/src/pull_request.rs b/crates/signed_core/src/pull_request.rs index 88ea4c9..28790aa 100644 --- a/crates/signed_core/src/pull_request.rs +++ b/crates/signed_core/src/pull_request.rs @@ -131,7 +131,8 @@ mod tests { /// Builds a signed pull request event. fn pr_event(content: &str, tags: Vec) -> Event { - EventBuilder::new(Kind::GitPullRequest, content) + EventBuilder::new(Kind::GitPullRequest) + .content(content) .tags(tags) .finalize(&keys()) .expect("signed event") @@ -139,7 +140,8 @@ mod tests { /// Builds a signed patch event with a fixed timestamp. fn patch_event(content: &str, tags: Vec, created_at: u64) -> Event { - EventBuilder::new(Kind::GitPatch, content) + EventBuilder::new(Kind::GitPatch) + .content(content) .tags(tags) .custom_created_at(Timestamp::from(created_at)) .finalize(&keys()) @@ -214,7 +216,7 @@ mod tests { /// Builds a signed event with a fixed timestamp. fn signed_at(kind: Kind, tags: Vec, created_at: u64) -> Event { - EventBuilder::new(kind, "") + EventBuilder::new(kind) .tags(tags) .custom_created_at(Timestamp::from(created_at)) .finalize(&keys()) @@ -268,7 +270,7 @@ mod tests { SecretKey::from_hex("0000000000000000000000000000000000000000000000000000000000000002") .expect("valid secret key"), ); - let stranger = EventBuilder::new(Kind::GitPullRequestUpdate, "") + let stranger = EventBuilder::new(Kind::GitPullRequestUpdate) .tags([Tag::parse(["E", &root_hex]).expect("valid tag")]) .custom_created_at(Timestamp::from(999)) .finalize(&other) diff --git a/crates/signed_core/src/status.rs b/crates/signed_core/src/status.rs index 2bb2f18..6f512d1 100644 --- a/crates/signed_core/src/status.rs +++ b/crates/signed_core/src/status.rs @@ -63,7 +63,7 @@ mod tests { } fn status_event(author: &Keys, kind: Kind, root: EventId, created_at: u64) -> Event { - EventBuilder::new(kind, "") + EventBuilder::new(kind) .tags([Tag::event(root)]) .custom_created_at(Timestamp::from(created_at)) .finalize(author) @@ -73,7 +73,7 @@ mod tests { #[test] fn references_root_matches_e_tag() { let root = root_event_id(); - let event = EventBuilder::new(Kind::GitStatusOpen, "") + let event = EventBuilder::new(Kind::GitStatusOpen) .tags([Tag::event(root)]) .finalize(&keys_from_hex( "0000000000000000000000000000000000000000000000000000000000000001", diff --git a/crates/signed_state/src/inbox.rs b/crates/signed_state/src/inbox.rs index 69bab27..0dadf49 100644 --- a/crates/signed_state/src/inbox.rs +++ b/crates/signed_state/src/inbox.rs @@ -154,7 +154,8 @@ impl Inbox { me: PublicKey, state: &InboxReadState, ) -> Result<(), Error> { - let event = EventBuilder::new(Kind::ApplicationSpecificData, serde_json::to_string(state)?) + let event = EventBuilder::new(Kind::ApplicationSpecificData) + .content(serde_json::to_string(state)?) .tags([Tag::identifier(Self::inbox_state_d_tag(me))]) .finalize(&Keys::generate())?; diff --git a/crates/signed_state/src/local_repos.rs b/crates/signed_state/src/local_repos.rs index 5fd5488..8d6ffa4 100644 --- a/crates/signed_state/src/local_repos.rs +++ b/crates/signed_state/src/local_repos.rs @@ -177,7 +177,7 @@ mod tests { fn announcement(secret: &str, id: &str) -> Announcement { let keys = Keys::new(SecretKey::from_hex(secret).expect("secret")); let tag = Tag::parse(vec!["d", id]).expect("tag"); - let event = EventBuilder::new(Kind::GitRepoAnnouncement, "") + let event = EventBuilder::new(Kind::GitRepoAnnouncement) .tags(vec![tag]) .finalize(&keys) .expect("signed"); diff --git a/crates/signed_state/src/repo.rs b/crates/signed_state/src/repo.rs index fae685e..836a86e 100644 --- a/crates/signed_state/src/repo.rs +++ b/crates/signed_state/src/repo.rs @@ -1134,7 +1134,7 @@ impl RepoStore { return; }; - let builder = EventBuilder::new(status.kind(), "").tags([ + let builder = EventBuilder::new(status.kind()).tags([ root_ref, Tag::public_key(addr.public_key()), Tag::public_key(root.pubkey), @@ -1508,7 +1508,10 @@ where tags.push(tag); } - let builder = EventBuilder::new(Kind::GitPatch, part.clone()).tags(tags); + let builder = EventBuilder::new(Kind::GitPatch) + .content(part.clone()) + .tags(tags); + let event = builder.finalize_async(signer).await?; let output = client.send_event(&event).broadcast().await?; diff --git a/crates/signed_state/src/state.rs b/crates/signed_state/src/state.rs index 58cb4e2..565d4a4 100644 --- a/crates/signed_state/src/state.rs +++ b/crates/signed_state/src/state.rs @@ -116,7 +116,7 @@ impl SyncState { ); } - EventBuilder::new(Kind::RepoState, "").tags(tags) + EventBuilder::new(Kind::RepoState).tags(tags) } pub fn parse(event: &Event) -> Self {