From 5be2784ddb104506e418896184039e265486d704 Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 22 Jan 2025 11:37:19 -0500 Subject: [PATCH] git_ui: Feature flag repo selector (#23470) Fixes an issue where the repo selector showed for all users, not just those in the git_ui feature flag. This was meant to be included in the `git_ui` feature flag. Release Notes: - N/A --- Cargo.lock | 2 ++ crates/git_ui/Cargo.toml | 2 ++ crates/git_ui/src/git_ui.rs | 13 ++++++++++++ crates/title_bar/src/title_bar.rs | 34 ++++++++++++++++++++++++++++--- crates/zed/src/zed.rs | 10 +-------- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7920d44783047e1a18dfaa859c7c081f9fbbed8..1f6edc76067b67fbdd3f583cbf13d662fe5e388b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5242,6 +5242,7 @@ dependencies = [ "collections", "db", "editor", + "feature_flags", "futures 0.3.31", "git", "gpui", @@ -5253,6 +5254,7 @@ dependencies = [ "serde_derive", "serde_json", "settings", + "smol", "theme", "ui", "util", diff --git a/crates/git_ui/Cargo.toml b/crates/git_ui/Cargo.toml index acc7987d80a6d3bc9bdfa0c1117c72f5d6b30928..f79ac7dddfca9b784a93f10fb4e7d4a715eefa94 100644 --- a/crates/git_ui/Cargo.toml +++ b/crates/git_ui/Cargo.toml @@ -32,6 +32,8 @@ ui.workspace = true util.workspace = true workspace.workspace = true picker.workspace = true +feature_flags.workspace = true +smol.workspace = true [target.'cfg(windows)'.dependencies] windows.workspace = true diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 5cb341ed454142b4bc3962f19fffb48ad7411882..c91402f1723680f850a9321d6cc736a0ae287ad6 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/crates/git_ui/src/git_ui.rs @@ -1,4 +1,6 @@ use ::settings::Settings; +use feature_flags::WaitForFlag; +use futures::{select_biased, FutureExt}; use git::status::FileStatus; use git_panel_settings::GitPanelSettings; use gpui::{AppContext, Hsla}; @@ -12,6 +14,17 @@ pub fn init(cx: &mut AppContext) { GitPanelSettings::register(cx); } +// TODO: Remove this before launching Git UI +pub async fn git_ui_enabled(flag: WaitForFlag) -> bool { + let mut git_ui_feature_flag = flag.fuse(); + let mut timeout = FutureExt::fuse(smol::Timer::after(std::time::Duration::from_secs(5))); + + select_biased! { + is_git_ui_enabled = git_ui_feature_flag => is_git_ui_enabled, + _ = timeout => false, + } +} + const ADDED_COLOR: Hsla = Hsla { h: 142. / 360., s: 0.68, diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs index b8dcd0c433c5d113af9fbff20c5e247aac86c5a5..c8d8455e48bb546b4478d7a42c48917129fd3e2b 100644 --- a/crates/title_bar/src/title_bar.rs +++ b/crates/title_bar/src/title_bar.rs @@ -108,6 +108,7 @@ pub struct TitleBar { should_move: bool, application_menu: Option>, _subscriptions: Vec, + git_ui_enabled: bool, } impl Render for TitleBar { @@ -289,7 +290,7 @@ impl TitleBar { subscriptions.push(cx.observe_window_activation(Self::window_activation_changed)); subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify())); - Self { + let title_bar = Self { platform_style, content: div().id(id.into()), children: SmallVec::new(), @@ -301,7 +302,29 @@ impl TitleBar { user_store, client, _subscriptions: subscriptions, - } + git_ui_enabled: false, + }; + + title_bar.check_git_ui_enabled(cx); + + title_bar + } + + fn check_git_ui_enabled(&self, cx: &mut ViewContext) { + let git_ui_feature_flag = cx.wait_for_flag::(); + + let weak_self = cx.view().downgrade(); + cx.spawn(|_, mut cx| async move { + let enabled = git_ui::git_ui_enabled(git_ui_feature_flag).await; + if let Some(this) = weak_self.upgrade() { + this.update(&mut cx, |this, cx| { + this.git_ui_enabled = enabled; + cx.notify(); + }) + .ok(); + } + }) + .detach(); } #[cfg(not(target_os = "windows"))] @@ -484,9 +507,14 @@ impl TitleBar { &self, cx: &mut ViewContext, ) -> Option { - // TODO what to render if no active repository? + if !self.git_ui_enabled { + return None; + } + let active_repository = self.project.read(cx).active_repository(cx)?; let display_name = active_repository.display_name(self.project.read(cx), cx); + + // TODO: what to render if no active repository? Some(RepositorySelectorPopoverMenu::new( self.repository_selector.clone(), ButtonLike::new("active-repository") diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 16504c3077046ae6e93c4aaea9c42ec761e760eb..eb87c7add3201e733df2b86d02899815770d18a9 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -389,16 +389,8 @@ fn initialize_panels(prompt_builder: Arc, cx: &mut ViewContext is_git_ui_enabled, - _ = timeout => false, - } - }; let git_panel = if git_ui_enabled { Some(git_ui::git_panel::GitPanel::load(workspace_handle.clone(), cx.clone()).await?) } else {