From 1021f0e28808285e3d301fcb9ccf9af40854ea98 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sat, 28 Sep 2024 14:21:13 -0400 Subject: [PATCH] Show release notes locally when showing update notification (#18486) Closes https://github.com/zed-industries/zed/issues/17527 I think we are ok to switch to using the local action now. There are a few things we don't support, like media, but we don't include media directly too often, and I think this might help push the community to maybe add support for it. That being said, I updated the markdown coming back from the endpoint to include links to the web version of the release notes, so they can always hop over to that version, if they would like. https://github.com/user-attachments/assets/b4d207a7-1640-48f1-91d0-94537f74116c All forming of the Markdown happens in the endpoint, so if someone with a better eye wants to update this, you can do that here: https://github.com/zed-industries/zed.dev/blob/0e5923e3e7d1caa8b4bf32d0a7f8999b34dbe64c/src/pages/api/release_notes/v2/%5Bchannel_type%5D/%5Bversion%5D.ts#L50-L62 Release Notes: - Changed the `view the release notes` button in the update toast to trigger the local release notes action. --- crates/auto_update/src/auto_update.rs | 12 +++++++----- crates/auto_update/src/update_notification.rs | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 1fe89cce0f9c4..60d6369ee869c 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -345,15 +345,17 @@ pub fn notify_of_any_new_update(cx: &mut ViewContext) -> Option<()> { let should_show_notification = should_show_notification.await?; if should_show_notification { workspace.update(&mut cx, |workspace, cx| { + let workspace_handle = workspace.weak_handle(); workspace.show_notification( NotificationId::unique::(), cx, - |cx| cx.new_view(|_| UpdateNotification::new(version)), + |cx| cx.new_view(|_| UpdateNotification::new(version, workspace_handle)), ); - updater - .read(cx) - .set_should_show_update_notification(false, cx) - .detach_and_log_err(cx); + updater.update(cx, |updater, cx| { + updater + .set_should_show_update_notification(false, cx) + .detach_and_log_err(cx); + }); })?; } anyhow::Ok(()) diff --git a/crates/auto_update/src/update_notification.rs b/crates/auto_update/src/update_notification.rs index 66028c2401199..7568a0eb1a94e 100644 --- a/crates/auto_update/src/update_notification.rs +++ b/crates/auto_update/src/update_notification.rs @@ -1,13 +1,18 @@ use gpui::{ div, DismissEvent, EventEmitter, InteractiveElement, IntoElement, ParentElement, Render, - SemanticVersion, StatefulInteractiveElement, Styled, ViewContext, + SemanticVersion, StatefulInteractiveElement, Styled, ViewContext, WeakView, }; use menu::Cancel; use release_channel::ReleaseChannel; -use workspace::ui::{h_flex, v_flex, Icon, IconName, Label, StyledExt}; +use util::ResultExt; +use workspace::{ + ui::{h_flex, v_flex, Icon, IconName, Label, StyledExt}, + Workspace, +}; pub struct UpdateNotification { version: SemanticVersion, + workspace: WeakView, } impl EventEmitter for UpdateNotification {} @@ -41,7 +46,11 @@ impl Render for UpdateNotification { .child(Label::new("View the release notes")) .cursor_pointer() .on_click(cx.listener(|this, _, cx| { - crate::view_release_notes(&Default::default(), cx); + this.workspace + .update(cx, |workspace, cx| { + crate::view_release_notes_locally(workspace, cx); + }) + .log_err(); this.dismiss(&menu::Cancel, cx) })), ) @@ -49,8 +58,8 @@ impl Render for UpdateNotification { } impl UpdateNotification { - pub fn new(version: SemanticVersion) -> Self { - Self { version } + pub fn new(version: SemanticVersion, workspace: WeakView) -> Self { + Self { version, workspace } } pub fn dismiss(&mut self, _: &Cancel, cx: &mut ViewContext) {