mirror of
https://github.com/storytold/craft-launcher.git
synced 2026-11-16 15:14:56 +00:00
Merge pull request #1089 from AxylumRust/refactor/core-clippy-pedantic
refactor(core): satisfy Clippy pedantic lints
This commit is contained in:
9 files changed
+41
-34
No files matched your search
@@ -30,9 +30,9 @@ pub struct CraftApp {
|
||||
pub ink_dark: [u8; 3],
|
||||
/// GitHub `owner/repo`.
|
||||
pub repo: &'static str,
|
||||
/// Older names its release assets may carry (PdfCraft shipped as PrintCraft until 0.2.1).
|
||||
/// Older names its release assets may carry (`PdfCraft` shipped as `PrintCraft` until 0.2.1).
|
||||
pub former_ids: &'static [&'static str],
|
||||
/// Older display names its installers registered (PdfCraft's MSI said PrintCraft until 0.2.1).
|
||||
/// Older display names its installers registered (`PdfCraft`'s MSI said `PrintCraft` until 0.2.1).
|
||||
pub former_names: &'static [&'static str],
|
||||
/// The `.app` bundle stem on macOS when it differs from `name` (`ArtCraft` for `ArtCraft Studio`).
|
||||
pub mac_bundle_name: Option<&'static str>,
|
||||
@@ -43,7 +43,7 @@ pub struct CraftApp {
|
||||
pub msi_publisher: Option<&'static str>,
|
||||
/// The bundle id when it isn't `ai.storyteller.<id>` (a community app brings its own).
|
||||
pub bundle: Option<&'static str>,
|
||||
/// Older bundle ids its Flatpak shipped under (SolidCraft was `ai.storyteller.solidcraft`).
|
||||
/// Older bundle ids its Flatpak shipped under (`SolidCraft` was `ai.storyteller.solidcraft`).
|
||||
pub former_bundles: &'static [&'static str],
|
||||
/// Its website, when it isn't a page on getartcraft.com (a community app has its own).
|
||||
pub site: Option<&'static str>,
|
||||
@@ -87,7 +87,7 @@ impl CraftApp {
|
||||
|
||||
/// Bundle ids this app may be installed under, current first.
|
||||
pub fn bundle_ids(&self) -> impl Iterator<Item = String> + '_ {
|
||||
std::iter::once(self.bundle_id()).chain(self.former_bundles.iter().map(|b| b.to_string()))
|
||||
std::iter::once(self.bundle_id()).chain(self.former_bundles.iter().map(ToString::to_string))
|
||||
}
|
||||
|
||||
/// Asset stems this app's releases may use, current first.
|
||||
|
||||
@@ -75,7 +75,7 @@ pub fn looks_like_jpeg(bytes: &[u8]) -> bool {
|
||||
/// Reads the pixel dimensions `(width, height)` declared in a JPEG's frame header, without
|
||||
/// decoding any pixels. `None` when the bytes aren't a JPEG we can read a frame size from.
|
||||
///
|
||||
/// It walks the marker segments to the Start-Of-Frame (SOFn) marker, whose payload begins with
|
||||
/// It walks the marker segments to the Start-Of-Frame (`SOFn`) marker, whose payload begins with
|
||||
/// `precision (1) · height (2, big-endian) · width (2)`.
|
||||
pub fn jpeg_dimensions(bytes: &[u8]) -> Option<(u16, u16)> {
|
||||
if !looks_like_jpeg(bytes) {
|
||||
|
||||
@@ -45,7 +45,7 @@ fn unquote(v: &str) -> &str {
|
||||
|
||||
/// The distro's own package format: `.deb` for the Debian family, `.rpm` for the Fedora, Red Hat
|
||||
/// and SUSE families, `.pkg.tar.zst` for the Arch Linux family, `None` for anything else
|
||||
/// (unknown distros), which gets AppImages.
|
||||
/// (unknown distros), which gets `AppImage` files.
|
||||
pub fn native_package(os: &OsRelease) -> Option<PackageKind> {
|
||||
std::iter::once(&os.id).chain(&os.id_like).find_map(|id| family(id))
|
||||
}
|
||||
|
||||
@@ -234,9 +234,8 @@ fn lenient<'de, D: Deserializer<'de>, T: DeserializeOwned + Default>(d: D) -> Re
|
||||
/// A list where entries of the wrong shape are dropped rather than spoiling the rest.
|
||||
fn lenient_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(d: D) -> Result<Vec<T>, D::Error> {
|
||||
let value = serde_json::Value::deserialize(d)?;
|
||||
let items = match value {
|
||||
serde_json::Value::Array(items) => items,
|
||||
_ => return Ok(Vec::new()),
|
||||
let serde_json::Value::Array(items) = value else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
Ok(items.into_iter().filter_map(|v| T::deserialize(v).ok()).collect())
|
||||
}
|
||||
@@ -244,9 +243,8 @@ fn lenient_vec<'de, D: Deserializer<'de>, T: DeserializeOwned>(d: D) -> Result<V
|
||||
/// A map where entries of the wrong shape are dropped.
|
||||
fn lenient_map<'de, D: Deserializer<'de>, T: DeserializeOwned>(d: D) -> Result<BTreeMap<String, T>, D::Error> {
|
||||
let value = serde_json::Value::deserialize(d)?;
|
||||
let entries = match value {
|
||||
serde_json::Value::Object(entries) => entries,
|
||||
_ => return Ok(BTreeMap::new()),
|
||||
let serde_json::Value::Object(entries) = value else {
|
||||
return Ok(BTreeMap::new());
|
||||
};
|
||||
Ok(entries.into_iter().filter_map(|(k, v)| T::deserialize(v).ok().map(|t| (k, t))).collect())
|
||||
}
|
||||
|
||||
@@ -147,17 +147,14 @@ impl Platform {
|
||||
(Os::Windows, Arch::X64) => &["windows-x64", "windows-x86"],
|
||||
(Os::Windows, Arch::X86) => &["windows-x86"],
|
||||
(Os::Windows, Arch::Arm64) => &["windows-arm64", "windows-x64", "windows-x86"],
|
||||
(Os::Windows, _) => &[],
|
||||
(Os::MacOs, Arch::X64) => &["macos-universal", "macos-x86_64"],
|
||||
(Os::MacOs, Arch::Arm64) => &["macos-universal", "macos-aarch64", "macos-arm64", "macos-x86_64"],
|
||||
(Os::MacOs, _) => &[],
|
||||
(Os::Linux, Arch::X64) => &["linux-x86_64"],
|
||||
(Os::Linux, Arch::Arm64) => &["linux-aarch64"],
|
||||
(Os::Linux, Arch::Riscv64) => &["linux-riscv64"],
|
||||
(Os::Linux, Arch::X86) => &[],
|
||||
(Os::FreeBsd, Arch::X64) => &["freebsd-x86_64"],
|
||||
(Os::FreeBsd, Arch::Arm64) => &["freebsd-aarch64"],
|
||||
(Os::FreeBsd, _) => &[],
|
||||
(Os::Windows | Os::MacOs | Os::FreeBsd, _) | (Os::Linux, Arch::X86) => &[],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -159,6 +159,10 @@ fn contains_encoded_separator(rest: &str) -> bool {
|
||||
}
|
||||
|
||||
/// Reads `GET /repos/<repo>/releases/latest` (or one element of `/releases`).
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the JSON is malformed or does not describe a usable release.
|
||||
pub fn parse_github_release(json: &str, repo: &str) -> Result<Release, String> {
|
||||
let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?;
|
||||
release_from_value(&v, repo)
|
||||
@@ -166,6 +170,10 @@ pub fn parse_github_release(json: &str, repo: &str) -> Result<Release, String> {
|
||||
|
||||
/// Published releases offered for manual selection, in GitHub's order.
|
||||
/// Drafts and unparseable tags cannot be installed.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the JSON is malformed or its top level is not an array.
|
||||
pub fn parse_github_versions(json: &str, repo: &str) -> Result<Vec<Release>, String> {
|
||||
let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?;
|
||||
let list = v.as_array().ok_or("unexpected answer from GitHub")?;
|
||||
@@ -203,6 +211,10 @@ pub fn choose_version(releases: &[Release], track: &crate::protocol::VersionTrac
|
||||
|
||||
/// Reads `GET /repos/<repo>/releases` and returns the newest stable (or any, with
|
||||
/// `allow_prerelease`) published release.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the JSON is malformed or its top level is not an array.
|
||||
pub fn parse_github_release_list(json: &str, repo: &str, allow_prerelease: bool) -> Result<Option<Release>, String> {
|
||||
let v: serde_json::Value = serde_json::from_str(json).map_err(|e| format!("unreadable answer from GitHub ({e})"))?;
|
||||
let list = v.as_array().ok_or("unexpected answer from GitHub")?;
|
||||
|
||||
@@ -22,7 +22,7 @@ pub enum InstallSource {
|
||||
Pacman,
|
||||
/// A Flatpak.
|
||||
Flatpak,
|
||||
/// An AppImage file found on disk.
|
||||
/// An `AppImage` file found on disk.
|
||||
AppImage,
|
||||
/// A binary found on `PATH` or in a system prefix.
|
||||
Binary,
|
||||
@@ -56,7 +56,7 @@ pub struct Installed {
|
||||
/// `None` when the copy is there but its version couldn't be read.
|
||||
pub version: Option<Version>,
|
||||
pub source: InstallSource,
|
||||
/// Where it lives: the `.app`, the exe, the AppImage, or the binary of a package.
|
||||
/// Where it lives: the `.app`, the exe, the `AppImage`, or the binary of a package.
|
||||
pub location: String,
|
||||
/// The package that installed it, for package-manager installs (`photocraft-bin`).
|
||||
#[serde(default)]
|
||||
|
||||
+15
-15
@@ -36,36 +36,36 @@ pub enum TimeAgo {
|
||||
|
||||
/// Seconds since the Unix epoch for an RFC 3339 UTC timestamp such as `2026-10-08T14:52:50Z`.
|
||||
pub fn parse_rfc3339(text: &str) -> Option<i64> {
|
||||
let b = text.trim().as_bytes();
|
||||
if b.len() < 19 || b.get(4) != Some(&b'-') || b.get(7) != Some(&b'-') || !matches!(b.get(10), Some(b'T' | b't' | b' ')) {
|
||||
let bytes = text.trim().as_bytes();
|
||||
if bytes.len() < 19 || bytes.get(4) != Some(&b'-') || bytes.get(7) != Some(&b'-') || !matches!(bytes.get(10), Some(b'T' | b't' | b' ')) {
|
||||
return None;
|
||||
}
|
||||
let num = |from: usize, to: usize| -> Option<i64> {
|
||||
let s = std::str::from_utf8(b.get(from..to)?).ok()?;
|
||||
if !s.bytes().all(|c| c.is_ascii_digit()) {
|
||||
let slice = std::str::from_utf8(bytes.get(from..to)?).ok()?;
|
||||
if !slice.bytes().all(|c| c.is_ascii_digit()) {
|
||||
return None;
|
||||
}
|
||||
s.parse().ok()
|
||||
slice.parse().ok()
|
||||
};
|
||||
let (y, mo, d) = (num(0, 4)?, num(5, 7)?, num(8, 10)?);
|
||||
let (h, mi, s) = (num(11, 13)?, num(14, 16)?, num(17, 19)?);
|
||||
if !(1..=12).contains(&mo) || !(1..=31).contains(&d) || h > 23 || mi > 59 || s > 60 {
|
||||
let (year, month, day) = (num(0, 4)?, num(5, 7)?, num(8, 10)?);
|
||||
let (hour, minute, second) = (num(11, 13)?, num(14, 16)?, num(17, 19)?);
|
||||
if !(1..=12).contains(&month) || !(1..=31).contains(&day) || hour > 23 || minute > 59 || second > 60 {
|
||||
return None;
|
||||
}
|
||||
// Offsets other than Z: GitHub always sends Z, but honour ±hh:mm if present.
|
||||
let tail = std::str::from_utf8(b.get(19..)?).ok()?;
|
||||
let tail = std::str::from_utf8(bytes.get(19..)?).ok()?;
|
||||
let tail = tail.strip_prefix('.').map_or(tail, |t| t.trim_start_matches(|c: char| c.is_ascii_digit()));
|
||||
let offset = match tail {
|
||||
"" | "Z" | "z" => 0,
|
||||
t if t.len() == 6 && (t.starts_with('+') || t.starts_with('-')) => {
|
||||
let sign = if t.starts_with('-') { -1 } else { 1 };
|
||||
let oh: i64 = t.get(1..3)?.parse().ok()?;
|
||||
let om: i64 = t.get(4..6)?.parse().ok()?;
|
||||
sign * (oh * 3600 + om * 60)
|
||||
let offset_hours: i64 = t.get(1..3)?.parse().ok()?;
|
||||
let offset_minutes: i64 = t.get(4..6)?.parse().ok()?;
|
||||
sign * (offset_hours * 3600 + offset_minutes * 60)
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
Some(days_from_civil(y, mo, d)? * 86_400 + h * 3600 + mi * 60 + s - offset)
|
||||
Some(days_from_civil(year, month, day)? * 86_400 + hour * 3600 + minute * 60 + second - offset)
|
||||
}
|
||||
|
||||
/// Days since 1970-01-01 (through jiff's civil calendar). A day past the month's length rolls over
|
||||
@@ -78,9 +78,9 @@ fn days_from_civil(y: i64, m: i64, d: i64) -> Option<i64> {
|
||||
}
|
||||
|
||||
/// (year, month, day) for a Unix time (UTC). jiff's civil calendar only spans years -9999..=9999,
|
||||
/// far narrower than the whole `i64` the old hand-rolled Hinnant code converted, so the instant is
|
||||
/// far narrower than the whole `i64` the old hand-rolled `Hinnant` code converted, so the instant is
|
||||
/// first moved into range by whole 400-year Gregorian cycles (the calendar repeats every 400 years
|
||||
/// = 146_097 days) and the real year restored afterwards. jiff still does the month/day; the cycle
|
||||
/// = `146_097` days) and the real year restored afterwards. jiff still does the month/day; the cycle
|
||||
/// count only shifts the year, keeping every `i64` exact (e.g. `i64::MAX` → year 292277026596,
|
||||
/// `i64::MIN` → year -292277022657), with no epoch fallback for a value the old code converted.
|
||||
pub fn civil_from_unix(secs: i64) -> (i64, u32, u32) {
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn is_newer(latest: &Version, installed: &Version) -> bool {
|
||||
compare(latest, installed) == Ordering::Greater
|
||||
}
|
||||
|
||||
/// Platforms that only record `X.Y.Z` (the MSI ProductVersion, `CFBundleShortVersionString`)
|
||||
/// Platforms that only record `X.Y.Z` (the MSI `ProductVersion`, `CFBundleShortVersionString`)
|
||||
/// drop a pre-release suffix. A numeric-only installed version therefore counts as current when it
|
||||
/// matches a pre-release's numbers, rather than nagging forever.
|
||||
pub fn is_update(latest: &Version, installed: &Version) -> bool {
|
||||
|
||||
Reference in new issue
Block a user