1use std::path::PathBuf;
2use std::sync::Arc;
3
4use anyhow::Result;
5use extension::{ExtensionHostProxy, ExtensionThemeProxy};
6use fs::Fs;
7use gpui::{AppContext, BackgroundExecutor, SharedString, Task};
8use theme::{ThemeRegistry, ThemeSettings};
9
10pub fn init(
11 extension_host_proxy: Arc<ExtensionHostProxy>,
12 theme_registry: Arc<ThemeRegistry>,
13 executor: BackgroundExecutor,
14) {
15 extension_host_proxy.register_theme_proxy(ThemeRegistryProxy {
16 theme_registry,
17 executor,
18 });
19}
20
21struct ThemeRegistryProxy {
22 theme_registry: Arc<ThemeRegistry>,
23 executor: BackgroundExecutor,
24}
25
26impl ExtensionThemeProxy for ThemeRegistryProxy {
27 fn list_theme_names(&self, theme_path: PathBuf, fs: Arc<dyn Fs>) -> Task<Result<Vec<String>>> {
28 self.executor.spawn(async move {
29 let themes = theme::read_user_theme(&theme_path, fs).await?;
30 Ok(themes.themes.into_iter().map(|theme| theme.name).collect())
31 })
32 }
33
34 fn remove_user_themes(&self, themes: Vec<SharedString>) {
35 self.theme_registry.remove_user_themes(&themes);
36 }
37
38 fn load_user_theme(&self, theme_path: PathBuf, fs: Arc<dyn Fs>) -> Task<Result<()>> {
39 let theme_registry = self.theme_registry.clone();
40 self.executor
41 .spawn(async move { theme_registry.load_user_theme(&theme_path, fs).await })
42 }
43
44 fn reload_current_theme(&self, cx: &mut AppContext) {
45 ThemeSettings::reload_current_theme(cx)
46 }
47}