2022-06-07 00:27:16 +00:00
|
|
|
use gpui::{
|
2024-01-03 18:52:40 +00:00
|
|
|
div, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render,
|
|
|
|
SemanticVersion, StatefulInteractiveElement, Styled, ViewContext,
|
2022-06-07 00:27:16 +00:00
|
|
|
};
|
|
|
|
use menu::Cancel;
|
2022-11-14 21:18:44 +00:00
|
|
|
use util::channel::ReleaseChannel;
|
2024-01-03 18:52:40 +00:00
|
|
|
use workspace::ui::{h_stack, v_stack, Icon, IconElement, Label, StyledExt};
|
2022-06-07 00:27:16 +00:00
|
|
|
|
|
|
|
pub struct UpdateNotification {
|
2024-01-03 18:52:40 +00:00
|
|
|
version: SemanticVersion,
|
2022-06-07 00:27:16 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 18:52:40 +00:00
|
|
|
impl EventEmitter<DismissEvent> for UpdateNotification {}
|
2022-06-07 00:27:16 +00:00
|
|
|
|
2024-01-03 18:52:40 +00:00
|
|
|
impl Render for UpdateNotification {
|
|
|
|
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
|
2022-12-02 22:30:26 +00:00
|
|
|
let app_name = cx.global::<ReleaseChannel>().display_name();
|
2022-10-27 17:57:59 +00:00
|
|
|
|
2024-01-03 18:52:40 +00:00
|
|
|
v_stack()
|
|
|
|
.on_action(cx.listener(UpdateNotification::dismiss))
|
|
|
|
.elevation_3(cx)
|
|
|
|
.p_4()
|
|
|
|
.child(
|
|
|
|
h_stack()
|
|
|
|
.justify_between()
|
|
|
|
.child(Label::new(format!(
|
|
|
|
"Updated to {app_name} {}",
|
|
|
|
self.version
|
|
|
|
)))
|
|
|
|
.child(
|
|
|
|
div()
|
|
|
|
.id("cancel")
|
|
|
|
.child(IconElement::new(Icon::Close))
|
|
|
|
.cursor_pointer()
|
|
|
|
.on_click(cx.listener(|this, _, cx| this.dismiss(&menu::Cancel, cx))),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.child(
|
|
|
|
div()
|
|
|
|
.id("notes")
|
|
|
|
.child(Label::new("View the release notes"))
|
|
|
|
.cursor_pointer()
|
|
|
|
.on_click(|_, cx| crate::view_release_notes(&Default::default(), cx)),
|
|
|
|
)
|
2022-06-07 00:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateNotification {
|
2024-01-03 18:52:40 +00:00
|
|
|
pub fn new(version: SemanticVersion) -> Self {
|
2022-06-07 00:27:16 +00:00
|
|
|
Self { version }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
|
2024-01-03 18:52:40 +00:00
|
|
|
cx.emit(DismissEvent);
|
2022-06-07 00:27:16 +00:00
|
|
|
}
|
|
|
|
}
|