Add support for applying theme after extension is installed (#9529)

Release Notes:

- Added support for opening the theme selector with installed themes
after installing an extension containing themes.
([#9228](https://github.com/zed-industries/zed/issues/9228)).

<img width="1315" alt="Screenshot 2024-03-20 at 11 00 35 AM"
src="https://github.com/zed-industries/zed/assets/1486634/593389b3-eade-4bce-ae17-25c02a074f21">

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Jason Lee 2024-03-20 23:13:58 +08:00 committed by GitHub
parent 6cec389125
commit 269d2513ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 102 additions and 16 deletions

View file

@ -92,16 +92,18 @@ pub enum ExtensionStatus {
Removing,
}
#[derive(Clone, Copy)]
enum ExtensionOperation {
Upgrade,
Install,
Remove,
}
#[derive(Copy, Clone)]
#[derive(Clone)]
pub enum Event {
ExtensionsUpdated,
StartedReloading,
ExtensionInstalled(Arc<str>),
}
impl EventEmitter<Event> for ExtensionStore {}
@ -330,6 +332,7 @@ impl ExtensionStore {
.unbounded_send(modified_extension)
.expect("reload task exited");
cx.emit(Event::StartedReloading);
async move {
rx.await.ok();
}
@ -358,6 +361,17 @@ impl ExtensionStore {
.filter_map(|extension| extension.dev.then_some(&extension.manifest))
}
/// Returns the names of themes provided by extensions.
pub fn extension_themes<'a>(
&'a self,
extension_id: &'a str,
) -> impl Iterator<Item = &'a Arc<str>> {
self.extension_index
.themes
.iter()
.filter_map(|(name, theme)| theme.extension.as_ref().eq(extension_id).then_some(name))
}
pub fn fetch_extensions(
&self,
search: Option<&str>,
@ -441,8 +455,21 @@ impl ExtensionStore {
archive
.unpack(extensions_dir.join(extension_id.as_ref()))
.await?;
this.update(&mut cx, |this, cx| this.reload(Some(extension_id), cx))?
.await;
this.update(&mut cx, |this, cx| {
this.reload(Some(extension_id.clone()), cx)
})?
.await;
match operation {
ExtensionOperation::Install => {
this.update(&mut cx, |_, cx| {
cx.emit(Event::ExtensionInstalled(extension_id));
})
.ok();
}
_ => {}
}
anyhow::Ok(())
})
.detach_and_log_err(cx);