Fix version for feedback-related commands
Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
d9278f7416
commit
248161aa63
6 changed files with 88 additions and 59 deletions
|
@ -2,15 +2,15 @@ mod update_notification;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN};
|
use client::{http::HttpClient, ZED_SECRET_CLIENT_TOKEN};
|
||||||
|
use client::{ZED_APP_PATH, ZED_APP_VERSION};
|
||||||
use db::kvp::KEY_VALUE_STORE;
|
use db::kvp::KEY_VALUE_STORE;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
|
actions, platform::AppVersion, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle,
|
||||||
MutableAppContext, Task, WeakViewHandle,
|
MutableAppContext, Task, WeakViewHandle,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use smol::{fs::File, io::AsyncReadExt, process::Command};
|
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 update_notification::UpdateNotification;
|
||||||
use util::channel::ReleaseChannel;
|
use util::channel::ReleaseChannel;
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
@ -18,13 +18,6 @@ use workspace::Workspace;
|
||||||
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification";
|
const SHOULD_SHOW_UPDATE_NOTIFICATION_KEY: &str = "auto-updater-should-show-updated-notification";
|
||||||
const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);
|
const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref ZED_APP_VERSION: Option<AppVersion> = env::var("ZED_APP_VERSION")
|
|
||||||
.ok()
|
|
||||||
.and_then(|v| v.parse().ok());
|
|
||||||
pub static ref ZED_APP_PATH: Option<PathBuf> = env::var("ZED_APP_PATH").ok().map(PathBuf::from);
|
|
||||||
}
|
|
||||||
|
|
||||||
actions!(auto_update, [Check, DismissErrorMessage, ViewReleaseNotes]);
|
actions!(auto_update, [Check, DismissErrorMessage, ViewReleaseNotes]);
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
|
|
@ -15,7 +15,7 @@ use futures::{future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamEx
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
serde_json::{self, Value},
|
serde_json::{self, Value},
|
||||||
AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext,
|
AnyModelHandle, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, AppContext, AppVersion,
|
||||||
AsyncAppContext, Entity, ModelHandle, MutableAppContext, Task, View, ViewContext, ViewHandle,
|
AsyncAppContext, Entity, ModelHandle, MutableAppContext, Task, View, ViewContext, ViewHandle,
|
||||||
};
|
};
|
||||||
use http::HttpClient;
|
use http::HttpClient;
|
||||||
|
@ -55,6 +55,11 @@ lazy_static! {
|
||||||
pub static ref ADMIN_API_TOKEN: Option<String> = std::env::var("ZED_ADMIN_API_TOKEN")
|
pub static ref ADMIN_API_TOKEN: Option<String> = std::env::var("ZED_ADMIN_API_TOKEN")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| if s.is_empty() { None } else { Some(s) });
|
.and_then(|s| if s.is_empty() { None } else { Some(s) });
|
||||||
|
pub static ref ZED_APP_VERSION: Option<AppVersion> = std::env::var("ZED_APP_VERSION")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok());
|
||||||
|
pub static ref ZED_APP_PATH: Option<PathBuf> =
|
||||||
|
std::env::var("ZED_APP_PATH").ok().map(PathBuf::from);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894";
|
pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894";
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
pub mod feedback_editor;
|
pub mod feedback_editor;
|
||||||
mod system_specs;
|
mod system_specs;
|
||||||
use gpui::{actions, impl_actions, ClipboardItem, ViewContext};
|
use gpui::{actions, impl_actions, ClipboardItem, MutableAppContext, PromptLevel, ViewContext};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use system_specs::SystemSpecs;
|
use system_specs::SystemSpecs;
|
||||||
use workspace::{AppState, Workspace};
|
use workspace::{AppState, Workspace};
|
||||||
|
@ -16,23 +16,32 @@ impl_actions!(zed, [OpenBrowser]);
|
||||||
|
|
||||||
actions!(
|
actions!(
|
||||||
zed,
|
zed,
|
||||||
[CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature,]
|
[CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature]
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn init(app_state: Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
feedback_editor::init(app_state, cx);
|
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));
|
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(
|
cx.add_action(
|
||||||
|_: &mut Workspace, _: &CopySystemSpecsIntoClipboard, cx: &mut ViewContext<Workspace>| {
|
move |_: &mut Workspace,
|
||||||
let system_specs = SystemSpecs::new(cx).to_string();
|
_: &CopySystemSpecsIntoClipboard,
|
||||||
let item = ClipboardItem::new(system_specs.clone());
|
cx: &mut ViewContext<Workspace>| {
|
||||||
cx.prompt(
|
cx.prompt(
|
||||||
gpui::PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
&format!("Copied into clipboard:\n\n{system_specs}"),
|
&format!("Copied into clipboard:\n\n{system_specs_text}"),
|
||||||
&["OK"],
|
&["OK"],
|
||||||
);
|
);
|
||||||
|
let item = ClipboardItem::new(system_specs_text.clone());
|
||||||
cx.write_to_clipboard(item);
|
cx.write_to_clipboard(item);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -47,14 +56,9 @@ pub fn init(app_state: Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
||||||
);
|
);
|
||||||
|
|
||||||
cx.add_action(
|
cx.add_action(
|
||||||
|_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext<Workspace>| {
|
move |_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext<Workspace>| {
|
||||||
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)
|
|
||||||
);
|
|
||||||
cx.dispatch_action(OpenBrowser {
|
cx.dispatch_action(OpenBrowser {
|
||||||
url: url.into(),
|
url: url.clone().into(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::bail;
|
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 editor::{Anchor, Editor};
|
||||||
use futures::AsyncReadExt;
|
use futures::AsyncReadExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
|
@ -19,7 +19,6 @@ use isahc::Request;
|
||||||
use language::Buffer;
|
use language::Buffer;
|
||||||
use postage::prelude::Stream;
|
use postage::prelude::Stream;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
@ -31,11 +30,6 @@ use workspace::{
|
||||||
|
|
||||||
use crate::system_specs::SystemSpecs;
|
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<usize> = 10..=5000;
|
const FEEDBACK_CHAR_LIMIT: RangeInclusive<usize> = 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_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 =
|
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
||||||
|
@ -43,10 +37,10 @@ const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
||||||
|
|
||||||
actions!(feedback, [SubmitFeedback, GiveFeedback, DeployFeedback]);
|
actions!(feedback, [SubmitFeedback, GiveFeedback, DeployFeedback]);
|
||||||
|
|
||||||
pub fn init(app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
pub fn init(system_specs: SystemSpecs, app_state: Arc<AppState>, cx: &mut MutableAppContext) {
|
||||||
cx.add_action({
|
cx.add_action({
|
||||||
move |workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext<Workspace>| {
|
move |workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext<Workspace>| {
|
||||||
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)]
|
#[derive(Clone)]
|
||||||
struct FeedbackEditor {
|
struct FeedbackEditor {
|
||||||
|
system_specs: SystemSpecs,
|
||||||
editor: ViewHandle<Editor>,
|
editor: ViewHandle<Editor>,
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FeedbackEditor {
|
impl FeedbackEditor {
|
||||||
fn new(
|
fn new(
|
||||||
|
system_specs: SystemSpecs,
|
||||||
project: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer: ModelHandle<Buffer>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
|
@ -117,7 +113,11 @@ impl FeedbackEditor {
|
||||||
cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone()))
|
cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone()))
|
||||||
.detach();
|
.detach();
|
||||||
|
|
||||||
Self { editor, project }
|
Self {
|
||||||
|
system_specs: system_specs.clone(),
|
||||||
|
editor,
|
||||||
|
project,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_save(
|
fn handle_save(
|
||||||
|
@ -155,7 +155,7 @@ impl FeedbackEditor {
|
||||||
let this = cx.handle();
|
let this = cx.handle();
|
||||||
let client = cx.global::<Arc<Client>>().clone();
|
let client = cx.global::<Arc<Client>>().clone();
|
||||||
let feedback_text = self.editor.read(cx).text(cx);
|
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 {
|
cx.spawn(|_, mut cx| async move {
|
||||||
let answer = answer.recv().await;
|
let answer = answer.recv().await;
|
||||||
|
@ -229,6 +229,7 @@ impl FeedbackEditor {
|
||||||
|
|
||||||
impl FeedbackEditor {
|
impl FeedbackEditor {
|
||||||
pub fn deploy(
|
pub fn deploy(
|
||||||
|
system_specs: SystemSpecs,
|
||||||
workspace: &mut Workspace,
|
workspace: &mut Workspace,
|
||||||
app_state: Arc<AppState>,
|
app_state: Arc<AppState>,
|
||||||
cx: &mut ViewContext<Workspace>,
|
cx: &mut ViewContext<Workspace>,
|
||||||
|
@ -242,7 +243,8 @@ impl FeedbackEditor {
|
||||||
project.create_buffer("", markdown_language, cx)
|
project.create_buffer("", markdown_language, cx)
|
||||||
})
|
})
|
||||||
.expect("creating buffers on a local workspace always succeeds");
|
.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);
|
workspace.add_item(Box::new(feedback_editor), cx);
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
@ -340,7 +342,12 @@ impl Item for FeedbackEditor {
|
||||||
.as_singleton()
|
.as_singleton()
|
||||||
.expect("Feedback buffer is only ever 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> {
|
fn serialized_item_kind() -> Option<&'static str> {
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
use std::{env, fmt::Display};
|
use client::ZED_APP_VERSION;
|
||||||
|
use gpui::{AppContext, AppVersion};
|
||||||
use gpui::AppContext;
|
|
||||||
use human_bytes::human_bytes;
|
use human_bytes::human_bytes;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use std::{env, fmt::Display};
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
use util::channel::ReleaseChannel;
|
use util::channel::ReleaseChannel;
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct SystemSpecs {
|
pub struct SystemSpecs {
|
||||||
app_version: &'static str,
|
#[serde(serialize_with = "serialize_app_version")]
|
||||||
|
app_version: Option<AppVersion>,
|
||||||
release_channel: &'static str,
|
release_channel: &'static str,
|
||||||
os_name: &'static str,
|
os_name: &'static str,
|
||||||
os_version: Option<String>,
|
os_version: Option<String>,
|
||||||
|
@ -19,18 +20,24 @@ pub struct SystemSpecs {
|
||||||
impl SystemSpecs {
|
impl SystemSpecs {
|
||||||
pub fn new(cx: &AppContext) -> Self {
|
pub fn new(cx: &AppContext) -> Self {
|
||||||
let platform = cx.platform();
|
let platform = cx.platform();
|
||||||
|
let app_version = ZED_APP_VERSION.or_else(|| platform.app_version().ok());
|
||||||
|
let release_channel = cx.global::<ReleaseChannel>().dev_name();
|
||||||
|
let os_name = platform.os_name();
|
||||||
let system = System::new_all();
|
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 {
|
SystemSpecs {
|
||||||
app_version: env!("CARGO_PKG_VERSION"),
|
app_version,
|
||||||
release_channel: cx.global::<ReleaseChannel>().dev_name(),
|
release_channel,
|
||||||
os_name: platform.os_name(),
|
os_name,
|
||||||
os_version: platform
|
os_version,
|
||||||
.os_version()
|
memory,
|
||||||
.ok()
|
architecture,
|
||||||
.map(|os_version| os_version.to_string()),
|
|
||||||
memory: system.total_memory(),
|
|
||||||
architecture: env::consts::ARCH,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,14 +48,28 @@ impl Display for SystemSpecs {
|
||||||
Some(os_version) => format!("OS: {} {}", self.os_name, os_version),
|
Some(os_version) => format!("OS: {} {}", self.os_name, os_version),
|
||||||
None => format!("OS: {}", self.os_name),
|
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 = [
|
let system_specs = [
|
||||||
format!("Zed: v{} ({})", self.app_version, self.release_channel),
|
app_version_information,
|
||||||
os_information,
|
Some(os_information),
|
||||||
format!("Memory: {}", human_bytes(self.memory as f64)),
|
Some(format!("Memory: {}", human_bytes(self.memory as f64))),
|
||||||
format!("Architecture: {}", self.architecture),
|
Some(format!("Architecture: {}", self.architecture)),
|
||||||
]
|
]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.collect::<Vec<String>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
write!(f, "{system_specs}")
|
write!(f, "{system_specs}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_app_version<S>(version: &Option<AppVersion>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
version.map(|v| v.to_string()).serialize(serializer)
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use assets::Assets;
|
use assets::Assets;
|
||||||
use auto_update::ZED_APP_VERSION;
|
|
||||||
use backtrace::Backtrace;
|
use backtrace::Backtrace;
|
||||||
use cli::{
|
use cli::{
|
||||||
ipc::{self, IpcSender},
|
ipc::{self, IpcSender},
|
||||||
|
@ -12,7 +11,7 @@ use cli::{
|
||||||
use client::{
|
use client::{
|
||||||
self,
|
self,
|
||||||
http::{self, HttpClient},
|
http::{self, HttpClient},
|
||||||
UserStore, ZED_SECRET_CLIENT_TOKEN,
|
UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::{
|
use futures::{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue