update_notification.rs

 1use gpui::{
 2    div, DismissEvent, Div, EventEmitter, InteractiveElement, ParentElement, Render,
 3    SemanticVersion, StatefulInteractiveElement, Styled, ViewContext,
 4};
 5use menu::Cancel;
 6use util::channel::ReleaseChannel;
 7use workspace::ui::{h_stack, v_stack, Icon, IconElement, Label, StyledExt};
 8
 9pub struct UpdateNotification {
10    version: SemanticVersion,
11}
12
13impl EventEmitter<DismissEvent> for UpdateNotification {}
14
15impl Render for UpdateNotification {
16    type Element = Div;
17
18    fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
19        let app_name = cx.global::<ReleaseChannel>().display_name();
20
21        v_stack()
22            .on_action(cx.listener(UpdateNotification::dismiss))
23            .elevation_3(cx)
24            .p_4()
25            .child(
26                h_stack()
27                    .justify_between()
28                    .child(Label::new(format!(
29                        "Updated to {app_name} {}",
30                        self.version
31                    )))
32                    .child(
33                        div()
34                            .id("cancel")
35                            .child(IconElement::new(Icon::Close))
36                            .cursor_pointer()
37                            .on_click(cx.listener(|this, _, cx| this.dismiss(&menu::Cancel, cx))),
38                    ),
39            )
40            .child(
41                div()
42                    .id("notes")
43                    .child(Label::new("View the release notes"))
44                    .cursor_pointer()
45                    .on_click(|_, cx| crate::view_release_notes(&Default::default(), cx)),
46            )
47    }
48}
49
50impl UpdateNotification {
51    pub fn new(version: SemanticVersion) -> Self {
52        Self { version }
53    }
54
55    pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
56        cx.emit(DismissEvent);
57    }
58}