get the encoder work off the main thread and harden the update path
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use futures_util::StreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const GITEA_LATEST: &str =
|
||||
"https://git.lashman.live/api/v1/repos/lashman/bytesize/releases/latest";
|
||||
|
||||
/// Everything the updater will fetch has to live under this prefix. The download
|
||||
/// URL arrives from the frontend, and an unconstrained one there would let
|
||||
/// anything that can reach the webview hand the app a new executable to install.
|
||||
const UPDATE_ORIGIN: &str = "https://git.lashman.live/";
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub(crate) struct UpdateInfo {
|
||||
pub version: String,
|
||||
@@ -37,7 +42,14 @@ pub(crate) async fn check_for_update() -> Result<Option<UpdateInfo>> {
|
||||
.build()?;
|
||||
let resp = client.get(GITEA_LATEST).send().await?;
|
||||
if !resp.status().is_success() {
|
||||
tracing::debug!("update check returned status {}", resp.status());
|
||||
// A 404 means the endpoint itself is wrong or the repo has no releases -
|
||||
// not that the app is up to date, which is how it reads if this is only
|
||||
// ever a debug line.
|
||||
if resp.status() == reqwest::StatusCode::NOT_FOUND {
|
||||
tracing::warn!("no release published at {GITEA_LATEST}");
|
||||
} else {
|
||||
tracing::warn!("update check returned status {}", resp.status());
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
let body = resp.text().await?;
|
||||
@@ -69,6 +81,10 @@ where
|
||||
{
|
||||
use std::io::Write;
|
||||
|
||||
if !url.starts_with(UPDATE_ORIGIN) {
|
||||
bail!("refusing to download an update from {url}");
|
||||
}
|
||||
|
||||
if let Some(parent) = dest.parent() {
|
||||
std::fs::create_dir_all(parent).context("creating update parent dir")?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user