#[cfg(test)]
mod copy_tests;
pub(super) mod update_panel;
#[cfg(any(test, feature = "test-support"))]
pub(in crate::app) struct FixtureAboutText(pub String);
#[cfg(any(test, feature = "test-support"))]
impl gpui_kit::Global for FixtureAboutText {}
use gpui_kit::component::WindowExt as _;
use gpui_kit::component::dialog::{DialogClose, DialogFooter};
use gpui_kit::component::v_flex;
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::{Context, InteractiveElement as _, ParentElement as _, Styled as _, Window, px};
use subspace_dashboard::copy_details::CopyDetails;
use subspace_dashboard::icon_button::IconButton;
use subspace_dashboard::tokens::ButtonRole;
use subspace_dashboard::{CurrentProduct, Modal};
use subspace_lucide::IconName;
use super::{OpenAbout, OpenLogView, SubspaceApp};
const ABOUT_WIDTH: f32 = 560.;
impl SubspaceApp {
pub(super) fn install_update_panel(&mut self, cx: &mut Context<Self>) {
update_panel::install(cx);
self._subscriptions.extend(update_panel::observe(cx));
}
pub(super) fn open_about(
&mut self,
_: &OpenAbout,
window: &mut Window,
cx: &mut Context<Self>,
) {
if window.has_active_dialog(cx) || !self.ready_for_about(cx) {
return;
}
let context = cx.global::<CurrentProduct>().0.clone();
let text = about_text(&context, cx);
let title = format!("About {}", context.product.display_name);
let app = cx.weak_entity();
let update_panel = update_panel::panel(cx);
window.open_dialog(cx, move |dialog, _, _| {
let close_app = app.clone();
dialog
.title(title.clone())
.width(px(ABOUT_WIDTH))
.overlay_closable(true)
.footer(
DialogFooter::new()
.child(
CopyDetails::diagnostics("about-copy-diagnostics")
.role(ButtonRole::Dialog),
)
.child(DialogClose::new().trigger(|button| {
IconButton::from_button(button)
.role(ButtonRole::Dialog)
.icon(IconName::X)
.label("Close")
})),
)
.child(v_flex().gap_2().whitespace_normal().child(text.clone()))
.when_some(update_panel.clone(), |dialog, panel| {
let log_app = app.clone();
dialog.child(
v_flex()
.on_action(move |_: &OpenLogView, window, cx| {
window.close_dialog(cx);
_ = log_app.update(cx, |app, cx| {
app.open_log_view(&OpenLogView, window, cx)
});
})
.child(panel),
)
})
.on_close(move |_, window, cx| {
_ = close_app.update(cx, |app, cx| {
app.focus_active(window, cx);
cx.notify();
});
})
});
cx.notify();
}
fn ready_for_about(&self, cx: &Context<Self>) -> bool {
if self.settings.is_some() || self.jig_open.get() || !self.jig.read(cx).can_close() {
return false;
}
self.dashboard()
.is_none_or(|dashboard| dashboard.modal(cx) != Some(Modal::Dialog))
}
}
fn about_text(context: &subspace_product::ProductContext, cx: &gpui_kit::App) -> String {
#[cfg(any(test, feature = "test-support"))]
if let Some(text) = cx.try_global::<FixtureAboutText>() {
return text.0.clone();
}
let _ = cx;
crate::build_metadata::about_text_for(context)
}