Skip to content

Commit

Permalink
Flip the optionality of the auto_update setting (zed-industries#10302)
Browse files Browse the repository at this point in the history
This PR flips the optionality of the `AutoUpdateSettingContent` to make
it a bit easier to work with.

#### Before

```rs
struct AutoUpdateSettingContent(Option<bool>);

type FileContent = AutoUpdateSettingContent;
```

#### After

```rs
struct AutoUpdateSettingContent(bool);

type FileContent = Option<AutoUpdateSettingContent>;
```

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Apr 9, 2024
1 parent def87a8 commit 843aad8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
23 changes: 8 additions & 15 deletions crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>);
struct AutoUpdateSettingContent(bool);

impl Settings for AutoUpdateSetting {
const KEY: Option<&'static str> = Some("auto_update");

type FileContent = AutoUpdateSettingOverride;
type FileContent = Option<AutoUpdateSettingContent>;

fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
if let Some(release_channel_value) = sources.release_channel {
if let Some(value) = release_channel_value.0 {
return Ok(Self(value));
}
}

if let Some(user_value) = sources.user {
if let Some(value) = user_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)?);

Ok(Self(sources.default.0.ok_or_else(Self::missing_default)?))
Ok(Self(auto_update.0))
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ impl Settings for ClientSettings {

type FileContent = ClientSettingsContent;

fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self>
where
Self: Sized,
{
fn load(sources: SettingsSources<Self::FileContent>, _: &mut AppContext) -> Result<Self> {
let mut result = sources.json_merge::<Self>()?;
if let Some(server_url) = &*ZED_SERVER_URL {
result.server_url = server_url.clone()
Expand Down

0 comments on commit 843aad8

Please sign in to comment.