Rework access to ThemeRegistry global (#7023)

This PR reworks how we access the `ThemeRegistry` global.

Previously we were making calls directly on the context, like
`cx.global::<ThemeRegistry>`. However, one problem with this is that it
spreads out the knowledge of exactly what type is stored in the global.

In order to make it easier to adjust the type we store in the context
(e.g., wrapping the `ThemeRegistry` in an `Arc`), we now call methods on
the `ThemeRegistry` itself for accessing the global.

It would also be interesting to see how we could prevent access to the
`ThemeRegistry` without going through one of these dedicated methods 🤔

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-01-29 17:51:34 -05:00 committed by GitHub
parent 2a2cf45e90
commit 7656096814
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 8 deletions

View file

@ -102,7 +102,7 @@ impl ThemeSelectorDelegate {
let original_theme = cx.theme().clone();
let staff_mode = cx.is_staff();
let registry = cx.global::<ThemeRegistry>();
let registry = ThemeRegistry::global(cx);
let mut themes = registry.list(staff_mode).collect::<Vec<_>>();
themes.sort_unstable_by(|a, b| {
a.appearance
@ -135,7 +135,7 @@ impl ThemeSelectorDelegate {
fn show_selected_theme(&mut self, cx: &mut ViewContext<Picker<ThemeSelectorDelegate>>) {
if let Some(mat) = self.matches.get(self.selected_index) {
let registry = cx.global::<ThemeRegistry>();
let registry = ThemeRegistry::global(cx);
match registry.get(&mat.string) {
Ok(theme) => {
Self::set_theme(theme, cx);