update_notification.rs

 1use gpui::{
 2    div, Context, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement,
 3    Render, SemanticVersion, StatefulInteractiveElement, Styled, WeakEntity, Window,
 4};
 5use menu::Cancel;
 6use release_channel::ReleaseChannel;
 7use util::ResultExt;
 8use workspace::{
 9    ui::{h_flex, v_flex, Icon, IconName, Label, StyledExt},
10    Workspace,
11};
12
13pub struct UpdateNotification {
14    version: SemanticVersion,
15    workspace: WeakEntity<Workspace>,
16}
17
18impl EventEmitter<DismissEvent> for UpdateNotification {}
19
20impl Render for UpdateNotification {
21    fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
22        let app_name = ReleaseChannel::global(cx).display_name();
23
24        v_flex()
25            .on_action(cx.listener(UpdateNotification::dismiss))
26            .elevation_3(cx)
27            .p_4()
28            .child(
29                h_flex()
30                    .justify_between()
31                    .child(Label::new(format!(
32                        "Updated to {app_name} {}",
33                        self.version
34                    )))
35                    .child(
36                        div()
37                            .id("cancel")
38                            .child(Icon::new(IconName::Close))
39                            .cursor_pointer()
40                            .on_click(cx.listener(|this, _, window, cx| {
41                                this.dismiss(&menu::Cancel, window, cx)
42                            })),
43                    ),
44            )
45            .child(
46                div()
47                    .id("notes")
48                    .child(Label::new("View the release notes"))
49                    .cursor_pointer()
50                    .on_click(cx.listener(|this, _, window, cx| {
51                        this.workspace
52                            .update(cx, |workspace, cx| {
53                                crate::view_release_notes_locally(workspace, window, cx);
54                            })
55                            .log_err();
56                        this.dismiss(&menu::Cancel, window, cx)
57                    })),
58            )
59    }
60}
61
62impl UpdateNotification {
63    pub fn new(version: SemanticVersion, workspace: WeakEntity<Workspace>) -> Self {
64        Self { version, workspace }
65    }
66
67    pub fn dismiss(&mut self, _: &Cancel, _: &mut Window, cx: &mut Context<Self>) {
68        cx.emit(DismissEvent);
69    }
70}