From 510260a10efbc179a5a3dccf5f28658df0e34744 Mon Sep 17 00:00:00 2001 From: Danilo Leal <67129314+danilo-leal@users.noreply.github.com> Date: Mon, 17 Feb 2025 11:32:04 -0300 Subject: [PATCH] Use the `MessageNotification` component for the release notes toast (#25013) Closes https://github.com/zed-industries/zed/issues/24981 Release Notes: - N/A --------- Co-authored-by: smit <0xtimsb@gmail.com> --- Cargo.lock | 1 - crates/auto_update_ui/Cargo.toml | 1 - crates/auto_update_ui/src/auto_update_ui.rs | 27 ++++--- .../auto_update_ui/src/update_notification.rs | 70 ------------------- crates/workspace/src/notifications.rs | 2 +- 5 files changed, 20 insertions(+), 81 deletions(-) delete mode 100644 crates/auto_update_ui/src/update_notification.rs diff --git a/Cargo.lock b/Cargo.lock index 1d3c9930a6ae6169e2fd153da3f102f2b9a44152..12dd44c71ac25bb77a92918225c69de72c76f92c 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.toml index 53e467ff27e34744f6f612c575e1cded4b3f3bf9..0e31f94f5ee268cdc3274dea747bd0b05d9c80eb 100644 --- a/crates/auto_update_ui/Cargo.toml +++ b/crates/auto_update_ui/Cargo.toml @@ -19,7 +19,6 @@ editor.workspace = true gpui.workspace = true http_client.workspace = true markdown_preview.workspace = true -menu.workspace = true release_channel.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/auto_update_ui/src/auto_update_ui.rs b/crates/auto_update_ui/src/auto_update_ui.rs index f0fbd6f404a0fb953a22916a263b64104b87c457..79ebdf9ce511aca0b0113042d74e52eefcf9f10e 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::(), 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.rs deleted file mode 100644 index e99e26983aff4370744dd0139c079b16b04c3baa..0000000000000000000000000000000000000000 --- 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, -} - -impl EventEmitter for UpdateNotification {} - -impl Render for UpdateNotification { - fn render(&mut self, _: &mut Window, cx: &mut Context) -> 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) -> Self { - Self { version, workspace } - } - - pub fn dismiss(&mut self, _: &Cancel, _: &mut Window, cx: &mut Context) { - cx.emit(DismissEvent); - } -} diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rs index 797c9754edd28ea9a96f33b9663d1cfa5aca3760..63dea1db0bc1e1b798cb258b70bf35c0e259e52b 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()