1use gpui::{
2 div, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render,
3 SemanticVersion, StatefulInteractiveElement, Styled, ViewContext,
4};
5use menu::Cancel;
6use util::channel::ReleaseChannel;
7use workspace::ui::{h_stack, v_stack, 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 = cx.global::<ReleaseChannel>().display_name();
18
19 v_stack()
20 .on_action(cx.listener(UpdateNotification::dismiss))
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(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| 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, _: &Cancel, cx: &mut ViewContext<Self>) {
54 cx.emit(DismissEvent);
55 }
56}