Detailed changes
@@ -3542,5 +3542,5 @@ fn report_assistant_event(
.default_open_ai_model
.clone();
- telemetry.report_assistant_event(conversation_id, assistant_kind, model.full_name(), cx)
+ telemetry.report_assistant_event(conversation_id, assistant_kind, model.full_name())
}
@@ -310,14 +310,14 @@ impl ActiveCall {
})
}
- pub fn decline_incoming(&mut self, cx: &mut ModelContext<Self>) -> Result<()> {
+ pub fn decline_incoming(&mut self, _: &mut ModelContext<Self>) -> Result<()> {
let call = self
.incoming_call
.0
.borrow_mut()
.take()
.ok_or_else(|| anyhow!("no incoming call"))?;
- report_call_event_for_room("decline incoming", call.room_id, None, &self.client, cx);
+ report_call_event_for_room("decline incoming", call.room_id, None, &self.client);
self.client.send(proto::DeclineCall {
room_id: call.room_id,
})?;
@@ -467,7 +467,7 @@ impl ActiveCall {
pub fn report_call_event(&self, operation: &'static str, cx: &mut AppContext) {
if let Some(room) = self.room() {
let room = room.read(cx);
- report_call_event_for_room(operation, room.id(), room.channel_id(), &self.client, cx);
+ report_call_event_for_room(operation, room.id(), room.channel_id(), &self.client);
}
}
}
@@ -477,11 +477,10 @@ pub fn report_call_event_for_room(
room_id: u64,
channel_id: Option<u64>,
client: &Arc<Client>,
- cx: &mut AppContext,
) {
let telemetry = client.telemetry();
- telemetry.report_call_event(operation, Some(room_id), channel_id, cx)
+ telemetry.report_call_event(operation, Some(room_id), channel_id)
}
pub fn report_call_event_for_channel(
@@ -494,12 +493,7 @@ pub fn report_call_event_for_channel(
let telemetry = client.telemetry();
- telemetry.report_call_event(
- operation,
- room.map(|r| r.read(cx).id()),
- Some(channel_id),
- cx,
- )
+ telemetry.report_call_event(operation, room.map(|r| r.read(cx).id()), Some(channel_id))
}
#[cfg(test)]
@@ -343,12 +343,13 @@ async fn test_channel_messages(cx: &mut TestAppContext) {
}
fn init_test(cx: &mut AppContext) -> Model<ChannelStore> {
+ let settings_store = SettingsStore::test(cx);
+ cx.set_global(settings_store);
+
let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx);
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
- let settings_store = SettingsStore::test(cx);
- cx.set_global(settings_store);
client::init(&client, cx);
crate::init(&client, user_store, cx);
@@ -45,7 +45,7 @@ use util::http::HttpClient;
use util::{ResultExt, TryFutureExt};
pub use rpc::*;
-pub use telemetry::ClickhouseEvent;
+pub use telemetry::Event;
pub use user::*;
lazy_static! {
@@ -501,8 +501,7 @@ impl Client {
}));
}
Status::SignedOut | Status::UpgradeRequired => {
- cx.update(|cx| self.telemetry.set_authenticated_user_info(None, false, cx))
- .log_err();
+ self.telemetry.set_authenticated_user_info(None, false);
state._reconnect_task.take();
}
_ => {}
@@ -1405,11 +1404,13 @@ mod tests {
use gpui::{BackgroundExecutor, Context, TestAppContext};
use parking_lot::Mutex;
+ use settings::SettingsStore;
use std::future;
use util::http::FakeHttpClient;
#[gpui::test(iterations = 10)]
async fn test_reconnection(cx: &mut TestAppContext) {
+ init_test(cx);
let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await;
@@ -1444,6 +1445,7 @@ mod tests {
#[gpui::test(iterations = 10)]
async fn test_connection_timeout(executor: BackgroundExecutor, cx: &mut TestAppContext) {
+ init_test(cx);
let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let mut status = client.status();
@@ -1515,6 +1517,7 @@ mod tests {
cx: &mut TestAppContext,
executor: BackgroundExecutor,
) {
+ init_test(cx);
let auth_count = Arc::new(Mutex::new(0));
let dropped_auth_count = Arc::new(Mutex::new(0));
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
@@ -1563,6 +1566,7 @@ mod tests {
#[gpui::test]
async fn test_subscribing_to_entity(cx: &mut TestAppContext) {
+ init_test(cx);
let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await;
@@ -1616,6 +1620,7 @@ mod tests {
#[gpui::test]
async fn test_subscribing_after_dropping_subscription(cx: &mut TestAppContext) {
+ init_test(cx);
let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await;
@@ -1644,6 +1649,7 @@ mod tests {
#[gpui::test]
async fn test_dropping_subscription_in_handler(cx: &mut TestAppContext) {
+ init_test(cx);
let user_id = 5;
let client = cx.update(|cx| Client::new(FakeHttpClient::with_404_response(), cx));
let server = FakeServer::for_client(user_id, &client, cx).await;
@@ -1672,4 +1678,11 @@ mod tests {
id: usize,
subscription: Option<Subscription>,
}
+
+ fn init_test(cx: &mut TestAppContext) {
+ cx.update(|cx| {
+ let settings_store = SettingsStore::test(cx);
+ cx.set_global(settings_store);
+ });
+ }
}
@@ -5,7 +5,7 @@ use gpui::{serde_json, AppContext, AppMetadata, BackgroundExecutor, Task};
use lazy_static::lazy_static;
use parking_lot::Mutex;
use serde::Serialize;
-use settings::Settings;
+use settings::{Settings, SettingsStore};
use std::{env, io::Write, mem, path::PathBuf, sync::Arc, time::Duration};
use sysinfo::{
CpuRefreshKind, Pid, PidExt, ProcessExt, ProcessRefreshKind, RefreshKind, System, SystemExt,
@@ -17,32 +17,32 @@ use util::{channel::ReleaseChannel, TryFutureExt};
pub struct Telemetry {
http_client: Arc<dyn HttpClient>,
executor: BackgroundExecutor,
- state: Mutex<TelemetryState>,
+ state: Arc<Mutex<TelemetryState>>,
}
struct TelemetryState {
+ settings: TelemetrySettings,
metrics_id: Option<Arc<str>>, // Per logged-in user
installation_id: Option<Arc<str>>, // Per app installation (different for dev, nightly, preview, and stable)
session_id: Option<Arc<str>>, // Per app launch
release_channel: Option<&'static str>,
app_metadata: AppMetadata,
architecture: &'static str,
- clickhouse_events_queue: Vec<ClickhouseEventWrapper>,
- flush_clickhouse_events_task: Option<Task<()>>,
+ events_queue: Vec<EventWrapper>,
+ flush_events_task: Option<Task<()>>,
log_file: Option<NamedTempFile>,
is_staff: Option<bool>,
first_event_datetime: Option<DateTime<Utc>>,
}
-const CLICKHOUSE_EVENTS_URL_PATH: &'static str = "/api/events";
+const EVENTS_URL_PATH: &'static str = "/api/events";
lazy_static! {
- static ref CLICKHOUSE_EVENTS_URL: String =
- format!("{}{}", *ZED_SERVER_URL, CLICKHOUSE_EVENTS_URL_PATH);
+ static ref EVENTS_URL: String = format!("{}{}", *ZED_SERVER_URL, EVENTS_URL_PATH);
}
#[derive(Serialize, Debug)]
-struct ClickhouseEventRequestBody {
+struct EventRequestBody {
token: &'static str,
installation_id: Option<Arc<str>>,
session_id: Option<Arc<str>>,
@@ -52,14 +52,14 @@ struct ClickhouseEventRequestBody {
os_version: Option<String>,
architecture: &'static str,
release_channel: Option<&'static str>,
- events: Vec<ClickhouseEventWrapper>,
+ events: Vec<EventWrapper>,
}
#[derive(Serialize, Debug)]
-struct ClickhouseEventWrapper {
+struct EventWrapper {
signed_in: bool,
#[serde(flatten)]
- event: ClickhouseEvent,
+ event: Event,
}
#[derive(Serialize, Debug)]
@@ -71,7 +71,7 @@ pub enum AssistantKind {
#[derive(Serialize, Debug)]
#[serde(tag = "type")]
-pub enum ClickhouseEvent {
+pub enum Event {
Editor {
operation: &'static str,
file_extension: Option<String>,
@@ -139,45 +139,61 @@ impl Telemetry {
None
};
+ TelemetrySettings::register(cx);
+
+ let state = Arc::new(Mutex::new(TelemetryState {
+ settings: TelemetrySettings::get_global(cx).clone(),
+ app_metadata: cx.app_metadata(),
+ architecture: env::consts::ARCH,
+ release_channel,
+ installation_id: None,
+ metrics_id: None,
+ session_id: None,
+ events_queue: Default::default(),
+ flush_events_task: Default::default(),
+ log_file: None,
+ is_staff: None,
+ first_event_datetime: None,
+ }));
+
+ cx.observe_global::<SettingsStore>({
+ let state = state.clone();
+
+ move |cx| {
+ let mut state = state.lock();
+ state.settings = TelemetrySettings::get_global(cx).clone();
+ }
+ })
+ .detach();
+
// TODO: Replace all hardware stuff with nested SystemSpecs json
let this = Arc::new(Self {
http_client: client,
executor: cx.background_executor().clone(),
- state: Mutex::new(TelemetryState {
- app_metadata: cx.app_metadata(),
- architecture: env::consts::ARCH,
- release_channel,
- installation_id: None,
- metrics_id: None,
- session_id: None,
- clickhouse_events_queue: Default::default(),
- flush_clickhouse_events_task: Default::default(),
- log_file: None,
- is_staff: None,
- first_event_datetime: None,
- }),
+ state,
});
// We should only ever have one instance of Telemetry, leak the subscription to keep it alive
// rather than store in TelemetryState, complicating spawn as subscriptions are not Send
std::mem::forget(cx.on_app_quit({
let this = this.clone();
- move |cx| this.shutdown_telemetry(cx)
+ move |_| this.shutdown_telemetry()
}));
this
}
#[cfg(any(test, feature = "test-support"))]
- fn shutdown_telemetry(self: &Arc<Self>, _: &mut AppContext) -> impl Future<Output = ()> {
+ fn shutdown_telemetry(self: &Arc<Self>) -> impl Future<Output = ()> {
Task::ready(())
}
// Skip calling this function in tests.
// TestAppContext ends up calling this function on shutdown and it panics when trying to find the TelemetrySettings
#[cfg(not(any(test, feature = "test-support")))]
- fn shutdown_telemetry(self: &Arc<Self>, cx: &mut AppContext) -> impl Future<Output = ()> {
- self.report_app_event("close", true, cx);
+ fn shutdown_telemetry(self: &Arc<Self>) -> impl Future<Output = ()> {
+ self.report_app_event("close");
+ self.flush_events();
Task::ready(())
}
@@ -197,7 +213,7 @@ impl Telemetry {
drop(state);
let this = self.clone();
- cx.spawn(|cx| async move {
+ cx.spawn(|_| async move {
// Avoiding calling `System::new_all()`, as there have been crashes related to it
let refresh_kind = RefreshKind::new()
.with_memory() // For memory usage
@@ -226,11 +242,8 @@ impl Telemetry {
return;
};
- cx.update(|cx| {
- this.report_memory_event(process.memory(), process.virtual_memory(), cx);
- this.report_cpu_event(process.cpu_usage(), system.cpus().len() as u32, cx);
- })
- .ok();
+ this.report_memory_event(process.memory(), process.virtual_memory());
+ this.report_cpu_event(process.cpu_usage(), system.cpus().len() as u32);
}
})
.detach();
@@ -240,13 +253,13 @@ impl Telemetry {
self: &Arc<Self>,
metrics_id: Option<String>,
is_staff: bool,
- cx: &AppContext,
) {
- if !TelemetrySettings::get_global(cx).metrics {
+ let mut state = self.state.lock();
+
+ if !state.settings.metrics {
return;
}
- let mut state = self.state.lock();
let metrics_id: Option<Arc<str>> = metrics_id.map(|id| id.into());
state.metrics_id = metrics_id.clone();
state.is_staff = Some(is_staff);
@@ -260,9 +273,8 @@ impl Telemetry {
operation: &'static str,
copilot_enabled: bool,
copilot_enabled_for_language: bool,
- cx: &AppContext,
) {
- let event = ClickhouseEvent::Editor {
+ let event = Event::Editor {
file_extension,
vim_mode,
operation,
@@ -271,7 +283,7 @@ impl Telemetry {
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
pub fn report_copilot_event(
@@ -279,16 +291,15 @@ impl Telemetry {
suggestion_id: Option<String>,
suggestion_accepted: bool,
file_extension: Option<String>,
- cx: &AppContext,
) {
- let event = ClickhouseEvent::Copilot {
+ let event = Event::Copilot {
suggestion_id,
suggestion_accepted,
file_extension,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
pub fn report_assistant_event(
@@ -296,16 +307,15 @@ impl Telemetry {
conversation_id: Option<String>,
kind: AssistantKind,
model: &'static str,
- cx: &AppContext,
) {
- let event = ClickhouseEvent::Assistant {
+ let event = Event::Assistant {
conversation_id,
kind,
model,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
pub fn report_call_event(
@@ -313,75 +323,58 @@ impl Telemetry {
operation: &'static str,
room_id: Option<u64>,
channel_id: Option<u64>,
- cx: &AppContext,
) {
- let event = ClickhouseEvent::Call {
+ let event = Event::Call {
operation,
room_id,
channel_id,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
- pub fn report_cpu_event(
- self: &Arc<Self>,
- usage_as_percentage: f32,
- core_count: u32,
- cx: &AppContext,
- ) {
- let event = ClickhouseEvent::Cpu {
+ pub fn report_cpu_event(self: &Arc<Self>, usage_as_percentage: f32, core_count: u32) {
+ let event = Event::Cpu {
usage_as_percentage,
core_count,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
pub fn report_memory_event(
self: &Arc<Self>,
memory_in_bytes: u64,
virtual_memory_in_bytes: u64,
- cx: &AppContext,
) {
- let event = ClickhouseEvent::Memory {
+ let event = Event::Memory {
memory_in_bytes,
virtual_memory_in_bytes,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
- pub fn report_app_event(
- self: &Arc<Self>,
- operation: &'static str,
- immediate_flush: bool,
- cx: &AppContext,
- ) {
- let event = ClickhouseEvent::App {
+ pub fn report_app_event(self: &Arc<Self>, operation: &'static str) {
+ let event = Event::App {
operation,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, immediate_flush, cx)
+ self.report_event(event)
}
- pub fn report_setting_event(
- self: &Arc<Self>,
- setting: &'static str,
- value: String,
- cx: &AppContext,
- ) {
- let event = ClickhouseEvent::Setting {
+ pub fn report_setting_event(self: &Arc<Self>, setting: &'static str, value: String) {
+ let event = Event::Setting {
setting,
value,
milliseconds_since_first_event: self.milliseconds_since_first_event(),
};
- self.report_clickhouse_event(event, false, cx)
+ self.report_event(event)
}
fn milliseconds_since_first_event(&self) -> i64 {
@@ -398,32 +391,26 @@ impl Telemetry {
}
}
- fn report_clickhouse_event(
- self: &Arc<Self>,
- event: ClickhouseEvent,
- immediate_flush: bool,
- cx: &AppContext,
- ) {
- if !TelemetrySettings::get_global(cx).metrics {
+ fn report_event(self: &Arc<Self>, event: Event) {
+ let mut state = self.state.lock();
+
+ if !state.settings.metrics {
return;
}
- let mut state = self.state.lock();
let signed_in = state.metrics_id.is_some();
- state
- .clickhouse_events_queue
- .push(ClickhouseEventWrapper { signed_in, event });
+ state.events_queue.push(EventWrapper { signed_in, event });
if state.installation_id.is_some() {
- if immediate_flush || state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {
+ if state.events_queue.len() >= MAX_QUEUE_LEN {
drop(state);
- self.flush_clickhouse_events();
+ self.flush_events();
} else {
let this = self.clone();
let executor = self.executor.clone();
- state.flush_clickhouse_events_task = Some(self.executor.spawn(async move {
+ state.flush_events_task = Some(self.executor.spawn(async move {
executor.timer(DEBOUNCE_INTERVAL).await;
- this.flush_clickhouse_events();
+ this.flush_events();
}));
}
}
@@ -441,11 +428,11 @@ impl Telemetry {
self.state.lock().is_staff
}
- fn flush_clickhouse_events(self: &Arc<Self>) {
+ pub fn flush_events(self: &Arc<Self>) {
let mut state = self.state.lock();
state.first_event_datetime = None;
- let mut events = mem::take(&mut state.clickhouse_events_queue);
- state.flush_clickhouse_events_task.take();
+ let mut events = mem::take(&mut state.events_queue);
+ state.flush_events_task.take();
drop(state);
let this = self.clone();
@@ -466,7 +453,7 @@ impl Telemetry {
{
let state = this.state.lock();
- let request_body = ClickhouseEventRequestBody {
+ let request_body = EventRequestBody {
token: ZED_SECRET_CLIENT_TOKEN,
installation_id: state.installation_id.clone(),
session_id: state.session_id.clone(),
@@ -490,7 +477,7 @@ impl Telemetry {
}
this.http_client
- .post_json(CLICKHOUSE_EVENTS_URL.as_str(), json_bytes.into())
+ .post_json(EVENTS_URL.as_str(), json_bytes.into())
.await?;
anyhow::Ok(())
}
@@ -164,7 +164,6 @@ impl UserStore {
client.telemetry.set_authenticated_user_info(
Some(info.metrics_id.clone()),
info.staff,
- cx,
)
}
})?;
@@ -271,11 +271,12 @@ mod tests {
fn init_test(cx: &mut TestAppContext) -> Arc<LanguageRegistry> {
cx.update(|cx| {
+ let settings = SettingsStore::test(cx);
+ cx.set_global(settings);
+
let http = FakeHttpClient::with_404_response();
let client = Client::new(http.clone(), cx);
let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
- let settings = SettingsStore::test(cx);
- cx.set_global(settings);
theme::init(theme::LoadThemes::JustBase, cx);
language::init(cx);
editor::init(cx);
@@ -58,7 +58,6 @@ pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
room.id(),
room.channel_id(),
&client,
- cx,
);
Task::ready(room.unshare_screen(cx))
} else {
@@ -67,7 +66,6 @@ pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {
room.id(),
room.channel_id(),
&client,
- cx,
);
room.share_screen(cx)
}
@@ -86,7 +84,7 @@ pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {
} else {
"disable microphone"
};
- report_call_event_for_room(operation, room.id(), room.channel_id(), &client, cx);
+ report_call_event_for_room(operation, room.id(), room.channel_id(), &client);
room.toggle_mute(cx)
})
@@ -8874,7 +8874,7 @@ impl Editor {
let telemetry = project.read(cx).client().telemetry().clone();
- telemetry.report_copilot_event(suggestion_id, suggestion_accepted, file_extension, cx)
+ telemetry.report_copilot_event(suggestion_id, suggestion_accepted, file_extension)
}
#[cfg(any(test, feature = "test-support"))]
@@ -8926,7 +8926,6 @@ impl Editor {
operation,
copilot_enabled,
copilot_enabled_for_language,
- cx,
)
}
@@ -182,7 +182,7 @@ impl PickerDelegate for ThemeSelectorDelegate {
let theme_name = cx.theme().name.clone();
self.telemetry
- .report_setting_event("theme", theme_name.to_string(), cx);
+ .report_setting_event("theme", theme_name.to_string());
update_settings_file::<ThemeSettings>(self.fs.clone(), cx, move |settings| {
settings.theme = Some(theme_name.to_string());
@@ -1,4 +1,5 @@
use super::base_keymap_setting::BaseKeymap;
+use client::telemetry::Telemetry;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, Task, View,
@@ -27,9 +28,10 @@ pub fn toggle(
cx: &mut ViewContext<Workspace>,
) {
let fs = workspace.app_state().fs.clone();
+ let telemetry = workspace.client().telemetry().clone();
workspace.toggle_modal(cx, |cx| {
BaseKeymapSelector::new(
- BaseKeymapSelectorDelegate::new(cx.view().downgrade(), fs, cx),
+ BaseKeymapSelectorDelegate::new(cx.view().downgrade(), fs, telemetry, cx),
cx,
)
});
@@ -68,6 +70,7 @@ pub struct BaseKeymapSelectorDelegate {
view: WeakView<BaseKeymapSelector>,
matches: Vec<StringMatch>,
selected_index: usize,
+ telemetry: Arc<Telemetry>,
fs: Arc<dyn Fs>,
}
@@ -75,6 +78,7 @@ impl BaseKeymapSelectorDelegate {
fn new(
weak_view: WeakView<BaseKeymapSelector>,
fs: Arc<dyn Fs>,
+ telemetry: Arc<Telemetry>,
cx: &mut ViewContext<BaseKeymapSelector>,
) -> Self {
let base = BaseKeymap::get(None, cx);
@@ -86,6 +90,7 @@ impl BaseKeymapSelectorDelegate {
view: weak_view,
matches: Vec::new(),
selected_index,
+ telemetry,
fs,
}
}
@@ -167,6 +172,10 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
fn confirm(&mut self, _: bool, cx: &mut ViewContext<Picker<BaseKeymapSelectorDelegate>>) {
if let Some(selection) = self.matches.get(self.selected_index) {
let base_keymap = BaseKeymap::from_names(&selection.string);
+
+ self.telemetry
+ .report_setting_event("keymap", base_keymap.to_string());
+
update_settings_file::<BaseKeymap>(self.fs.clone(), cx, move |setting| {
*setting = Some(base_keymap)
});
@@ -1,3 +1,5 @@
+use std::fmt::{Display, Formatter};
+
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use settings::Settings;
@@ -12,6 +14,18 @@ pub enum BaseKeymap {
TextMate,
}
+impl Display for BaseKeymap {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ BaseKeymap::VSCode => write!(f, "VSCode"),
+ BaseKeymap::JetBrains => write!(f, "JetBrains"),
+ BaseKeymap::SublimeText => write!(f, "Sublime Text"),
+ BaseKeymap::Atom => write!(f, "Atom"),
+ BaseKeymap::TextMate => write!(f, "TextMate"),
+ }
+ }
+}
+
impl BaseKeymap {
pub const OPTIONS: [(&'static str, Self); 5] = [
("VSCode (Default)", Self::VSCode),
@@ -1,7 +1,7 @@
mod base_keymap_picker;
mod base_keymap_setting;
-use client::TelemetrySettings;
+use client::{telemetry::Telemetry, TelemetrySettings};
use db::kvp::KEY_VALUE_STORE;
use gpui::{
svg, AnyElement, AppContext, EventEmitter, FocusHandle, FocusableView, InteractiveElement,
@@ -27,7 +27,7 @@ pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, _cx| {
workspace.register_action(|workspace, _: &Welcome, cx| {
- let welcome_page = cx.new_view(|cx| WelcomePage::new(workspace, cx));
+ let welcome_page = WelcomePage::new(workspace, cx);
workspace.add_item(Box::new(welcome_page), cx)
});
})
@@ -39,7 +39,7 @@ pub fn init(cx: &mut AppContext) {
pub fn show_welcome_view(app_state: &Arc<AppState>, cx: &mut AppContext) {
open_new(&app_state, cx, |workspace, cx| {
workspace.toggle_dock(DockPosition::Left, cx);
- let welcome_page = cx.new_view(|cx| WelcomePage::new(workspace, cx));
+ let welcome_page = WelcomePage::new(workspace, cx);
workspace.add_item_to_center(Box::new(welcome_page.clone()), cx);
cx.focus_view(&welcome_page);
cx.notify();
@@ -54,174 +54,213 @@ pub fn show_welcome_view(app_state: &Arc<AppState>, cx: &mut AppContext) {
pub struct WelcomePage {
workspace: WeakView<Workspace>,
focus_handle: FocusHandle,
+ telemetry: Arc<Telemetry>,
_settings_subscription: Subscription,
}
impl Render for WelcomePage {
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl IntoElement {
- h_stack()
- .full()
- .bg(cx.theme().colors().editor_background)
- .track_focus(&self.focus_handle)
- .child(
- v_stack()
- .w_96()
- .gap_4()
- .mx_auto()
- .child(
- svg()
- .path("icons/logo_96.svg")
- .text_color(gpui::white())
- .w(px(96.))
- .h(px(96.))
- .mx_auto(),
- )
- .child(
- h_stack()
- .justify_center()
- .child(Label::new("Code at the speed of thought")),
- )
- .child(
- v_stack()
- .gap_2()
- .child(
- Button::new("choose-theme", "Choose a theme")
- .full_width()
- .on_click(cx.listener(|this, _, cx| {
- this.workspace
- .update(cx, |workspace, cx| {
- theme_selector::toggle(
- workspace,
- &Default::default(),
- cx,
- )
- })
- .ok();
- })),
- )
- .child(
- Button::new("choose-keymap", "Choose a keymap")
- .full_width()
- .on_click(cx.listener(|this, _, cx| {
- this.workspace
- .update(cx, |workspace, cx| {
- base_keymap_picker::toggle(
- workspace,
- &Default::default(),
- cx,
- )
- })
- .ok();
- })),
- )
- .child(
- Button::new("install-cli", "Install the CLI")
- .full_width()
- .on_click(cx.listener(|_, _, cx| {
- cx.app_mut()
- .spawn(|cx| async move {
- install_cli::install_cli(&cx).await
- })
- .detach_and_log_err(cx);
- })),
- ),
- )
- .child(
- v_stack()
- .p_3()
- .gap_2()
- .bg(cx.theme().colors().elevated_surface_background)
- .border_1()
- .border_color(cx.theme().colors().border)
- .rounded_md()
- .child(
- h_stack()
- .gap_2()
- .child(
- Checkbox::new(
- "enable-vim",
- if VimModeSetting::get_global(cx).0 {
- ui::Selection::Selected
- } else {
- ui::Selection::Unselected
- },
+ h_stack().full().track_focus(&self.focus_handle).child(
+ v_stack()
+ .w_96()
+ .gap_4()
+ .mx_auto()
+ .child(
+ svg()
+ .path("icons/logo_96.svg")
+ .text_color(gpui::white())
+ .w(px(96.))
+ .h(px(96.))
+ .mx_auto(),
+ )
+ .child(
+ h_stack()
+ .justify_center()
+ .child(Label::new("Code at the speed of thought")),
+ )
+ .child(
+ v_stack()
+ .gap_2()
+ .child(
+ Button::new("choose-theme", "Choose a theme")
+ .full_width()
+ .on_click(cx.listener(|this, _, cx| {
+ this.telemetry
+ .report_app_event("welcome page: change theme");
+ this.workspace
+ .update(cx, |workspace, cx| {
+ theme_selector::toggle(
+ workspace,
+ &Default::default(),
+ cx,
+ )
+ })
+ .ok();
+ })),
+ )
+ .child(
+ Button::new("choose-keymap", "Choose a keymap")
+ .full_width()
+ .on_click(cx.listener(|this, _, cx| {
+ this.telemetry
+ .report_app_event("welcome page: change keymap");
+ this.workspace
+ .update(cx, |workspace, cx| {
+ base_keymap_picker::toggle(
+ workspace,
+ &Default::default(),
+ cx,
+ )
+ })
+ .ok();
+ })),
+ )
+ .child(
+ Button::new("install-cli", "Install the CLI")
+ .full_width()
+ .on_click(cx.listener(|this, _, cx| {
+ this.telemetry.report_app_event("welcome page: install cli");
+ cx.app_mut()
+ .spawn(
+ |cx| async move { install_cli::install_cli(&cx).await },
)
- .on_click(
- cx.listener(move |this, selection, cx| {
- this.update_settings::<VimModeSetting>(
- selection,
- cx,
- |setting, value| *setting = Some(value),
- );
- }),
- ),
+ .detach_and_log_err(cx);
+ })),
+ ),
+ )
+ .child(
+ v_stack()
+ .p_3()
+ .gap_2()
+ .bg(cx.theme().colors().elevated_surface_background)
+ .border_1()
+ .border_color(cx.theme().colors().border)
+ .rounded_md()
+ .child(
+ h_stack()
+ .gap_2()
+ .child(
+ Checkbox::new(
+ "enable-vim",
+ if VimModeSetting::get_global(cx).0 {
+ ui::Selection::Selected
+ } else {
+ ui::Selection::Unselected
+ },
)
- .child(Label::new("Enable vim mode")),
- )
- .child(
- h_stack()
- .gap_2()
- .child(
- Checkbox::new(
- "enable-telemetry",
- if TelemetrySettings::get_global(cx).metrics {
- ui::Selection::Selected
- } else {
- ui::Selection::Unselected
- },
- )
- .on_click(
- cx.listener(move |this, selection, cx| {
- this.update_settings::<TelemetrySettings>(
- selection,
- cx,
- |settings, value| {
- settings.metrics = Some(value)
- },
- );
- }),
- ),
+ .on_click(cx.listener(
+ move |this, selection, cx| {
+ this.telemetry
+ .report_app_event("welcome page: toggle vim");
+ this.update_settings::<VimModeSetting>(
+ selection,
+ cx,
+ |setting, value| *setting = Some(value),
+ );
+ },
+ )),
+ )
+ .child(Label::new("Enable vim mode")),
+ )
+ .child(
+ h_stack()
+ .gap_2()
+ .child(
+ Checkbox::new(
+ "enable-telemetry",
+ if TelemetrySettings::get_global(cx).metrics {
+ ui::Selection::Selected
+ } else {
+ ui::Selection::Unselected
+ },
)
- .child(Label::new("Send anonymous usage data")),
- )
- .child(
- h_stack()
- .gap_2()
- .child(
- Checkbox::new(
- "enable-crash",
- if TelemetrySettings::get_global(cx).diagnostics {
- ui::Selection::Selected
- } else {
- ui::Selection::Unselected
- },
- )
- .on_click(
- cx.listener(move |this, selection, cx| {
- this.update_settings::<TelemetrySettings>(
- selection,
- cx,
- |settings, value| {
- settings.diagnostics = Some(value)
- },
- );
- }),
- ),
+ .on_click(cx.listener(
+ move |this, selection, cx| {
+ this.telemetry.report_app_event(
+ "welcome page: toggle metric telemetry",
+ );
+ this.update_settings::<TelemetrySettings>(
+ selection,
+ cx,
+ {
+ let telemetry = this.telemetry.clone();
+
+ move |settings, value| {
+ settings.metrics = Some(value);
+
+ telemetry.report_setting_event(
+ "metric telemetry",
+ value.to_string(),
+ );
+ }
+ },
+ );
+ },
+ )),
+ )
+ .child(Label::new("Send anonymous usage data")),
+ )
+ .child(
+ h_stack()
+ .gap_2()
+ .child(
+ Checkbox::new(
+ "enable-crash",
+ if TelemetrySettings::get_global(cx).diagnostics {
+ ui::Selection::Selected
+ } else {
+ ui::Selection::Unselected
+ },
)
- .child(Label::new("Send crash reports")),
- ),
- ),
- )
+ .on_click(cx.listener(
+ move |this, selection, cx| {
+ this.telemetry.report_app_event(
+ "welcome page: toggle diagnostic telemetry",
+ );
+ this.update_settings::<TelemetrySettings>(
+ selection,
+ cx,
+ {
+ let telemetry = this.telemetry.clone();
+
+ move |settings, value| {
+ settings.diagnostics = Some(value);
+
+ telemetry.report_setting_event(
+ "diagnostic telemetry",
+ value.to_string(),
+ );
+ }
+ },
+ );
+ },
+ )),
+ )
+ .child(Label::new("Send crash reports")),
+ ),
+ ),
+ )
}
}
impl WelcomePage {
- pub fn new(workspace: &Workspace, cx: &mut ViewContext<Self>) -> Self {
- WelcomePage {
- focus_handle: cx.focus_handle(),
- workspace: workspace.weak_handle(),
- _settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
- }
+ pub fn new(workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
+ let this = cx.new_view(|cx| {
+ cx.on_release(|this: &mut Self, _, _| {
+ this.telemetry.report_app_event("welcome page: close");
+ })
+ .detach();
+
+ WelcomePage {
+ focus_handle: cx.focus_handle(),
+ workspace: workspace.weak_handle(),
+ telemetry: workspace.client().telemetry().clone(),
+ _settings_subscription: cx
+ .observe_global::<SettingsStore>(move |_, cx| cx.notify()),
+ }
+ });
+
+ this
}
fn update_settings<T: Settings>(
@@ -279,6 +318,7 @@ impl Item for WelcomePage {
Some(cx.new_view(|cx| WelcomePage {
focus_handle: cx.focus_handle(),
workspace: self.workspace.clone(),
+ telemetry: self.telemetry.clone(),
_settings_subscription: cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()),
}))
}
@@ -1258,9 +1258,7 @@ impl Workspace {
}
pub fn open(&mut self, _: &Open, cx: &mut ViewContext<Self>) {
- self.client()
- .telemetry()
- .report_app_event("open project", false, cx);
+ self.client().telemetry().report_app_event("open project");
let paths = cx.prompt_for_paths(PathPromptOptions {
files: true,
directories: true,
@@ -45,7 +45,7 @@ use util::{
paths, ResultExt,
};
use uuid::Uuid;
-use welcome::{show_welcome_view, FIRST_OPEN};
+use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN};
use workspace::{AppState, WorkspaceStore};
use zed::{
app_menus, build_window_options, ensure_only_instance, handle_cli_connection,
@@ -171,17 +171,15 @@ fn main() {
})
.detach();
- client.telemetry().start(installation_id, session_id, cx);
- client
- .telemetry()
- .report_setting_event("theme", cx.theme().name.to_string(), cx);
- let event_operation = match existing_installation_id_found {
+ let telemetry = client.telemetry();
+ telemetry.start(installation_id, session_id, cx);
+ telemetry.report_setting_event("theme", cx.theme().name.to_string());
+ telemetry.report_setting_event("keymap", BaseKeymap::get_global(cx).to_string());
+ telemetry.report_app_event(match existing_installation_id_found {
Some(false) => "first open",
_ => "open",
- };
- client
- .telemetry()
- .report_app_event(event_operation, true, cx);
+ });
+ telemetry.flush_events();
let app_state = Arc::new(AppState {
languages: languages.clone(),