Merge pull request #1989 from zed-industries/add-command-to-copy-system-information-to-the-clipboard

add command to copy system information to the clipboard
This commit is contained in:
Joseph T. Lyons 2022-12-22 14:31:23 -05:00 committed by GitHub
commit 96ac650465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 6 deletions

View File

@ -95,7 +95,7 @@ actions!(
ToggleLeftSidebar,
ToggleRightSidebar,
NewTerminal,
NewSearch,
NewSearch
]
);

View File

@ -339,10 +339,8 @@ pub fn menus() -> Vec<Menu<'static>> {
},
MenuItem::Separator,
MenuItem::Action {
name: "Documentation",
action: Box::new(crate::OpenBrowser {
url: "https://zed.dev/docs".into(),
}),
name: "Copy System Specs Into Clipboard",
action: Box::new(crate::CopySystemSpecsIntoClipboard),
},
MenuItem::Action {
name: "Give Feedback",
@ -350,6 +348,13 @@ pub fn menus() -> Vec<Menu<'static>> {
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 {

View File

@ -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<String>,
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::<ReleaseChannel>().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}")
}
}

View File

@ -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<AppState>, cx: &mut gpui::MutableAppContext) {
},
);
cx.add_action(
|_: &mut Workspace, _: &CopySystemSpecsIntoClipboard, cx: &mut ViewContext<Workspace>| {
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);