update_notification.rs

 1use gpui::{
 2    div, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render,
 3    SemanticVersion, StatefulInteractiveElement, Styled, ViewContext,
 4};
 5use menu::Cancel;
 6use release_channel::ReleaseChannel;
 7use workspace::ui::{h_flex, v_flex, Icon, IconName, Label, StyledExt};
 8
 9pub struct UpdateNotification {
10    version: SemanticVersion,
11}
12
13impl EventEmitter<DismissEvent> for UpdateNotification {}
14
15impl Render for UpdateNotification {
16    fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
17        let app_name = ReleaseChannel::global(cx).display_name();
18
19        v_flex()
20            .on_action(cx.listener(UpdateNotification::dismiss))
21            .elevation_3(cx)
22            .p_4()
23            .child(
24                h_flex()
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(Icon::new(IconName::Close))
34                            .cursor_pointer()
35                            .on_click(cx.listener(|this, _, cx| this.dismiss(&menu::Cancel, 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.listener(|this, _, cx| {
44                        crate::view_release_notes(&Default::default(), cx);
45                        this.dismiss(&menu::Cancel, cx)
46                    })),
47            )
48    }
49}
50
51impl UpdateNotification {
52    pub fn new(version: SemanticVersion) -> Self {
53        Self { version }
54    }
55
56    pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
57        cx.emit(DismissEvent);
58    }
59}