From eeb5b03d6344baa91e3f24cb6ef2f84bdef7edbe Mon Sep 17 00:00:00 2001 From: Joseph Lyons Date: Thu, 22 Dec 2022 03:24:21 -0500 Subject: [PATCH] add command to copy system information to the clipboard --- crates/workspace/src/workspace.rs | 52 ++++++++++++++++++++++++++++--- crates/zed/src/menus.rs | 13 +++++--- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index a53f20aeda1f10c2eb890205a95187ada8608cd5..c9c8120eb7251f501a911ce9bd807ab5f7fba9f6 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -34,15 +34,16 @@ use gpui::{ elements::*, impl_actions, impl_internal_actions, platform::{CursorStyle, WindowOptions}, - AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, - MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, RenderContext, Task, View, - ViewContext, ViewHandle, WeakViewHandle, + AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Entity, + ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, + RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle, }; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use language::LanguageRegistry; use std::{ any::TypeId, borrow::Cow, + env, future::Future, path::{Path, PathBuf}, sync::Arc, @@ -72,7 +73,7 @@ use status_bar::StatusBar; pub use status_bar::StatusItemView; use theme::{Theme, ThemeRegistry}; pub use toolbar::{ToolbarItemLocation, ToolbarItemView}; -use util::ResultExt; +use util::{channel::ReleaseChannel, ResultExt}; #[derive(Clone, PartialEq)] pub struct RemoveWorktreeFromProject(pub WorktreeId); @@ -96,6 +97,7 @@ actions!( ToggleRightSidebar, NewTerminal, NewSearch, + CopySystemDetailsIntoClipboard ] ); @@ -299,6 +301,12 @@ pub fn init(app_state: Arc, cx: &mut MutableAppContext) { }, ); + cx.add_action( + |workspace: &mut Workspace, _: &CopySystemDetailsIntoClipboard, cx| { + workspace.copy_system_details_into_clipboard(cx); + }, + ); + let client = &app_state.client; client.add_view_request_handler(Workspace::handle_follow); client.add_view_message_handler(Workspace::handle_unfollow); @@ -980,6 +988,42 @@ impl Workspace { }) } + fn copy_system_details_into_clipboard(&mut self, cx: &mut ViewContext) { + let platform = cx.platform(); + + let os_name: String = platform.os_name().into(); + let os_version = platform.os_version().ok(); + let app_version = env!("CARGO_PKG_VERSION"); + let release_channel = cx.global::().dev_name(); + let architecture = env::var("CARGO_CFG_TARGET_ARCH"); + + let os_information = match os_version { + Some(os_version) => format!("OS: {os_name} {os_version}"), + None => format!("OS: {os_name}"), + }; + let system_information = vec![ + Some(os_information), + Some(format!("Zed: {app_version} ({release_channel})")), + architecture + .map(|architecture| format!("Architecture: {architecture}")) + .ok(), + ]; + + let system_information = system_information + .into_iter() + .flatten() + .collect::>() + .join("\n"); + + let item = ClipboardItem::new(system_information.clone()); + cx.prompt( + gpui::PromptLevel::Info, + &format!("Copied into clipboard:\n\n{system_information}"), + &["OK"], + ); + cx.write_to_clipboard(item.clone()); + } + #[allow(clippy::type_complexity)] pub fn open_paths( &mut self, diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index 18e7d6fe9b1ef8be5c634ce04d25ee5a1cd09893..b8b0f69bd46e94d4600a70b651c849c28f910489 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -339,10 +339,8 @@ pub fn menus() -> Vec> { }, MenuItem::Separator, MenuItem::Action { - name: "Documentation", - action: Box::new(crate::OpenBrowser { - url: "https://zed.dev/docs".into(), - }), + name: "Copy System Details Into Clipboard", + action: Box::new(workspace::CopySystemDetailsIntoClipboard), }, MenuItem::Action { name: "Give Feedback", @@ -350,6 +348,13 @@ pub fn menus() -> Vec> { url: super::feedback::NEW_ISSUE_URL.into(), }), }, + MenuItem::Separator, + MenuItem::Action { + name: "Documentation", + action: Box::new(crate::OpenBrowser { + url: "https://zed.dev/docs".into(), + }), + }, MenuItem::Action { name: "Zed Twitter", action: Box::new(crate::OpenBrowser {