From ed14fd6e0defee822b59d8f5fc36abda32ae7d81 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 3 Jun 2022 16:57:50 -0700 Subject: [PATCH] Add setting to make projects online/offline by default --- crates/collab/src/integration_tests.rs | 3 ++- crates/project/src/project.rs | 32 +++++++++++++------------- crates/settings/src/settings.rs | 9 ++++++++ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/crates/collab/src/integration_tests.rs b/crates/collab/src/integration_tests.rs index f03b16ce81fe0fba408d9da0d862f2ca6773cf3d..d335aabbe460260d880b6b2c2cfda2a9f837bcd1 100644 --- a/crates/collab/src/integration_tests.rs +++ b/crates/collab/src/integration_tests.rs @@ -4635,7 +4635,8 @@ impl TestServer { async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient { cx.update(|cx| { - let settings = Settings::test(cx); + let mut settings = Settings::test(cx); + settings.projects_online_by_default = false; cx.set_global(settings); }); diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index a449f303ef247f3e1bc1545a034f00d741aaec5b..3e09436b4bc80ad3df67f9c54123869f2c4e4fed 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -562,9 +562,14 @@ impl Project { let db = self.project_store.read(cx).db.clone(); let keys = self.db_keys_for_online_state(cx); + let online_by_default = cx.global::().projects_online_by_default; let read_online = cx.background().spawn(async move { let values = db.read(keys)?; - anyhow::Ok(values.into_iter().all(|e| e.is_some())) + anyhow::Ok( + values + .into_iter() + .all(|e| e.map_or(online_by_default, |e| e == [true as u8])), + ) }); cx.spawn(|this, mut cx| async move { let online = read_online.await.log_err().unwrap_or(false); @@ -592,11 +597,8 @@ impl Project { let keys = self.db_keys_for_online_state(cx); let is_online = self.is_online(); cx.background().spawn(async move { - if is_online { - db.write(keys.into_iter().map(|key| (key, &[]))) - } else { - db.delete(keys) - } + let value = &[is_online as u8]; + db.write(keys.into_iter().map(|key| (key, value))) }) } @@ -882,17 +884,15 @@ impl Project { self.worktrees .iter() .filter_map(|worktree| { - worktree.upgrade(&cx).map(|worktree| { - format!( + let worktree = worktree.upgrade(&cx)?.read(cx); + if worktree.is_visible() { + Some(format!( "project-path-online:{}", - worktree - .read(cx) - .as_local() - .unwrap() - .abs_path() - .to_string_lossy() - ) - }) + worktree.as_local().unwrap().abs_path().to_string_lossy() + )) + } else { + None + } }) .collect::>() } diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 58c70d32c1dcebc37cee699f31f1b45f5fd6351a..0efedbfd9b8ae92ce4a91c5b3fb3cf59991a2580 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -19,6 +19,7 @@ pub use keymap_file::{keymap_file_json_schema, KeymapFileContent}; #[derive(Clone)] pub struct Settings { + pub projects_online_by_default: bool, pub buffer_font_family: FamilyId, pub buffer_font_size: f32, pub default_buffer_font_size: f32, @@ -49,6 +50,8 @@ pub enum SoftWrap { #[derive(Clone, Debug, Default, Deserialize, JsonSchema)] pub struct SettingsFileContent { + #[serde(default)] + pub projects_online_by_default: Option, #[serde(default)] pub buffer_font_family: Option, #[serde(default)] @@ -81,6 +84,7 @@ impl Settings { preferred_line_length: 80, language_overrides: Default::default(), format_on_save: true, + projects_online_by_default: true, theme, }) } @@ -135,6 +139,7 @@ impl Settings { preferred_line_length: 80, format_on_save: true, language_overrides: Default::default(), + projects_online_by_default: true, theme: gpui::fonts::with_font_cache(cx.font_cache().clone(), || Default::default()), } } @@ -164,6 +169,10 @@ impl Settings { } } + merge( + &mut self.projects_online_by_default, + data.projects_online_by_default, + ); merge(&mut self.buffer_font_size, data.buffer_font_size); merge(&mut self.default_buffer_font_size, data.buffer_font_size); merge(&mut self.vim_mode, data.vim_mode);