update_notification.rs

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