Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use the `MessageNotification` component for the release notes toast (#25013)
Danilo Leal510260a10efb
diff --git a/Cargo.lock b/Cargo.lockindex 1d3c9930a6a..12dd44c71ac 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1142,7 +1142,6 @@ dependencies = ["gpui","http_client","markdown_preview",- "menu","release_channel","serde","serde_json",diff --git a/crates/auto_update_ui/Cargo.toml b/crates/auto_update_ui/Cargo.tomlindex 53e467ff27e..0e31f94f5ee 100644--- a/crates/auto_update_ui/Cargo.toml+++ b/crates/auto_update_ui/Cargo.toml@@ -19,7 +19,6 @@ editor.workspace = truegpui.workspace = truehttp_client.workspace = truemarkdown_preview.workspace = true-menu.workspace = truerelease_channel.workspace = trueserde.workspace = trueserde_json.workspace = truediff --git a/crates/auto_update_ui/src/auto_update_ui.rs b/crates/auto_update_ui/src/auto_update_ui.rsindex f0fbd6f404a..79ebdf9ce51 100644--- a/crates/auto_update_ui/src/auto_update_ui.rs+++ b/crates/auto_update_ui/src/auto_update_ui.rs@@ -1,19 +1,17 @@-mod update_notification;-use auto_update::AutoUpdater;+use client::proto::UpdateNotification;use editor::{Editor, MultiBuffer};-use gpui::{actions, prelude::*, App, Context, Entity, SharedString, Window};+use gpui::{actions, prelude::*, App, Context, DismissEvent, Entity, SharedString, Window};use http_client::HttpClient;use markdown_preview::markdown_preview_view::{MarkdownPreviewMode, MarkdownPreviewView};use release_channel::{AppVersion, ReleaseChannel};use serde::Deserialize;use smol::io::AsyncReadExt;use util::ResultExt as _;+use workspace::notifications::simple_message_notification::MessageNotification;use workspace::notifications::{show_app_notification, NotificationId};use workspace::Workspace;-use crate::update_notification::UpdateNotification;-actions!(auto_update, [ViewReleaseNotesLocally]);pub fn init(cx: &mut App) {@@ -131,19 +129,32 @@ pub fn notify_if_app_was_updated(cx: &mut App) {let Some(updater) = AutoUpdater::get(cx) else {return;};- let version = updater.read(cx).current_version();let should_show_notification = updater.read(cx).should_show_update_notification(cx);-cx.spawn(|cx| async move {let should_show_notification = should_show_notification.await?;if should_show_notification {cx.update(|cx| {+ let version = updater.read(cx).current_version();+ let app_name = ReleaseChannel::global(cx).display_name();show_app_notification(NotificationId::unique::<UpdateNotification>(),cx,move |cx| {let workspace_handle = cx.entity().downgrade();- cx.new(|_| UpdateNotification::new(version, workspace_handle))+ cx.new(|_cx| {+ MessageNotification::new(format!("Updated to {app_name} {}", version))+ .primary_message("View Release Notes")+ .primary_on_click(move |window, cx| {+ if let Some(workspace) = workspace_handle.upgrade() {+ workspace.update(cx, |workspace, cx| {+ crate::view_release_notes_locally(+ workspace, window, cx,+ );+ })+ }+ cx.emit(DismissEvent);+ })+ })},);updater.update(cx, |updater, cx| {diff --git a/crates/auto_update_ui/src/update_notification.rs b/crates/auto_update_ui/src/update_notification.rsdeleted file mode 100644index e99e26983af..00000000000--- a/crates/auto_update_ui/src/update_notification.rs+++ /dev/null@@ -1,70 +0,0 @@-use gpui::{- div, Context, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement,- Render, SemanticVersion, StatefulInteractiveElement, Styled, WeakEntity, Window,-};-use menu::Cancel;-use release_channel::ReleaseChannel;-use util::ResultExt;-use workspace::{- ui::{h_flex, v_flex, Icon, IconName, Label, StyledExt},- Workspace,-};--pub struct UpdateNotification {- version: SemanticVersion,- workspace: WeakEntity<Workspace>,-}--impl EventEmitter<DismissEvent> for UpdateNotification {}--impl Render for UpdateNotification {- fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {- let app_name = ReleaseChannel::global(cx).display_name();-- v_flex()- .on_action(cx.listener(UpdateNotification::dismiss))- .elevation_3(cx)- .p_4()- .child(- h_flex()- .justify_between()- .child(Label::new(format!(- "Updated to {app_name} {}",- self.version- )))- .child(- div()- .id("cancel")- .child(Icon::new(IconName::Close))- .cursor_pointer()- .on_click(cx.listener(|this, _, window, cx| {- this.dismiss(&menu::Cancel, window, cx)- })),- ),- )- .child(- div()- .id("notes")- .child(Label::new("View the release notes"))- .cursor_pointer()- .on_click(cx.listener(|this, _, window, cx| {- this.workspace- .update(cx, |workspace, cx| {- crate::view_release_notes_locally(workspace, window, cx);- })- .log_err();- this.dismiss(&menu::Cancel, window, cx)- })),- )- }-}--impl UpdateNotification {- pub fn new(version: SemanticVersion, workspace: WeakEntity<Workspace>) -> Self {- Self { version, workspace }- }-- pub fn dismiss(&mut self, _: &Cancel, _: &mut Window, cx: &mut Context<Self>) {- cx.emit(DismissEvent);- }-}diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rsindex 797c9754edd..63dea1db0bc 100644--- a/crates/workspace/src/notifications.rs+++ b/crates/workspace/src/notifications.rs@@ -529,7 +529,7 @@ pub mod simple_message_notification {v_flex().occlude().p_3()- .gap_3()+ .gap_2().elevation_3(cx).child(h_flex()