diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index d3fcc36c2f..19f4652005 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -2,15 +2,15 @@ mod update_notification; use anyhow::{anyhow, Context, Result}; use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN}; +use client::{ZED_APP_PATH, ZED_APP_VERSION}; use db::kvp::KEY_VALUE_STORE; use gpui::{ actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakViewHandle, }; -use lazy_static::lazy_static; use serde::Deserialize; use smol::{fs::File, io::AsyncReadExt, process::Command}; -use std::{env, ffi::OsString, path::PathBuf, sync::Arc, time::Duration}; +use std::{ffi::OsString, sync::Arc, time::Duration}; use update_notification::UpdateNotification; use util::channel::ReleaseChannel; use workspace::Workspace; @@ -18,13 +18,6 @@ use workspace::Workspace; const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification"; const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60); -lazy_static! { - pub static ref ZED_APP_VERSION: Option = env::var("ZED_APP_VERSION") - .ok() - .and_then(|v| v.parse().ok()); - pub static ref ZED_APP_PATH: Option = env::var("ZED_APP_PATH").ok().map(PathBuf::from); -} - actions!(auto_update, [Check, DismissErrorMessage, ViewReleaseNotes]); #[derive(Clone, Copy, PartialEq, Eq)] diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 4d129fab2e..08a3223eb0 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -15,7 +15,7 @@ use futures::{future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamEx use gpui::{ actions, serde_json::{self, Value}, - AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, + AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, AppVersion, AsyncAppContext, Entity, ModelHandle, MutableAppContext, Task, View, ViewContext, ViewHandle, }; use http::HttpClient; @@ -55,6 +55,11 @@ lazy_static! { pub static ref ADMIN_API_TOKEN: Option = std::env::var("ZED_ADMIN_API_TOKEN") .ok() .and_then(|s| if s.is_empty() { None } else { Some(s) }); + pub static ref ZED_APP_VERSION: Option = std::env::var("ZED_APP_VERSION") + .ok() + .and_then(|v| v.parse().ok()); + pub static ref ZED_APP_PATH: Option = + std::env::var("ZED_APP_PATH").ok().map(PathBuf::from); } pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894"; diff --git a/crates/feedback/src/feedback.rs b/crates/feedback/src/feedback.rs index f47f95d4f3..680155b657 100644 --- a/crates/feedback/src/feedback.rs +++ b/crates/feedback/src/feedback.rs @@ -2,7 +2,7 @@ use std::sync::Arc; pub mod feedback_editor; mod system_specs; -use gpui::{actions, impl_actions, ClipboardItem, ViewContext}; +use gpui::{actions, impl_actions, ClipboardItem, MutableAppContext, PromptLevel, ViewContext}; use serde::Deserialize; use system_specs::SystemSpecs; use workspace::{AppState, Workspace}; @@ -16,23 +16,32 @@ impl_actions!(zed, [OpenBrowser]); actions!( zed, - [CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature,] + [CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature] ); -pub fn init(app_state: Arc, cx: &mut gpui::MutableAppContext) { - feedback_editor::init(app_state, cx); +pub fn init(app_state: Arc, cx: &mut MutableAppContext) { + let system_specs = SystemSpecs::new(&cx); + let system_specs_text = system_specs.to_string(); + + feedback_editor::init(system_specs, app_state, cx); cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url)); + let url = format!( + "https://github.com/zed-industries/feedback/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}", + urlencoding::encode(&system_specs_text) + ); + cx.add_action( - |_: &mut Workspace, _: &CopySystemSpecsIntoClipboard, cx: &mut ViewContext| { - let system_specs = SystemSpecs::new(cx).to_string(); - let item = ClipboardItem::new(system_specs.clone()); + move |_: &mut Workspace, + _: &CopySystemSpecsIntoClipboard, + cx: &mut ViewContext| { cx.prompt( - gpui::PromptLevel::Info, - &format!("Copied into clipboard:\n\n{system_specs}"), + PromptLevel::Info, + &format!("Copied into clipboard:\n\n{system_specs_text}"), &["OK"], ); + let item = ClipboardItem::new(system_specs_text.clone()); cx.write_to_clipboard(item); }, ); @@ -47,14 +56,9 @@ pub fn init(app_state: Arc, cx: &mut gpui::MutableAppContext) { ); cx.add_action( - |_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext| { - let system_specs_text = SystemSpecs::new(cx).to_string(); - let url = format!( - "https://github.com/zed-industries/feedback/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}", - urlencoding::encode(&system_specs_text) - ); + move |_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext| { cx.dispatch_action(OpenBrowser { - url: url.into(), + url: url.clone().into(), }); }, ); diff --git a/crates/feedback/src/feedback_editor.rs b/crates/feedback/src/feedback_editor.rs index a4c10d8fc2..56c1def935 100644 --- a/crates/feedback/src/feedback_editor.rs +++ b/crates/feedback/src/feedback_editor.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::bail; -use client::{Client, ZED_SECRET_CLIENT_TOKEN}; +use client::{Client, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL}; use editor::{Anchor, Editor}; use futures::AsyncReadExt; use gpui::{ @@ -19,7 +19,6 @@ use isahc::Request; use language::Buffer; use postage::prelude::Stream; -use lazy_static::lazy_static; use project::Project; use serde::Serialize; use settings::Settings; @@ -31,11 +30,6 @@ use workspace::{ use crate::system_specs::SystemSpecs; -lazy_static! { - pub static ref ZED_SERVER_URL: String = - std::env::var("ZED_SERVER_URL").unwrap_or_else(|_| "https://zed.dev".to_string()); -} - const FEEDBACK_CHAR_LIMIT: RangeInclusive = 10..=5000; const FEEDBACK_PLACEHOLDER_TEXT: &str = "Thanks for spending time with Zed. Enter your feedback here as Markdown. Save the tab to submit your feedback."; const FEEDBACK_SUBMISSION_ERROR_TEXT: &str = @@ -43,10 +37,10 @@ const FEEDBACK_SUBMISSION_ERROR_TEXT: &str = actions!(feedback, [SubmitFeedback, GiveFeedback, DeployFeedback]); -pub fn init(app_state: Arc, cx: &mut MutableAppContext) { +pub fn init(system_specs: SystemSpecs, app_state: Arc, cx: &mut MutableAppContext) { cx.add_action({ move |workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext| { - FeedbackEditor::deploy(workspace, app_state.clone(), cx); + FeedbackEditor::deploy(system_specs.clone(), workspace, app_state.clone(), cx); } }); } @@ -97,12 +91,14 @@ struct FeedbackRequestBody<'a> { #[derive(Clone)] struct FeedbackEditor { + system_specs: SystemSpecs, editor: ViewHandle, project: ModelHandle, } impl FeedbackEditor { fn new( + system_specs: SystemSpecs, project: ModelHandle, buffer: ModelHandle, cx: &mut ViewContext, @@ -117,7 +113,11 @@ impl FeedbackEditor { cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone())) .detach(); - Self { editor, project } + Self { + system_specs: system_specs.clone(), + editor, + project, + } } fn handle_save( @@ -155,7 +155,7 @@ impl FeedbackEditor { let this = cx.handle(); let client = cx.global::>().clone(); let feedback_text = self.editor.read(cx).text(cx); - let specs = SystemSpecs::new(cx); + let specs = self.system_specs.clone(); cx.spawn(|_, mut cx| async move { let answer = answer.recv().await; @@ -229,6 +229,7 @@ impl FeedbackEditor { impl FeedbackEditor { pub fn deploy( + system_specs: SystemSpecs, workspace: &mut Workspace, app_state: Arc, cx: &mut ViewContext, @@ -242,7 +243,8 @@ impl FeedbackEditor { project.create_buffer("", markdown_language, cx) }) .expect("creating buffers on a local workspace always succeeds"); - let feedback_editor = cx.add_view(|cx| FeedbackEditor::new(project, buffer, cx)); + let feedback_editor = + cx.add_view(|cx| FeedbackEditor::new(system_specs, project, buffer, cx)); workspace.add_item(Box::new(feedback_editor), cx); }) .detach(); @@ -340,7 +342,12 @@ impl Item for FeedbackEditor { .as_singleton() .expect("Feedback buffer is only ever singleton"); - Some(Self::new(self.project.clone(), buffer.clone(), cx)) + Some(Self::new( + self.system_specs.clone(), + self.project.clone(), + buffer.clone(), + cx, + )) } fn serialized_item_kind() -> Option<&'static str> { diff --git a/crates/feedback/src/system_specs.rs b/crates/feedback/src/system_specs.rs index 17e51a6815..f20561826e 100644 --- a/crates/feedback/src/system_specs.rs +++ b/crates/feedback/src/system_specs.rs @@ -1,14 +1,15 @@ -use std::{env, fmt::Display}; - -use gpui::AppContext; +use client::ZED_APP_VERSION; +use gpui::{AppContext, AppVersion}; use human_bytes::human_bytes; use serde::Serialize; +use std::{env, fmt::Display}; use sysinfo::{System, SystemExt}; use util::channel::ReleaseChannel; -#[derive(Debug, Serialize)] +#[derive(Clone, Debug, Serialize)] pub struct SystemSpecs { - app_version: &'static str, + #[serde(serialize_with = "serialize_app_version")] + app_version: Option, release_channel: &'static str, os_name: &'static str, os_version: Option, @@ -19,18 +20,24 @@ pub struct SystemSpecs { impl SystemSpecs { pub fn new(cx: &AppContext) -> Self { let platform = cx.platform(); + let app_version = ZED_APP_VERSION.or_else(|| platform.app_version().ok()); + let release_channel = cx.global::().dev_name(); + let os_name = platform.os_name(); let system = System::new_all(); + let memory = system.total_memory(); + let architecture = env::consts::ARCH; + let os_version = platform + .os_version() + .ok() + .map(|os_version| os_version.to_string()); SystemSpecs { - app_version: env!("CARGO_PKG_VERSION"), - release_channel: cx.global::().dev_name(), - os_name: platform.os_name(), - os_version: platform - .os_version() - .ok() - .map(|os_version| os_version.to_string()), - memory: system.total_memory(), - architecture: env::consts::ARCH, + app_version, + release_channel, + os_name, + os_version, + memory, + architecture, } } } @@ -41,14 +48,28 @@ impl Display for SystemSpecs { Some(os_version) => format!("OS: {} {}", self.os_name, os_version), None => format!("OS: {}", self.os_name), }; + let app_version_information = self + .app_version + .as_ref() + .map(|app_version| format!("Zed: v{} ({})", app_version, self.release_channel)); let system_specs = [ - format!("Zed: v{} ({})", self.app_version, self.release_channel), - os_information, - format!("Memory: {}", human_bytes(self.memory as f64)), - format!("Architecture: {}", self.architecture), + app_version_information, + Some(os_information), + Some(format!("Memory: {}", human_bytes(self.memory as f64))), + Some(format!("Architecture: {}", self.architecture)), ] + .into_iter() + .flatten() + .collect::>() .join("\n"); write!(f, "{system_specs}") } } + +fn serialize_app_version(version: &Option, serializer: S) -> Result +where + S: serde::Serializer, +{ + version.map(|v| v.to_string()).serialize(serializer) +} diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 98d2aa879f..77fd516b86 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -3,7 +3,6 @@ use anyhow::{anyhow, Context, Result}; use assets::Assets; -use auto_update::ZED_APP_VERSION; use backtrace::Backtrace; use cli::{ ipc::{self, IpcSender}, @@ -12,7 +11,7 @@ use cli::{ use client::{ self, http::{self, HttpClient}, - UserStore, ZED_SECRET_CLIENT_TOKEN, + UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN, }; use futures::{