1use gpui::{
2 div, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render,
3 SemanticVersion, StatefulInteractiveElement, Styled, ViewContext, WeakView,
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: WeakView<Workspace>,
16}
17
18impl EventEmitter<DismissEvent> for UpdateNotification {}
19
20impl Render for UpdateNotification {
21 fn render(&mut self, cx: &mut ViewContext<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, _, cx| this.dismiss(&menu::Cancel, cx))),
41 ),
42 )
43 .child(
44 div()
45 .id("notes")
46 .child(Label::new("View the release notes"))
47 .cursor_pointer()
48 .on_click(cx.listener(|this, _, cx| {
49 this.workspace
50 .update(cx, |workspace, cx| {
51 crate::view_release_notes_locally(workspace, cx);
52 })
53 .log_err();
54 this.dismiss(&menu::Cancel, cx)
55 })),
56 )
57 }
58}
59
60impl UpdateNotification {
61 pub fn new(version: SemanticVersion, workspace: WeakView<Workspace>) -> Self {
62 Self { version, workspace }
63 }
64
65 pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
66 cx.emit(DismissEvent);
67 }
68}