From 843aad80c6dc731a2a6c943c08534a47af9cee85 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 8 Apr 2024 20:16:05 -0400 Subject: [PATCH] Flip the optionality of the `auto_update` setting (#10302) This PR flips the optionality of the `AutoUpdateSettingContent` to make it a bit easier to work with. #### Before ```rs struct AutoUpdateSettingContent(Option); type FileContent = AutoUpdateSettingContent; ``` #### After ```rs struct AutoUpdateSettingContent(bool); type FileContent = Option; ``` Release Notes: - N/A --- crates/auto_update/src/auto_update.rs | 23 ++++++++--------------- crates/client/src/client.rs | 5 +---- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 9e41d7248f..1715be8b6a 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -82,29 +82,22 @@ struct AutoUpdateSetting(bool); /// Whether or not to automatically check for updates. /// /// Default: true -#[derive(Clone, Default, JsonSchema, Deserialize, Serialize)] +#[derive(Clone, Copy, Default, JsonSchema, Deserialize, Serialize)] #[serde(transparent)] -struct AutoUpdateSettingOverride(Option); +struct AutoUpdateSettingContent(bool); impl Settings for AutoUpdateSetting { const KEY: Option<&'static str> = Some("auto_update"); - type FileContent = AutoUpdateSettingOverride; + type FileContent = Option; fn load(sources: SettingsSources, _: &mut AppContext) -> Result { - if let Some(release_channel_value) = sources.release_channel { - if let Some(value) = release_channel_value.0 { - return Ok(Self(value)); - } - } + let auto_update = [sources.release_channel, sources.user] + .into_iter() + .find_map(|value| value.copied().flatten()) + .unwrap_or(sources.default.ok_or_else(Self::missing_default)?); - if let Some(user_value) = sources.user { - if let Some(value) = user_value.0 { - return Ok(Self(value)); - } - } - - Ok(Self(sources.default.0.ok_or_else(Self::missing_default)?)) + Ok(Self(auto_update.0)) } } diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 5d06fccb7a..7b696d1eaa 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -97,10 +97,7 @@ impl Settings for ClientSettings { type FileContent = ClientSettingsContent; - fn load(sources: SettingsSources, _: &mut AppContext) -> Result - where - Self: Sized, - { + fn load(sources: SettingsSources, _: &mut AppContext) -> Result { let mut result = sources.json_merge::()?; if let Some(server_url) = &*ZED_SERVER_URL { result.server_url = server_url.clone()