theme: Turn ThemeRegistry into a trait (#20076)

This PR converts the `ThemeRegistry` type into a trait instead of a
concrete implementation.

This allows for the extension store to depend on an abstraction rather
than the concrete theme registry implementation.

We currently have two `ThemeRegistry` implementations:

- `RealThemeRegistry` — this was previously the `ThemeRegistry` and
contains the real implementation of the registry.
- `VoidThemeRegistry` — a null object that doesn't have any behavior.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-01 10:19:09 -04:00 committed by GitHub
parent c04c439d23
commit af9e7f1f96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 184 additions and 118 deletions

View file

@ -407,7 +407,7 @@ fn main() {
app_state.client.clone(),
app_state.node_runtime.clone(),
app_state.languages.clone(),
ThemeRegistry::global(cx),
<dyn ThemeRegistry>::global(cx),
cx,
);
recent_projects::init(cx);
@ -1160,8 +1160,9 @@ fn load_user_themes_in_background(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
cx.spawn({
let fs = fs.clone();
|cx| async move {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
if let Some(theme_registry) = cx
.update(|cx| <dyn ThemeRegistry>::global(cx).clone())
.log_err()
{
let themes_dir = paths::themes_dir().as_ref();
match fs
@ -1200,8 +1201,9 @@ fn watch_themes(fs: Arc<dyn fs::Fs>, cx: &mut AppContext) {
while let Some(paths) = events.next().await {
for event in paths {
if fs.metadata(&event.path).await.ok().flatten().is_some() {
if let Some(theme_registry) =
cx.update(|cx| ThemeRegistry::global(cx).clone()).log_err()
if let Some(theme_registry) = cx
.update(|cx| <dyn ThemeRegistry>::global(cx).clone())
.log_err()
{
if let Some(()) = theme_registry
.load_user_theme(&event.path, fs.clone())

View file

@ -1139,7 +1139,7 @@ mod tests {
path::{Path, PathBuf},
time::Duration,
};
use theme::{ThemeRegistry, ThemeSettings};
use theme::{RealThemeRegistry, ThemeRegistry, ThemeSettings};
use workspace::{
item::{Item, ItemHandle},
open_new, open_paths, pane, NewFile, OpenVisible, SaveIntent, SplitDirection,
@ -3419,7 +3419,7 @@ mod tests {
.unwrap(),
])
.unwrap();
let themes = ThemeRegistry::default();
let themes = RealThemeRegistry::default();
settings::init(cx);
theme::init(theme::LoadThemes::JustBase, cx);