diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index c9c8120eb7251f501a911ce9bd807ab5f7fba9f6..06e19bbf88c1dcabb1827254209a08d8b104cd85 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -34,16 +34,15 @@ use gpui::{ elements::*, impl_actions, impl_internal_actions, platform::{CursorStyle, WindowOptions}, - AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Entity, - ModelContext, ModelHandle, MouseButton, MutableAppContext, PathPromptOptions, PromptLevel, - RenderContext, Task, View, ViewContext, ViewHandle, WeakViewHandle, + AnyModelHandle, AnyViewHandle, AppContext, AsyncAppContext, 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, @@ -73,7 +72,7 @@ use status_bar::StatusBar; pub use status_bar::StatusItemView; use theme::{Theme, ThemeRegistry}; pub use toolbar::{ToolbarItemLocation, ToolbarItemView}; -use util::{channel::ReleaseChannel, ResultExt}; +use util::ResultExt; #[derive(Clone, PartialEq)] pub struct RemoveWorktreeFromProject(pub WorktreeId); @@ -96,8 +95,7 @@ actions!( ToggleLeftSidebar, ToggleRightSidebar, NewTerminal, - NewSearch, - CopySystemDetailsIntoClipboard + NewSearch ] ); @@ -301,12 +299,6 @@ 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); @@ -988,42 +980,6 @@ 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 b8b0f69bd46e94d4600a70b651c849c28f910489..3865389e99f7e30cabccb2bf427130fffaaf866e 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -339,8 +339,8 @@ pub fn menus() -> Vec> { }, MenuItem::Separator, MenuItem::Action { - name: "Copy System Details Into Clipboard", - action: Box::new(workspace::CopySystemDetailsIntoClipboard), + name: "Copy System Specs Into Clipboard", + action: Box::new(crate::CopySystemSpecsIntoClipboard), }, MenuItem::Action { name: "Give Feedback", diff --git a/crates/zed/src/system_specs.rs b/crates/zed/src/system_specs.rs new file mode 100644 index 0000000000000000000000000000000000000000..56eeeb8167ec26f9e7377ba29bc62028457e6c54 --- /dev/null +++ b/crates/zed/src/system_specs.rs @@ -0,0 +1,46 @@ +use std::{env, fmt::Display}; + +use gpui::AppContext; +use util::channel::ReleaseChannel; + +pub struct SystemSpecs { + os_name: &'static str, + os_version: Option, + app_version: &'static str, + release_channel: &'static str, + architecture: &'static str, +} + +impl SystemSpecs { + pub fn new(cx: &AppContext) -> Self { + let platform = cx.platform(); + + SystemSpecs { + os_name: platform.os_name(), + os_version: platform + .os_version() + .ok() + .map(|os_version| os_version.to_string()), + app_version: env!("CARGO_PKG_VERSION"), + release_channel: cx.global::().dev_name(), + architecture: env::consts::ARCH, + } + } +} + +impl Display for SystemSpecs { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let os_information = match &self.os_version { + Some(os_version) => format!("OS: {} {}", self.os_name, os_version), + None => format!("OS: {}", self.os_name), + }; + let system_specs = [ + os_information, + format!("Zed: {} ({})", self.app_version, self.release_channel), + format!("Architecture: {}", self.architecture), + ] + .join("\n"); + + write!(f, "{system_specs}") + } +} diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 099fb4eea934cf286da36959040595f1bbb0774f..0936e317f4ab405ed02d0f9c6a46005fb9bf19fc 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -1,6 +1,7 @@ mod feedback; pub mod languages; pub mod menus; +pub mod system_specs; #[cfg(any(test, feature = "test-support"))] pub mod test; @@ -21,7 +22,7 @@ use gpui::{ }, impl_actions, platform::{WindowBounds, WindowOptions}, - AssetSource, AsyncAppContext, TitlebarOptions, ViewContext, WindowKind, + AssetSource, AsyncAppContext, ClipboardItem, TitlebarOptions, ViewContext, WindowKind, }; use language::Rope; use lazy_static::lazy_static; @@ -33,6 +34,7 @@ use serde::Deserialize; use serde_json::to_string_pretty; use settings::{keymap_file_json_schema, settings_file_json_schema, Settings}; use std::{env, path::Path, str, sync::Arc}; +use system_specs::SystemSpecs; use util::{channel::ReleaseChannel, paths, ResultExt}; pub use workspace; use workspace::{sidebar::SidebarSide, AppState, Workspace}; @@ -67,6 +69,7 @@ actions!( ResetBufferFontSize, InstallCommandLineInterface, ResetDatabase, + CopySystemSpecsIntoClipboard ] ); @@ -245,6 +248,19 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { }, ); + cx.add_action( + |_: &mut Workspace, _: &CopySystemSpecsIntoClipboard, cx: &mut ViewContext| { + let system_specs = SystemSpecs::new(cx).to_string(); + let item = ClipboardItem::new(system_specs.clone()); + cx.prompt( + gpui::PromptLevel::Info, + &format!("Copied into clipboard:\n\n{system_specs}"), + &["OK"], + ); + cx.write_to_clipboard(item); + }, + ); + activity_indicator::init(cx); call::init(app_state.client.clone(), app_state.user_store.clone(), cx); settings::KeymapFileContent::load_defaults(cx);