From f4a93b61f03d8e47c9775bdeb6224694d839ff0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 27 Sep 2022 21:23:28 +0200 Subject: [PATCH] Log update errors (#1362) * Remove unused functions, log update errors * Remove some outdated comments --- lapce-data/src/update.rs | 46 ---------------------------------------- lapce-ui/src/about.rs | 7 ------ lapce-ui/src/app.rs | 31 ++++++++++++++++++--------- 3 files changed, 21 insertions(+), 63 deletions(-) diff --git a/lapce-data/src/update.rs b/lapce-data/src/update.rs index c05ffab7..a24079de 100644 --- a/lapce-data/src/update.rs +++ b/lapce-data/src/update.rs @@ -158,49 +158,3 @@ pub fn restart(path: &Path) -> Result<()> { .spawn()?; Ok(()) } - -#[cfg(target_os = "macos")] -pub fn update(_process_id: &str, src: &Path, dest: &Path) -> Result<()> { - let info = dmg::Attach::new(src).with()?; - if dest.file_name().and_then(|s| s.to_str()) == Some("MacOS") { - dest.parent().unwrap().parent().unwrap().parent().unwrap() - } else { - dest - }; - let _ = std::fs::remove_dir_all(dest.join("Lapce.app")); - fs_extra::copy_items( - &[info.mount_point.join("Lapce.app")], - dest, - &fs_extra::dir::CopyOptions { - overwrite: true, - skip_exist: false, - buffer_size: 64000, - copy_inside: true, - content_only: false, - depth: 0, - }, - )?; - - std::process::Command::new("open") - .arg(dest.join("Lapce.app")) - .output()?; - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))] -pub fn update(_process_id: &str, src: &Path, dest: &Path) -> Result<()> { - let tar_gz = std::fs::File::open(src)?; - let tar = flate2::read::GzDecoder::new(tar_gz); - let mut archive = tar::Archive::new(tar); - let parent = src.parent().ok_or_else(|| anyhow::anyhow!("no parent"))?; - archive.unpack(parent)?; - let dest = dest.join("lapce"); - std::fs::copy(parent.join("Lapce").join("lapce"), &dest)?; - let _ = std::process::Command::new(dest).arg("&").output(); - Ok(()) -} - -#[cfg(target_os = "windows")] -pub fn update(_process_id: &str, _src: &Path, _dest: &Path) -> Result<()> { - Ok(()) -} diff --git a/lapce-ui/src/about.rs b/lapce-ui/src/about.rs index f17212a3..52770843 100644 --- a/lapce-ui/src/about.rs +++ b/lapce-ui/src/about.rs @@ -302,13 +302,6 @@ fn layout( Point::new(self.padding, self.padding * 2.0 + self.svg_size), )); - // GitHub: {}\nDiscord: {}\nMatrix: {}\n\n\nThird party resources used:\n\nCodicons (CC-BY-4.0)\n{} - // "https://lapce.dev", - // "https://github.com/lapce/lapce", - // "https://discord.gg/n8tGJ6Rn6D", - // "https://matrix.to/#/#lapce-editor:matrix.org", - // "https://github.com/microsoft/vscode-codicons" - let mut y = self.padding * 2.0 + self.svg_size + title_size.height diff --git a/lapce-ui/src/app.rs b/lapce-ui/src/app.rs index 38be6577..0e0e46a4 100644 --- a/lapce-ui/src/app.rs +++ b/lapce-ui/src/app.rs @@ -375,16 +375,27 @@ fn command( let _ = data.db.save_app(data); let process_path = process_path.clone(); let release = release.clone(); - std::thread::spawn(move || -> anyhow::Result<()> { - log::info!("start to down new versoin"); - let src = - lapce_data::update::download_release(&release)?; - log::info!("start to extract"); - let path = - lapce_data::update::extract(&src, &process_path)?; - log::info!("now restart {path:?}"); - lapce_data::update::restart(&path)?; - Ok(()) + std::thread::spawn(move || { + let do_update = || -> anyhow::Result<()> { + log::info!("start to down new versoin"); + let src = + lapce_data::update::download_release(&release)?; + + log::info!("start to extract"); + let path = lapce_data::update::extract( + &src, + &process_path, + )?; + + log::info!("now restart {path:?}"); + lapce_data::update::restart(&path)?; + + Ok(()) + }; + + if let Err(err) = do_update() { + log::error!("Failed to update: {err}"); + } }); return druid::Handled::Yes; }