Revert "Allow updater to check for updates after downloading one (#30969)" (#31086)

Joseph T. Lyons created

This reverts commit 5c4f9e57d8f919f58e39d660515e1dbec7d71483.

Release Notes:

- N/A

Change summary

crates/activity_indicator/src/activity_indicator.rs |  2 
crates/auto_update/src/auto_update.rs               | 85 ++++----------
2 files changed, 24 insertions(+), 63 deletions(-)

Detailed changes

crates/activity_indicator/src/activity_indicator.rs 🔗

@@ -485,7 +485,7 @@ impl ActivityIndicator {
                         this.dismiss_error_message(&DismissErrorMessage, window, cx)
                     })),
                 }),
-                AutoUpdateStatus::Updated { binary_path, .. } => Some(Content {
+                AutoUpdateStatus::Updated { binary_path } => Some(Content {
                     icon: None,
                     message: "Click to restart and update Zed".to_string(),
                     on_click: Some(Arc::new({

crates/auto_update/src/auto_update.rs 🔗

@@ -39,22 +39,13 @@ struct UpdateRequestBody {
     destination: &'static str,
 }
 
-#[derive(Clone, PartialEq, Eq)]
-pub enum VersionCheckType {
-    Sha(String),
-    Semantic(SemanticVersion),
-}
-
 #[derive(Clone, PartialEq, Eq)]
 pub enum AutoUpdateStatus {
     Idle,
     Checking,
     Downloading,
     Installing,
-    Updated {
-        binary_path: PathBuf,
-        version: VersionCheckType,
-    },
+    Updated { binary_path: PathBuf },
     Errored,
 }
 
@@ -71,7 +62,7 @@ pub struct AutoUpdater {
     pending_poll: Option<Task<Option<()>>>,
 }
 
-#[derive(Deserialize, Clone, Debug)]
+#[derive(Deserialize, Debug)]
 pub struct JsonRelease {
     pub version: String,
     pub url: String,
@@ -316,7 +307,7 @@ impl AutoUpdater {
     }
 
     pub fn poll(&mut self, cx: &mut Context<Self>) {
-        if self.pending_poll.is_some() {
+        if self.pending_poll.is_some() || self.status.is_updated() {
             return;
         }
 
@@ -491,63 +482,36 @@ impl AutoUpdater {
         Self::get_release(this, asset, os, arch, None, release_channel, cx).await
     }
 
-    fn installed_update_version(&self) -> Option<VersionCheckType> {
-        match &self.status {
-            AutoUpdateStatus::Updated { version, .. } => Some(version.clone()),
-            _ => None,
-        }
-    }
-
     async fn update(this: Entity<Self>, mut cx: AsyncApp) -> Result<()> {
-        let (client, current_version, installed_update_version, release_channel) =
-            this.update(&mut cx, |this, cx| {
-                this.status = AutoUpdateStatus::Checking;
-                cx.notify();
-                (
-                    this.http_client.clone(),
-                    this.current_version,
-                    this.installed_update_version(),
-                    ReleaseChannel::try_global(cx),
-                )
-            })?;
+        let (client, current_version, release_channel) = this.update(&mut cx, |this, cx| {
+            this.status = AutoUpdateStatus::Checking;
+            cx.notify();
+            (
+                this.http_client.clone(),
+                this.current_version,
+                ReleaseChannel::try_global(cx),
+            )
+        })?;
 
         let release =
             Self::get_latest_release(&this, "zed", OS, ARCH, release_channel, &mut cx).await?;
 
-        let update_version_to_install = match *RELEASE_CHANNEL {
-            ReleaseChannel::Nightly => {
-                let should_download = cx
-                    .update(|cx| AppCommitSha::try_global(cx).map(|sha| release.version != sha.0))
-                    .ok()
-                    .flatten()
-                    .unwrap_or(true);
-
-                should_download.then(|| VersionCheckType::Sha(release.version.clone()))
-            }
-            _ => {
-                let installed_version =
-                    installed_update_version.unwrap_or(VersionCheckType::Semantic(current_version));
-                match installed_version {
-                    VersionCheckType::Sha(_) => {
-                        log::warn!("Unexpected SHA-based version in non-nightly build");
-                        Some(installed_version)
-                    }
-                    VersionCheckType::Semantic(semantic_comparison_version) => {
-                        let latest_release_version = release.version.parse::<SemanticVersion>()?;
-                        let should_download = latest_release_version > semantic_comparison_version;
-                        should_download.then(|| VersionCheckType::Semantic(latest_release_version))
-                    }
-                }
-            }
+        let should_download = match *RELEASE_CHANNEL {
+            ReleaseChannel::Nightly => cx
+                .update(|cx| AppCommitSha::try_global(cx).map(|sha| release.version != sha.0))
+                .ok()
+                .flatten()
+                .unwrap_or(true),
+            _ => release.version.parse::<SemanticVersion>()? > current_version,
         };
 
-        let Some(update_version) = update_version_to_install else {
+        if !should_download {
             this.update(&mut cx, |this, cx| {
                 this.status = AutoUpdateStatus::Idle;
                 cx.notify();
             })?;
             return Ok(());
-        };
+        }
 
         this.update(&mut cx, |this, cx| {
             this.status = AutoUpdateStatus::Downloading;
@@ -569,7 +533,7 @@ impl AutoUpdater {
         );
 
         let downloaded_asset = installer_dir.path().join(filename);
-        download_release(&downloaded_asset, release.clone(), client, &cx).await?;
+        download_release(&downloaded_asset, release, client, &cx).await?;
 
         this.update(&mut cx, |this, cx| {
             this.status = AutoUpdateStatus::Installing;
@@ -586,10 +550,7 @@ impl AutoUpdater {
         this.update(&mut cx, |this, cx| {
             this.set_should_show_update_notification(true, cx)
                 .detach_and_log_err(cx);
-            this.status = AutoUpdateStatus::Updated {
-                binary_path,
-                version: update_version,
-            };
+            this.status = AutoUpdateStatus::Updated { binary_path };
             cx.notify();
         })?;