mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-11-19 09:01:23 +01:00
Merge pull request #1398 from dotCooCoo/chore/craft-update-6e03f65
build: pin the craft-libs crates to craft-libs main at 453b0da, pass the release's repo to craft-update, and offer Update and Restart only to a copy that can update itself
This commit is contained in:
6 files changed
+163
-42
No files matched your search
Generated
+7
-7
@@ -1019,7 +1019,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-atomic"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=86d6e8c5b05a4dadc35ff1c8e5d2f992c687ee97#86d6e8c5b05a4dadc35ff1c8e5d2f992c687ee97"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"rustix 1.1.5",
|
||||
]
|
||||
@@ -1027,7 +1027,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-flags"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=86d6e8c5b05a4dadc35ff1c8e5d2f992c687ee97#86d6e8c5b05a4dadc35ff1c8e5d2f992c687ee97"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"craft-atomic",
|
||||
"dirs 7.0.0",
|
||||
@@ -1037,12 +1037,12 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"fixed_decimal",
|
||||
"icu_decimal",
|
||||
@@ -1065,7 +1065,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-quit"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"dispatch2",
|
||||
"egui",
|
||||
@@ -1076,7 +1076,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-ui"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=92d392cff132eaf53e13afff77f38b5c11b73aa0#92d392cff132eaf53e13afff77f38b5c11b73aa0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"craft-fonts-build",
|
||||
"craft-i18n",
|
||||
@@ -1096,7 +1096,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-update"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=6e03f65bf45181db77ba6229716e6624db9eb25b#6e03f65bf45181db77ba6229716e6624db9eb25b"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=453b0da782ccef39be9a6dac8d27c80b553ef1cc#453b0da782ccef39be9a6dac8d27c80b553ef1cc"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dunce",
|
||||
|
||||
+3
-3
@@ -34,12 +34,12 @@ log = "0.4"
|
||||
# All date/time conversion goes through jiff (no hand-rolled calendar code beyond the 400-year range extension; AGENTS.md).
|
||||
jiff = "0.2"
|
||||
# Feature flags (craft-libs#1118, merged in craft-libs#1119).
|
||||
craft-flags = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "86d6e8c5b05a4dadc35ff1c8e5d2f992c687ee97" }
|
||||
craft-flags = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" }
|
||||
# The agents switch and app list (Settings › AI agents), shared with the craft-ai-mcp gateway and
|
||||
# every Craft app. Pinned to the merge of storytold/craft-ai-integrations#197.
|
||||
craft-ai-agents = { git = "https://github.com/storytold/craft-ai-integrations", rev = "0d76ea02a06299a5a6eee1993863fbcafe9c2cc3" }
|
||||
craft-update = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b" }
|
||||
craft-ui = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0" }
|
||||
craft-update = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" }
|
||||
craft-ui = { version = "=0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc" }
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
||||
|
||||
@@ -30,7 +30,7 @@ notify-rust = "4"
|
||||
# Cargo.lock through eframe's "persistence" feature.
|
||||
ron = "0.12.2"
|
||||
serde = { workspace = true }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "92d392cff132eaf53e13afff77f38b5c11b73aa0", features = ["egui"] }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "453b0da782ccef39be9a6dac8d27c80b553ef1cc", features = ["egui"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
zbus = "5"
|
||||
|
||||
@@ -14,7 +14,7 @@ workspace = true
|
||||
# Lets ARTCRAFT_LAUNCHER_DOWNLOAD_BASE point the launcher at a developer's own loopback mirror
|
||||
# (`cargo xtask local serve`). Development only: release builds never enable it, so a shipped
|
||||
# launcher can't be steered away from GitHub's releases by an environment variable.
|
||||
local-mirror = []
|
||||
local-mirror = ["craft-update/local-mirror"]
|
||||
|
||||
[dependencies]
|
||||
artcraft-launcher-core = { workspace = true }
|
||||
|
||||
@@ -88,12 +88,16 @@ struct Shared {
|
||||
/// A detection pass is running; another request waits for the next one.
|
||||
detecting: AtomicBool,
|
||||
last_check: Mutex<Option<i64>>,
|
||||
/// The newer ArtCraft Launcher release, once a check has found one.
|
||||
launcher_release: Mutex<Option<Release>>,
|
||||
/// The newer ArtCraft Launcher release, once a check has found one, with the repo that check
|
||||
/// read it from (the feed's rename, if any): its download links must be that repo's.
|
||||
launcher_release: Mutex<Option<(Release, String)>>,
|
||||
/// How this launcher is installed, when it can replace itself. Worked out on the check thread
|
||||
/// just before a newer launcher is announced: finding out can ask the host's Flatpak, which
|
||||
/// mustn't hold up the first frame.
|
||||
self_install: OnceLock<Option<crate::self_update::Install>>,
|
||||
/// Whether this copy can update itself ([`crate::self_update::is_self_updating`]: on Windows,
|
||||
/// only a signed copy). Worked out with `self_install`.
|
||||
self_updating: OnceLock<bool>,
|
||||
/// When GitHub was last asked about each app (Unix seconds), to keep the fallback rare.
|
||||
github_asked: Mutex<HashMap<String, i64>>,
|
||||
/// Apps with an answer (a release or "none yet") from either service.
|
||||
@@ -281,6 +285,7 @@ impl NativeBackend {
|
||||
detecting: AtomicBool::new(false),
|
||||
launcher_release: Mutex::new(None),
|
||||
self_install: OnceLock::new(),
|
||||
self_updating: OnceLock::new(),
|
||||
github_asked: Mutex::new(HashMap::new()),
|
||||
answered: Mutex::new(std::collections::HashSet::new()),
|
||||
loaded: AtomicBool::new(false),
|
||||
@@ -599,12 +604,16 @@ impl NativeBackend {
|
||||
}
|
||||
|
||||
/// What updating this launcher to the newer release takes, when this copy can replace itself
|
||||
/// and the release has the file the update downloads. Otherwise the UI offers the download.
|
||||
fn launcher_update_job(&self) -> Option<(crate::self_update::Install, Release, Platform)> {
|
||||
/// ([`crate::self_update::is_self_updating`]) and the release has the file the update
|
||||
/// downloads. Otherwise the UI offers the download.
|
||||
fn launcher_update_job(&self) -> Option<(crate::self_update::Install, Release, String, Platform)> {
|
||||
let install = self.shared.self_install.get().cloned().flatten()?;
|
||||
let platform = self.platform?;
|
||||
let release = self.shared.launcher_release.lock().unwrap_or_else(PoisonError::into_inner).clone()?;
|
||||
crate::self_update::installs_from(&install, &release, platform).then_some((install, release, platform))
|
||||
if !self.shared.self_updating.get().copied().unwrap_or(false) {
|
||||
return None;
|
||||
}
|
||||
let (release, repo) = self.shared.launcher_release.lock().unwrap_or_else(PoisonError::into_inner).clone()?;
|
||||
crate::self_update::installs_from(&install, &release, platform).then_some((install, release, repo, platform))
|
||||
}
|
||||
|
||||
/// Downloads the newer launcher, puts it in place and asks the UI to quit so it can start.
|
||||
@@ -622,7 +631,7 @@ impl NativeBackend {
|
||||
if self.shared.launcher_release.lock().unwrap_or_else(PoisonError::into_inner).is_none() {
|
||||
return;
|
||||
}
|
||||
let Some((install, release, platform)) = self.launcher_update_job() else { return refuse() };
|
||||
let Some((install, release, repo, platform)) = self.launcher_update_job() else { return refuse() };
|
||||
let stop = Arc::new(Stop::default());
|
||||
{
|
||||
let mut jobs = self.shared.jobs.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
@@ -649,7 +658,7 @@ impl NativeBackend {
|
||||
claim_restart(&shared.jobs, &shared.restarting, &stop, RESTART_WAIT, &mut waiting)
|
||||
};
|
||||
let result = match http.as_ref() {
|
||||
Some(http) => crate::self_update::update(&install, &release, platform, http, &paths, &stop, &mut phase, &last),
|
||||
Some(http) => crate::self_update::update(&install, &release, &repo, platform, http, &paths, &stop, &mut phase, &last),
|
||||
None => Err("secure connections aren't available on this system".into()),
|
||||
};
|
||||
drop(job);
|
||||
@@ -1203,7 +1212,7 @@ fn sweep(
|
||||
if let Some(used) = used {
|
||||
sources.lock().unwrap_or_else(PoisonError::into_inner).push(used);
|
||||
}
|
||||
check_app(app, latest, from, shared, paths, platform);
|
||||
check_app(app, latest, from, &feed_repo(feed, app), shared, paths, platform);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1212,10 +1221,19 @@ fn sweep(
|
||||
}
|
||||
|
||||
/// Publishes one app's answer to the shared state, or handles the launcher's own update check
|
||||
/// first (it doesn't appear in the grid, so it has no card of its own to publish to).
|
||||
fn check_app(app: &'static CraftApp, latest: Option<LatestRelease>, from: Origin, shared: &Arc<Shared>, paths: &Paths, platform: Option<Platform>) {
|
||||
/// first (it doesn't appear in the grid, so it has no card of its own to publish to). `repo` is the
|
||||
/// repo this check asked about for `app` (the feed's rename, if any).
|
||||
fn check_app(
|
||||
app: &'static CraftApp,
|
||||
latest: Option<LatestRelease>,
|
||||
from: Origin,
|
||||
repo: &str,
|
||||
shared: &Arc<Shared>,
|
||||
paths: &Paths,
|
||||
platform: Option<Platform>,
|
||||
) {
|
||||
if app.id == LAUNCHER_ID {
|
||||
launcher_update(paths, latest, shared);
|
||||
launcher_update(paths, latest, repo, shared);
|
||||
return;
|
||||
}
|
||||
let Some(latest) = latest else { return };
|
||||
@@ -1225,13 +1243,15 @@ fn check_app(app: &'static CraftApp, latest: Option<LatestRelease>, from: Origin
|
||||
publish_latest(app, latest, from, shared, platform);
|
||||
}
|
||||
|
||||
/// Offers the launcher's own update when its answer is a newer release than the running one.
|
||||
fn launcher_update(paths: &Paths, latest: Option<LatestRelease>, shared: &Arc<Shared>) {
|
||||
/// Offers the launcher's own update when its answer is a newer release than the running one,
|
||||
/// keeping `repo`, the repo it was read from, for the download's link check.
|
||||
fn launcher_update(paths: &Paths, latest: Option<LatestRelease>, repo: &str, shared: &Arc<Shared>) {
|
||||
let Some(LatestRelease::Found(r)) = latest else { return };
|
||||
let (Some(newest), Some(current)) = (r.version.as_ref(), crate::self_update::current_version()) else { return };
|
||||
if version::is_newer(newest, ¤t) && !crate::self_update::just_updated_to(paths, &r) {
|
||||
shared.self_install.get_or_init(crate::self_update::current);
|
||||
*shared.launcher_release.lock().unwrap_or_else(PoisonError::into_inner) = Some(r.clone());
|
||||
shared.self_updating.get_or_init(crate::self_update::is_self_updating);
|
||||
*shared.launcher_release.lock().unwrap_or_else(PoisonError::into_inner) = Some((r.clone(), repo.to_string()));
|
||||
shared.emit(Event::LauncherUpdate(r));
|
||||
}
|
||||
}
|
||||
@@ -1960,6 +1980,7 @@ mod tests {
|
||||
last_check: Mutex::new(None),
|
||||
launcher_release: Mutex::new(None),
|
||||
self_install: OnceLock::new(),
|
||||
self_updating: OnceLock::new(),
|
||||
github_asked: Mutex::new(HashMap::new()),
|
||||
answered: Mutex::new(std::collections::HashSet::new()),
|
||||
loaded: AtomicBool::new(false),
|
||||
@@ -2363,15 +2384,52 @@ mod tests {
|
||||
|
||||
let mut windows_only = stable("0.6.0");
|
||||
windows_only.assets.retain(|a| a.name.contains("windows"));
|
||||
check_app(app, Some(LatestRelease::Found(windows_only)), Origin::GitHub, &backend.shared, &backend.paths, Some(platform));
|
||||
check_app(app, Some(LatestRelease::Found(windows_only)), Origin::GitHub, app.repo, &backend.shared, &backend.paths, Some(platform));
|
||||
assert_eq!(told(backend.poll()), ["installable false", "latest"]);
|
||||
check_app(app, Some(LatestRelease::Found(stable("0.6.0"))), Origin::GitHub, &backend.shared, &backend.paths, Some(platform));
|
||||
check_app(app, Some(LatestRelease::Found(stable("0.6.0"))), Origin::GitHub, app.repo, &backend.shared, &backend.paths, Some(platform));
|
||||
assert_eq!(told(backend.poll()), ["installable true", "latest"]);
|
||||
|
||||
publish_detected(app, None, &backend.shared, Some(platform));
|
||||
assert_eq!(told(backend.poll()), ["detected"], "removed: no answer");
|
||||
}
|
||||
|
||||
/// The launcher offers to replace itself only when this copy can update itself and the newer
|
||||
/// release has a file to install it from. Otherwise the UI offers the download, in the format
|
||||
/// this copy was installed as. Update and Restart refuses in the same cases without starting a
|
||||
/// download.
|
||||
#[test]
|
||||
fn self_update_is_offered_only_when_the_copy_and_the_release_allow_it() {
|
||||
let platform = Platform { os: Os::Windows, arch: Arch::X64 };
|
||||
let release = |name: &str| Release {
|
||||
assets: vec![Asset { name: name.into(), size: 1, url: format!("https://example.invalid/{name}"), sha256: None }],
|
||||
..stable("0.9.0")
|
||||
};
|
||||
let offered = |updating: bool, release: Release| {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut backend = backend(dir.path(), platform, None);
|
||||
let install = crate::self_update::Install::Portable(dir.path().join("artcraft-launcher.exe"));
|
||||
assert!(backend.shared.self_install.set(Some(install)).is_ok());
|
||||
assert!(backend.shared.self_updating.set(updating).is_ok());
|
||||
*backend.shared.launcher_release.lock().unwrap() = Some((release, String::new()));
|
||||
let offered = backend.capabilities().self_update;
|
||||
if !offered {
|
||||
backend.update_launcher();
|
||||
let events = backend.poll();
|
||||
assert!(
|
||||
matches!(&events[..], [Event::JobFinished { app, result: Err(_) }] if app == LAUNCHER_ID),
|
||||
"it refuses without starting a download: {events:?}"
|
||||
);
|
||||
assert!(backend.shared.jobs.lock().unwrap().is_empty());
|
||||
}
|
||||
(offered, backend.launcher_kind())
|
||||
};
|
||||
let portable = release("artcraft-launcher-0.9.0-windows-x64-portable.zip");
|
||||
let msi_only = release("artcraft-launcher-0.9.0-windows-x64.msi");
|
||||
assert_eq!(offered(true, portable.clone()), (true, Some(PackageKind::PortableZip)));
|
||||
assert_eq!(offered(false, portable), (false, Some(PackageKind::PortableZip)), "a copy that can't update itself (unsigned on Windows)");
|
||||
assert_eq!(offered(true, msi_only), (false, Some(PackageKind::PortableZip)), "a release without a file for this copy");
|
||||
}
|
||||
|
||||
/// A report made when only the plan changed (a settings change, a check or an install ending)
|
||||
/// still tells the UI whether an install would go ahead, on its own, with the settings as
|
||||
/// they are then.
|
||||
@@ -2806,6 +2864,7 @@ mod tests {
|
||||
CraftApp::by_id(APP).unwrap(),
|
||||
Some(LatestRelease::Found(latest)),
|
||||
Origin::GitHub,
|
||||
CraftApp::by_id(APP).unwrap().repo,
|
||||
&backend.shared,
|
||||
&backend.paths,
|
||||
backend.platform,
|
||||
@@ -3106,7 +3165,8 @@ mod tests {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let mut backend = backend(dir.path(), mac, None);
|
||||
backend.shared.self_install.set(Some(install.clone())).unwrap();
|
||||
*backend.shared.launcher_release.lock().unwrap() = Some(release.clone());
|
||||
backend.shared.self_updating.set(true).unwrap();
|
||||
*backend.shared.launcher_release.lock().unwrap() = Some((release.clone(), String::new()));
|
||||
assert_eq!(backend.capabilities().self_update, updates, "{install:?}");
|
||||
if !updates {
|
||||
backend.update_launcher();
|
||||
|
||||
@@ -13,7 +13,7 @@ use artcraft_launcher_core::version::Version;
|
||||
use crate::http::{Http, Stop};
|
||||
use crate::paths::Paths;
|
||||
|
||||
pub use craft_update::self_update::{FINISH_FLAG, Install, PRETEND_VAR, is_self_updating};
|
||||
pub use craft_update::self_update::{FINISH_FLAG, Install, PRETEND_VAR};
|
||||
|
||||
/// The version this launcher counts as (see [`PRETEND_VAR`]).
|
||||
pub fn current_version() -> Option<Version> {
|
||||
@@ -25,12 +25,20 @@ pub fn current() -> Option<Install> {
|
||||
craft_update::self_update::current(&craft_update::suite::LAUNCHER)
|
||||
}
|
||||
|
||||
/// Whether this copy can update itself: [`current`] finds it and, on Windows, it is signed.
|
||||
pub fn is_self_updating() -> bool {
|
||||
craft_update::self_update::is_self_updating(&craft_update::suite::LAUNCHER)
|
||||
}
|
||||
|
||||
fn to_update_paths(paths: &Paths) -> craft_update::Paths {
|
||||
craft_update::Paths { data: paths.data.clone(), cache: paths.cache.clone() }
|
||||
}
|
||||
|
||||
fn to_update_release(release: &Release) -> craft_update::Release {
|
||||
/// craft-update's copy of `release`, read from `repo` (`""` for the launcher's own). craft-update
|
||||
/// downloads only assets whose links belong to that repository.
|
||||
fn to_update_release(release: &Release, repo: &str) -> craft_update::Release {
|
||||
craft_update::Release {
|
||||
repo: repo.to_string(),
|
||||
tag: release.tag.clone(),
|
||||
version: release.version.clone(),
|
||||
name: release.name.clone(),
|
||||
@@ -43,8 +51,6 @@ fn to_update_release(release: &Release) -> craft_update::Release {
|
||||
.iter()
|
||||
.map(|a| craft_update::Asset { name: a.name.clone(), size: a.size, url: a.url.clone(), sha256: a.sha256.clone() })
|
||||
.collect(),
|
||||
// Empty: the launcher's own repository (`suite::LAUNCHER`), the only one its releases are read from.
|
||||
repo: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +74,7 @@ fn to_update_platform(platform: Platform) -> craft_update::Platform {
|
||||
/// Whether `release` is the version this launcher just updated itself to.
|
||||
pub fn just_updated_to(paths: &Paths, release: &Release) -> bool {
|
||||
let update_paths = to_update_paths(paths);
|
||||
let update_release = to_update_release(release);
|
||||
let update_release = to_update_release(release, "");
|
||||
craft_update::self_update::just_updated_to(&update_paths, &update_release)
|
||||
}
|
||||
|
||||
@@ -78,13 +84,15 @@ pub fn take_failure(paths: &Paths) -> Option<String> {
|
||||
craft_update::self_update::take_failure(&update_paths)
|
||||
}
|
||||
|
||||
/// Downloads `release` for `platform`, puts it in place and starts the helper that relaunches
|
||||
/// it once this process has exited. On success the caller must quit promptly. `last` is called
|
||||
/// once the download is ready and returns when the launcher may replace itself and restart.
|
||||
/// Downloads `release`, read from `repo` (the launcher's, or the one the feed renamed it to), for
|
||||
/// `platform`, puts it in place and starts the helper that relaunches it once this process has
|
||||
/// exited. On success the caller must quit promptly. `last` is called once the download is ready
|
||||
/// and returns when the launcher may replace itself and restart.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn update(
|
||||
install: &Install,
|
||||
release: &Release,
|
||||
repo: &str,
|
||||
platform: Platform,
|
||||
_http: &Http,
|
||||
paths: &Paths,
|
||||
@@ -92,7 +100,7 @@ pub fn update(
|
||||
phase: &mut dyn FnMut(JobPhase),
|
||||
last: &dyn Fn() -> Result<(), String>,
|
||||
) -> Result<(), String> {
|
||||
let update_release = to_update_release(release);
|
||||
let update_release = to_update_release(release, repo);
|
||||
let update_platform = to_update_platform(platform);
|
||||
let update_paths = to_update_paths(paths);
|
||||
let update_http = craft_update::Http::new("ArtCraft-Launcher/SelfUpdate")?;
|
||||
@@ -151,10 +159,10 @@ fn update_kind(install: &Install) -> craft_update::PackageKind {
|
||||
}
|
||||
|
||||
/// Whether `release` has the file that updating `install` on `platform` downloads ([`kind`]),
|
||||
/// picked as [`update`] picks it.
|
||||
/// picked as [`update`] picks it. The pick reads only the file names, so the repo is left empty.
|
||||
pub fn installs_from(install: &Install, release: &Release, platform: Platform) -> bool {
|
||||
let app = &craft_update::suite::LAUNCHER;
|
||||
craft_update::pick_asset(&to_update_release(release), &[app.id], to_update_platform(platform), &[update_kind(install)]).is_some()
|
||||
craft_update::pick_asset(&to_update_release(release, ""), &[app.id], to_update_platform(platform), &[update_kind(install)]).is_some()
|
||||
}
|
||||
|
||||
/// Finishes an update when this program was started as the update helper.
|
||||
@@ -166,6 +174,59 @@ pub fn finish(args: &[OsString]) -> Option<Result<(), String>> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// craft-update downloads only links in the repository the release was read from: a release
|
||||
/// read from the repository the feed renamed the launcher's to passes when it carries that
|
||||
/// repository, and is refused as the launcher's own.
|
||||
#[test]
|
||||
fn the_update_checks_links_against_the_repo_the_release_came_from() {
|
||||
let app = &craft_update::suite::LAUNCHER;
|
||||
let sums = |name: &str| [("a".repeat(64), name.to_string())];
|
||||
let renamed = artcraft_launcher_core::release::release_from_sums(
|
||||
"storytold/artcraft-launcher-next",
|
||||
"v0.9.0",
|
||||
&sums("artcraft-launcher-0.9.0-linux-x86_64.AppImage"),
|
||||
);
|
||||
let carried = to_update_release(&renamed, "storytold/artcraft-launcher-next");
|
||||
assert!(craft_update::install::check_download_link(app, &carried, &carried.assets[0]).is_ok());
|
||||
let own = to_update_release(&renamed, "");
|
||||
assert!(craft_update::install::check_download_link(app, &own, &own.assets[0]).is_err());
|
||||
|
||||
let launcher = artcraft_launcher_core::release::release_from_sums(app.repo, "v0.9.0", &sums("artcraft-launcher-0.9.0-linux-x86_64.AppImage"));
|
||||
let launcher = to_update_release(&launcher, app.repo);
|
||||
assert!(craft_update::install::check_download_link(app, &launcher, &launcher.assets[0]).is_ok());
|
||||
}
|
||||
|
||||
/// The update downloads the file for this platform in the format the copy was installed from,
|
||||
/// so a release without that file offers the download instead: an AppImage-only release for
|
||||
/// an MSI copy, an MSI for another architecture, or an MSI for a portable copy.
|
||||
#[test]
|
||||
fn a_release_without_the_installed_format_for_this_platform_does_not_install() {
|
||||
use artcraft_launcher_core::platform::{Arch, Os};
|
||||
use std::path::PathBuf;
|
||||
let app = &craft_update::suite::LAUNCHER;
|
||||
let release = |names: &[&str]| {
|
||||
let sums: Vec<(String, String)> = names.iter().map(|n| ("a".repeat(64), (*n).to_string())).collect();
|
||||
artcraft_launcher_core::release::release_from_sums(app.repo, "v0.9.0", &sums)
|
||||
};
|
||||
let windows_x64 = Platform { os: Os::Windows, arch: Arch::X64 };
|
||||
let msi = Install::Msi(PathBuf::new());
|
||||
let portable = Install::Portable(PathBuf::new());
|
||||
|
||||
let with_msi = release(&["artcraft-launcher-0.9.0-windows-x64.msi"]);
|
||||
assert!(installs_from(&msi, &with_msi, windows_x64));
|
||||
let appimage_only = release(&["artcraft-launcher-0.9.0-linux-x86_64.AppImage"]);
|
||||
assert!(!installs_from(&msi, &appimage_only, windows_x64));
|
||||
let other_arch = release(&["artcraft-launcher-0.9.0-windows-arm64.msi"]);
|
||||
assert!(!installs_from(&msi, &other_arch, windows_x64));
|
||||
assert!(installs_from(&msi, &other_arch, Platform { os: Os::Windows, arch: Arch::Arm64 }));
|
||||
assert!(!installs_from(&portable, &with_msi, windows_x64));
|
||||
|
||||
let linux_x64 = Platform { os: Os::Linux, arch: Arch::X64 };
|
||||
let deb = Install::Package(craft_update::PackageKind::Deb, PathBuf::new());
|
||||
assert!(installs_from(&Install::AppImage(PathBuf::new()), &appimage_only, linux_x64));
|
||||
assert!(!installs_from(&deb, &appimage_only, linux_x64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_development_build_does_not_update_itself() {
|
||||
assert_eq!(current(), None);
|
||||
@@ -277,7 +338,7 @@ mod tests {
|
||||
installs.push(Install::Package(kind, PathBuf::new()));
|
||||
}
|
||||
for install in installs {
|
||||
let error = update(&install, &Release::default(), platform, &http, &paths, &Stop::default(), &mut |_| {}, &|| Ok(())).unwrap_err();
|
||||
let error = update(&install, &Release::default(), "", platform, &http, &paths, &Stop::default(), &mut |_| {}, &|| Ok(())).unwrap_err();
|
||||
let looked_for = format!(" has no {} for ", update_kind(&install).label());
|
||||
assert!(error.contains(&looked_for), "{install:?}: {error}");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user