Skip to content

Commit

Permalink
Avoid logging errors about missing themes dir (zed-industries#7290)
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneToIgnore authored Feb 2, 2024
1 parent 115f067 commit 2d58226
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions crates/zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,27 +892,37 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
{
if let Some(()) = theme_registry
.load_user_themes(&paths::THEMES_DIR.clone(), fs)
let themes_dir = paths::THEMES_DIR.as_ref();
match fs
.metadata(themes_dir)
.await
.log_err()
.ok()
.flatten()
.map(|m| m.is_dir)
{
cx.update(|cx| {
let mut theme_settings = ThemeSettings::get_global(cx).clone();

if let Some(requested_theme) = theme_settings.requested_theme.clone() {
if let Some(_theme) = theme_settings.switch_theme(&requested_theme, cx)
{
ThemeSettings::override_global(theme_settings, cx);
}
}
})
.log_err();
Some(is_dir) => {
anyhow::ensure!(is_dir, "Themes dir path {themes_dir:?} is not a directory")
}
None => {
fs.create_dir(themes_dir).await.with_context(|| {
format!("Failed to create themes dir at path {themes_dir:?}")
})?;
}
}
theme_registry.load_user_themes(themes_dir, fs).await?;
cx.update(|cx| {
let mut theme_settings = ThemeSettings::get_global(cx).clone();
if let Some(requested_theme) = theme_settings.requested_theme.clone() {
if let Some(_theme) = theme_settings.switch_theme(&requested_theme, cx) {
ThemeSettings::override_global(theme_settings, cx);
}
}
})?;
}
anyhow::Ok(())
}
})
.detach();
.detach_and_log_err(cx);
}

/// Spawns a background task to watch the themes directory for changes.
Expand Down

0 comments on commit 2d58226

Please sign in to comment.