title_bar: Simplify git-ui
feature flag check (#23475)
This PR is a follow-up to https://github.com/zed-industries/zed/pull/23470 that simplifies the way we check the `git-ui` feature flag in the title bar. Release Notes: - N/A
This commit is contained in:
parent
5930b552b9
commit
9f87145af9
5 changed files with 25 additions and 45 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -5242,7 +5242,6 @@ dependencies = [
|
|||
"collections",
|
||||
"db",
|
||||
"editor",
|
||||
"feature_flags",
|
||||
"futures 0.3.31",
|
||||
"git",
|
||||
"gpui",
|
||||
|
@ -5254,7 +5253,6 @@ dependencies = [
|
|||
"serde_derive",
|
||||
"serde_json",
|
||||
"settings",
|
||||
"smol",
|
||||
"theme",
|
||||
"ui",
|
||||
"util",
|
||||
|
|
|
@ -32,8 +32,6 @@ 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
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
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};
|
||||
|
@ -14,17 +12,6 @@ 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,
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::platforms::{platform_linux, platform_mac, platform_windows};
|
|||
use auto_update::AutoUpdateStatus;
|
||||
use call::ActiveCall;
|
||||
use client::{Client, UserStore};
|
||||
use feature_flags::{FeatureFlagAppExt, ZedPro};
|
||||
use feature_flags::{FeatureFlagAppExt, GitUiFeatureFlag, ZedPro};
|
||||
use git_ui::repository_selector::RepositorySelector;
|
||||
use git_ui::repository_selector::RepositorySelectorPopoverMenu;
|
||||
use gpui::{
|
||||
|
@ -27,6 +27,7 @@ use project::Project;
|
|||
use rpc::proto;
|
||||
use settings::Settings as _;
|
||||
use smallvec::SmallVec;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use theme::ActiveTheme;
|
||||
use ui::{
|
||||
|
@ -108,7 +109,7 @@ pub struct TitleBar {
|
|||
should_move: bool,
|
||||
application_menu: Option<View<ApplicationMenu>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
git_ui_enabled: bool,
|
||||
git_ui_enabled: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl Render for TitleBar {
|
||||
|
@ -290,7 +291,15 @@ impl TitleBar {
|
|||
subscriptions.push(cx.observe_window_activation(Self::window_activation_changed));
|
||||
subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
|
||||
|
||||
let title_bar = Self {
|
||||
let is_git_ui_enabled = Arc::new(AtomicBool::new(false));
|
||||
subscriptions.push(cx.observe_flag::<GitUiFeatureFlag, _>({
|
||||
let is_git_ui_enabled = is_git_ui_enabled.clone();
|
||||
move |enabled, _cx| {
|
||||
is_git_ui_enabled.store(enabled, Ordering::SeqCst);
|
||||
}
|
||||
}));
|
||||
|
||||
Self {
|
||||
platform_style,
|
||||
content: div().id(id.into()),
|
||||
children: SmallVec::new(),
|
||||
|
@ -302,29 +311,8 @@ 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<Self>) {
|
||||
let git_ui_feature_flag = cx.wait_for_flag::<feature_flags::GitUiFeatureFlag>();
|
||||
|
||||
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();
|
||||
git_ui_enabled: is_git_ui_enabled,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -507,7 +495,7 @@ impl TitleBar {
|
|||
&self,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<impl IntoElement> {
|
||||
if !self.git_ui_enabled {
|
||||
if !self.git_ui_enabled.load(Ordering::SeqCst) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -389,7 +389,16 @@ fn initialize_panels(prompt_builder: Arc<PromptBuilder>, cx: &mut ViewContext<Wo
|
|||
workspace.add_panel(notification_panel, cx);
|
||||
})?;
|
||||
|
||||
let git_ui_enabled = git_ui::git_ui_enabled(git_ui_feature_flag).await;
|
||||
let git_ui_enabled = {
|
||||
let mut git_ui_feature_flag = git_ui_feature_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,
|
||||
}
|
||||
};
|
||||
|
||||
let git_panel = if git_ui_enabled {
|
||||
Some(git_ui::git_panel::GitPanel::load(workspace_handle.clone(), cx.clone()).await?)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue