2022-06-07 00:27:16 +00:00
|
|
|
use crate::ViewReleaseNotes;
|
|
|
|
use gpui::{
|
|
|
|
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
|
|
|
|
platform::{AppVersion, CursorStyle},
|
2022-07-18 06:19:32 +00:00
|
|
|
Element, Entity, MouseButton, View, ViewContext,
|
2022-06-07 00:27:16 +00:00
|
|
|
};
|
|
|
|
use menu::Cancel;
|
2022-10-27 17:57:59 +00:00
|
|
|
use settings::{ReleaseChannel, Settings};
|
2022-06-07 00:27:16 +00:00
|
|
|
use workspace::Notification;
|
|
|
|
|
|
|
|
pub struct UpdateNotification {
|
|
|
|
version: AppVersion,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Event {
|
|
|
|
Dismiss,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Entity for UpdateNotification {
|
|
|
|
type Event = Event;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl View for UpdateNotification {
|
|
|
|
fn ui_name() -> &'static str {
|
|
|
|
"UpdateNotification"
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox {
|
|
|
|
let theme = cx.global::<Settings>().theme.clone();
|
|
|
|
let theme = &theme.update_notification;
|
|
|
|
|
2022-10-27 19:53:14 +00:00
|
|
|
let app_name = cx.global::<ReleaseChannel>().name();
|
2022-10-27 17:57:59 +00:00
|
|
|
|
2022-09-10 00:29:52 +00:00
|
|
|
MouseEventHandler::<ViewReleaseNotes>::new(0, cx, |state, cx| {
|
2022-06-07 00:27:16 +00:00
|
|
|
Flex::column()
|
|
|
|
.with_child(
|
|
|
|
Flex::row()
|
|
|
|
.with_child(
|
|
|
|
Text::new(
|
2022-10-27 17:57:59 +00:00
|
|
|
format!("Updated to {app_name} {}", self.version),
|
2022-06-07 00:27:16 +00:00
|
|
|
theme.message.text.clone(),
|
|
|
|
)
|
|
|
|
.contained()
|
|
|
|
.with_style(theme.message.container)
|
|
|
|
.aligned()
|
|
|
|
.top()
|
|
|
|
.left()
|
|
|
|
.flex(1., true)
|
|
|
|
.boxed(),
|
|
|
|
)
|
|
|
|
.with_child(
|
2022-09-10 00:29:52 +00:00
|
|
|
MouseEventHandler::<Cancel>::new(0, cx, |state, _| {
|
2022-06-07 00:27:16 +00:00
|
|
|
let style = theme.dismiss_button.style_for(state, false);
|
2022-10-28 16:59:05 +00:00
|
|
|
Svg::new("icons/x_mark_8.svg")
|
2022-06-07 00:27:16 +00:00
|
|
|
.with_color(style.color)
|
|
|
|
.constrained()
|
|
|
|
.with_width(style.icon_width)
|
|
|
|
.aligned()
|
|
|
|
.contained()
|
|
|
|
.with_style(style.container)
|
|
|
|
.constrained()
|
|
|
|
.with_width(style.button_width)
|
|
|
|
.with_height(style.button_width)
|
|
|
|
.boxed()
|
|
|
|
})
|
|
|
|
.with_padding(Padding::uniform(5.))
|
2022-07-18 06:19:32 +00:00
|
|
|
.on_click(MouseButton::Left, move |_, cx| cx.dispatch_action(Cancel))
|
2022-06-07 00:27:16 +00:00
|
|
|
.aligned()
|
|
|
|
.constrained()
|
|
|
|
.with_height(cx.font_cache().line_height(theme.message.text.font_size))
|
|
|
|
.aligned()
|
|
|
|
.top()
|
|
|
|
.flex_float()
|
|
|
|
.boxed(),
|
|
|
|
)
|
|
|
|
.boxed(),
|
|
|
|
)
|
|
|
|
.with_child({
|
|
|
|
let style = theme.action_message.style_for(state, false);
|
|
|
|
Text::new("View the release notes".to_string(), style.text.clone())
|
|
|
|
.contained()
|
|
|
|
.with_style(style.container)
|
|
|
|
.boxed()
|
|
|
|
})
|
|
|
|
.contained()
|
|
|
|
.boxed()
|
|
|
|
})
|
|
|
|
.with_cursor_style(CursorStyle::PointingHand)
|
2022-07-18 06:19:32 +00:00
|
|
|
.on_click(MouseButton::Left, |_, cx| {
|
|
|
|
cx.dispatch_action(ViewReleaseNotes)
|
|
|
|
})
|
2022-06-07 00:27:16 +00:00
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Notification for UpdateNotification {
|
|
|
|
fn should_dismiss_notification_on_event(&self, event: &<Self as Entity>::Event) -> bool {
|
|
|
|
matches!(event, Event::Dismiss)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateNotification {
|
|
|
|
pub fn new(version: AppVersion) -> Self {
|
|
|
|
Self { version }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
|
|
|
|
cx.emit(Event::Dismiss);
|
|
|
|
}
|
|
|
|
}
|