Disable incompatible extension versions in extension view (#9938)
This PR makes it so extension versions that are incompatible with what the current Zed instance supports are disabled in the UI, to prevent attempting to install them. Here's what it looks like in the extension version picker: <img width="589" alt="Screenshot 2024-03-28 at 4 21 15 PM" src="https://github.com/zed-industries/zed/assets/1486634/8ef11c72-c8f0-4de8-a73b-5c82e96f6bfe"> Release Notes: - N/A
This commit is contained in:
parent
95fd426eff
commit
0d7f5f49e6
6 changed files with 87 additions and 20 deletions
|
@ -165,6 +165,10 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
|
|||
let candidate_id = self.matches[self.selected_index].candidate_id;
|
||||
let extension_version = &self.extension_versions[candidate_id];
|
||||
|
||||
if !extension::is_version_compatible(extension_version) {
|
||||
return;
|
||||
}
|
||||
|
||||
let extension_store = ExtensionStore::global(cx);
|
||||
extension_store.update(cx, |store, cx| {
|
||||
let extension_id = extension_version.id.clone();
|
||||
|
@ -196,21 +200,38 @@ impl PickerDelegate for ExtensionVersionSelectorDelegate {
|
|||
let version_match = &self.matches[ix];
|
||||
let extension_version = &self.extension_versions[version_match.candidate_id];
|
||||
|
||||
let is_version_compatible = extension::is_version_compatible(extension_version);
|
||||
let disabled = !is_version_compatible;
|
||||
|
||||
Some(
|
||||
ListItem::new(ix)
|
||||
.inset(true)
|
||||
.spacing(ListItemSpacing::Sparse)
|
||||
.selected(selected)
|
||||
.child(HighlightedLabel::new(
|
||||
version_match.string.clone(),
|
||||
version_match.positions.clone(),
|
||||
))
|
||||
.end_slot(Label::new(
|
||||
extension_version
|
||||
.published_at
|
||||
.format("%Y-%m-%d")
|
||||
.to_string(),
|
||||
)),
|
||||
.disabled(disabled)
|
||||
.child(
|
||||
HighlightedLabel::new(
|
||||
version_match.string.clone(),
|
||||
version_match.positions.clone(),
|
||||
)
|
||||
.when(disabled, |label| label.color(Color::Muted)),
|
||||
)
|
||||
.end_slot(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.when(!is_version_compatible, |this| {
|
||||
this.child(Label::new("Incompatible").color(Color::Muted))
|
||||
})
|
||||
.child(
|
||||
Label::new(
|
||||
extension_version
|
||||
.published_at
|
||||
.format("%Y-%m-%d")
|
||||
.to_string(),
|
||||
)
|
||||
.when(disabled, |label| label.color(Color::Muted)),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -578,10 +578,14 @@ impl ExtensionsPage {
|
|||
status: &ExtensionStatus,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> (Button, Option<Button>) {
|
||||
let is_compatible = extension::is_version_compatible(&extension);
|
||||
let disabled = !is_compatible;
|
||||
|
||||
match status.clone() {
|
||||
ExtensionStatus::NotInstalled => (
|
||||
Button::new(SharedString::from(extension.id.clone()), "Install").on_click(
|
||||
cx.listener({
|
||||
Button::new(SharedString::from(extension.id.clone()), "Install")
|
||||
.disabled(disabled)
|
||||
.on_click(cx.listener({
|
||||
let extension_id = extension.id.clone();
|
||||
let version = extension.manifest.version.clone();
|
||||
move |this, _, cx| {
|
||||
|
@ -591,8 +595,7 @@ impl ExtensionsPage {
|
|||
store.install_extension(extension_id.clone(), version.clone(), cx)
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
})),
|
||||
None,
|
||||
),
|
||||
ExtensionStatus::Installing => (
|
||||
|
@ -622,8 +625,9 @@ impl ExtensionsPage {
|
|||
None
|
||||
} else {
|
||||
Some(
|
||||
Button::new(SharedString::from(extension.id.clone()), "Upgrade").on_click(
|
||||
cx.listener({
|
||||
Button::new(SharedString::from(extension.id.clone()), "Upgrade")
|
||||
.disabled(disabled)
|
||||
.on_click(cx.listener({
|
||||
let extension_id = extension.id.clone();
|
||||
let version = extension.manifest.version.clone();
|
||||
move |this, _, cx| {
|
||||
|
@ -640,8 +644,7 @@ impl ExtensionsPage {
|
|||
.detach_and_log_err(cx)
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
})),
|
||||
)
|
||||
},
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue