Add auto-update system for extensions (#9890)
* [x] auto update extensions on startup * [ ] add a manual way of updating all? * [x] add a way to opt out of auto-updates for a particular extension We don't believe that there should be any background polling for extension auto-updates, because it could be disruptive to the user. Release Notes: - Added an auto-update system for extensions. --------- Co-authored-by: Marshall <marshall@zed.dev> Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
3a36b10e3a
commit
95fd426eff
9 changed files with 559 additions and 79 deletions
|
@ -1,11 +1,15 @@
|
|||
mod components;
|
||||
mod extension_suggest;
|
||||
mod extension_version_selector;
|
||||
|
||||
use crate::components::ExtensionCard;
|
||||
use crate::extension_version_selector::{
|
||||
ExtensionVersionSelector, ExtensionVersionSelectorDelegate,
|
||||
};
|
||||
use client::telemetry::Telemetry;
|
||||
use client::ExtensionMetadata;
|
||||
use editor::{Editor, EditorElement, EditorStyle};
|
||||
use extension::{ExtensionManifest, ExtensionStatus, ExtensionStore};
|
||||
use extension::{ExtensionManifest, ExtensionOperation, ExtensionStore};
|
||||
use fuzzy::{match_strings, StringMatchCandidate};
|
||||
use gpui::{
|
||||
actions, canvas, uniform_list, AnyElement, AppContext, EventEmitter, FocusableView, FontStyle,
|
||||
|
@ -17,7 +21,7 @@ use std::ops::DerefMut;
|
|||
use std::time::Duration;
|
||||
use std::{ops::Range, sync::Arc};
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, ToggleButton, Tooltip};
|
||||
use ui::{popover_menu, prelude::*, ContextMenu, ToggleButton, Tooltip};
|
||||
use util::ResultExt as _;
|
||||
use workspace::{
|
||||
item::{Item, ItemEvent},
|
||||
|
@ -77,6 +81,15 @@ pub fn init(cx: &mut AppContext) {
|
|||
.detach();
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ExtensionStatus {
|
||||
NotInstalled,
|
||||
Installing,
|
||||
Upgrading,
|
||||
Installed(Arc<str>),
|
||||
Removing,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
enum ExtensionFilter {
|
||||
All,
|
||||
|
@ -94,6 +107,7 @@ impl ExtensionFilter {
|
|||
}
|
||||
|
||||
pub struct ExtensionsPage {
|
||||
workspace: WeakView<Workspace>,
|
||||
list: UniformListScrollHandle,
|
||||
telemetry: Arc<Telemetry>,
|
||||
is_fetching_extensions: bool,
|
||||
|
@ -131,6 +145,7 @@ impl ExtensionsPage {
|
|||
cx.subscribe(&query_editor, Self::on_query_change).detach();
|
||||
|
||||
let mut this = Self {
|
||||
workspace: workspace.weak_handle(),
|
||||
list: UniformListScrollHandle::new(),
|
||||
telemetry: workspace.client().telemetry().clone(),
|
||||
is_fetching_extensions: false,
|
||||
|
@ -174,9 +189,21 @@ impl ExtensionsPage {
|
|||
}
|
||||
}
|
||||
|
||||
fn filter_extension_entries(&mut self, cx: &mut ViewContext<Self>) {
|
||||
fn extension_status(extension_id: &str, cx: &mut ViewContext<Self>) -> ExtensionStatus {
|
||||
let extension_store = ExtensionStore::global(cx).read(cx);
|
||||
|
||||
match extension_store.outstanding_operations().get(extension_id) {
|
||||
Some(ExtensionOperation::Install) => ExtensionStatus::Installing,
|
||||
Some(ExtensionOperation::Remove) => ExtensionStatus::Removing,
|
||||
Some(ExtensionOperation::Upgrade) => ExtensionStatus::Upgrading,
|
||||
None => match extension_store.installed_extensions().get(extension_id) {
|
||||
Some(extension) => ExtensionStatus::Installed(extension.manifest.version.clone()),
|
||||
None => ExtensionStatus::NotInstalled,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn filter_extension_entries(&mut self, cx: &mut ViewContext<Self>) {
|
||||
self.filtered_remote_extension_indices.clear();
|
||||
self.filtered_remote_extension_indices.extend(
|
||||
self.remote_extension_entries
|
||||
|
@ -185,11 +212,11 @@ impl ExtensionsPage {
|
|||
.filter(|(_, extension)| match self.filter {
|
||||
ExtensionFilter::All => true,
|
||||
ExtensionFilter::Installed => {
|
||||
let status = extension_store.extension_status(&extension.id);
|
||||
let status = Self::extension_status(&extension.id, cx);
|
||||
matches!(status, ExtensionStatus::Installed(_))
|
||||
}
|
||||
ExtensionFilter::NotInstalled => {
|
||||
let status = extension_store.extension_status(&extension.id);
|
||||
let status = Self::extension_status(&extension.id, cx);
|
||||
|
||||
matches!(status, ExtensionStatus::NotInstalled)
|
||||
}
|
||||
|
@ -285,9 +312,7 @@ impl ExtensionsPage {
|
|||
extension: &ExtensionManifest,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> ExtensionCard {
|
||||
let status = ExtensionStore::global(cx)
|
||||
.read(cx)
|
||||
.extension_status(&extension.id);
|
||||
let status = Self::extension_status(&extension.id, cx);
|
||||
|
||||
let repository_url = extension.repository.clone();
|
||||
|
||||
|
@ -389,10 +414,10 @@ impl ExtensionsPage {
|
|||
extension: &ExtensionMetadata,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> ExtensionCard {
|
||||
let status = ExtensionStore::global(cx)
|
||||
.read(cx)
|
||||
.extension_status(&extension.id);
|
||||
let this = cx.view().clone();
|
||||
let status = Self::extension_status(&extension.id, cx);
|
||||
|
||||
let extension_id = extension.id.clone();
|
||||
let (install_or_uninstall_button, upgrade_button) =
|
||||
self.buttons_for_entry(extension, &status, cx);
|
||||
let repository_url = extension.manifest.repository.clone();
|
||||
|
@ -454,24 +479,99 @@ impl ExtensionsPage {
|
|||
)
|
||||
}))
|
||||
.child(
|
||||
IconButton::new(
|
||||
SharedString::from(format!("repository-{}", extension.id)),
|
||||
IconName::Github,
|
||||
)
|
||||
.icon_color(Color::Accent)
|
||||
.icon_size(IconSize::Small)
|
||||
.style(ButtonStyle::Filled)
|
||||
.on_click(cx.listener({
|
||||
let repository_url = repository_url.clone();
|
||||
move |_, _, cx| {
|
||||
cx.open_url(&repository_url);
|
||||
}
|
||||
}))
|
||||
.tooltip(move |cx| Tooltip::text(repository_url.clone(), cx)),
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(
|
||||
IconButton::new(
|
||||
SharedString::from(format!("repository-{}", extension.id)),
|
||||
IconName::Github,
|
||||
)
|
||||
.icon_color(Color::Accent)
|
||||
.icon_size(IconSize::Small)
|
||||
.style(ButtonStyle::Filled)
|
||||
.on_click(cx.listener({
|
||||
let repository_url = repository_url.clone();
|
||||
move |_, _, cx| {
|
||||
cx.open_url(&repository_url);
|
||||
}
|
||||
}))
|
||||
.tooltip(move |cx| Tooltip::text(repository_url.clone(), cx)),
|
||||
)
|
||||
.child(
|
||||
popover_menu(SharedString::from(format!("more-{}", extension.id)))
|
||||
.trigger(
|
||||
IconButton::new(
|
||||
SharedString::from(format!("more-{}", extension.id)),
|
||||
IconName::Ellipsis,
|
||||
)
|
||||
.icon_color(Color::Accent)
|
||||
.icon_size(IconSize::Small)
|
||||
.style(ButtonStyle::Filled),
|
||||
)
|
||||
.menu(move |cx| {
|
||||
Some(Self::render_remote_extension_context_menu(
|
||||
&this,
|
||||
extension_id.clone(),
|
||||
cx,
|
||||
))
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn render_remote_extension_context_menu(
|
||||
this: &View<Self>,
|
||||
extension_id: Arc<str>,
|
||||
cx: &mut WindowContext,
|
||||
) -> View<ContextMenu> {
|
||||
let context_menu = ContextMenu::build(cx, |context_menu, cx| {
|
||||
context_menu.entry(
|
||||
"Install Another Version...",
|
||||
None,
|
||||
cx.handler_for(&this, move |this, cx| {
|
||||
this.show_extension_version_list(extension_id.clone(), cx)
|
||||
}),
|
||||
)
|
||||
});
|
||||
|
||||
context_menu
|
||||
}
|
||||
|
||||
fn show_extension_version_list(&mut self, extension_id: Arc<str>, cx: &mut ViewContext<Self>) {
|
||||
let Some(workspace) = self.workspace.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
let extension_versions_task = this.update(&mut cx, |_, cx| {
|
||||
let extension_store = ExtensionStore::global(cx);
|
||||
|
||||
extension_store.update(cx, |store, cx| {
|
||||
store.fetch_extension_versions(&extension_id, cx)
|
||||
})
|
||||
})?;
|
||||
|
||||
let extension_versions = extension_versions_task.await?;
|
||||
|
||||
workspace.update(&mut cx, |workspace, cx| {
|
||||
let fs = workspace.project().read(cx).fs().clone();
|
||||
workspace.toggle_modal(cx, |cx| {
|
||||
let delegate = ExtensionVersionSelectorDelegate::new(
|
||||
fs,
|
||||
cx.view().downgrade(),
|
||||
extension_versions,
|
||||
);
|
||||
|
||||
ExtensionVersionSelector::new(delegate, cx)
|
||||
});
|
||||
})?;
|
||||
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
fn buttons_for_entry(
|
||||
&self,
|
||||
extension: &ExtensionMetadata,
|
||||
|
@ -531,11 +631,13 @@ impl ExtensionsPage {
|
|||
"extensions: install extension".to_string(),
|
||||
);
|
||||
ExtensionStore::global(cx).update(cx, |store, cx| {
|
||||
store.upgrade_extension(
|
||||
extension_id.clone(),
|
||||
version.clone(),
|
||||
cx,
|
||||
)
|
||||
store
|
||||
.upgrade_extension(
|
||||
extension_id.clone(),
|
||||
version.clone(),
|
||||
cx,
|
||||
)
|
||||
.detach_and_log_err(cx)
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue