Some checks are pending
Release Multiplatform Binaries / build (deb,appimage, linux-x86_64, ubuntu-22.04, x86_64-unknown-linux-gnu) (push) Waiting to run
Release Multiplatform Binaries / build (dmg,app, macos-arm64, macos-14, aarch64-apple-darwin) (push) Waiting to run
Release Multiplatform Binaries / build (dmg,app, macos-x86_64, macos-14, x86_64-apple-darwin) (push) Waiting to run
Release Multiplatform Binaries / build (nsis, windows-x86_64, windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Release Multiplatform Binaries / create-release (push) Blocked by required conditions
- Rebased onto official Polyfrost OneLauncher v2.3.1 (commit 0e49c691)
- Preserved 100% offline authentication without requiring Microsoft accounts
- Integrated custom 3D offline skin changer with UUID character slot targeting
- Maintained CustomSkinLoader auto-configuration for Ely.by and SkinRestorer
- Maintained direct GitHub Releases auto-updater pointing to oiupoyt/OneLauncher-Cracked
- Maintained mods filter popover fix eliminating text ghosting/duplication
- Configured dev profile to prevent debug symbol bloat
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use std::time::Duration;
|
|
|
|
use bytes::Bytes;
|
|
use freya::query::{Query, QueryCapability, UseQuery, use_query};
|
|
use oneclient_core::LauncherError;
|
|
|
|
const IMAGE_STALE: Duration = Duration::from_secs(60 * 60);
|
|
const IMAGE_CLEAN: Duration = Duration::from_secs(6 * 60 * 60);
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub struct CachedImageQuery;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
|
pub struct CachedImageKeys {
|
|
pub url: String,
|
|
pub max_edge: u32,
|
|
}
|
|
|
|
impl QueryCapability for CachedImageQuery {
|
|
type Ok = Bytes;
|
|
type Err = LauncherError;
|
|
type Keys = CachedImageKeys;
|
|
|
|
#[tracing::instrument(name = "cached_image", level = "debug", skip(self, keys), fields(url = %keys.url, max_edge = keys.max_edge))]
|
|
async fn run(&self, keys: &Self::Keys) -> Result<Self::Ok, Self::Err> {
|
|
if keys.url.is_empty() {
|
|
return Err(LauncherError::Minecraft("no image url".to_string()));
|
|
}
|
|
|
|
let state = crate::launcher::state()?;
|
|
state
|
|
.images
|
|
.get(&state.services.requester, &keys.url, keys.max_edge)
|
|
.await
|
|
}
|
|
}
|
|
|
|
/// Returns the url alongside the bytes callers key their image handle on it
|
|
/// and a stale url with fresh bytes renders the wrong picture for a frame
|
|
pub fn loaded_image(url: Option<&str>, query: &UseQuery<CachedImageQuery>) -> Option<(String, Bytes)> {
|
|
let url = url?;
|
|
let bytes = super::state::settled_or_loading(query)?;
|
|
Some((url.to_string(), bytes))
|
|
}
|
|
|
|
pub fn use_cached_image(url: Option<String>, max_edge: u32) -> UseQuery<CachedImageQuery> {
|
|
let url = url.unwrap_or_default();
|
|
let keys = (!url.is_empty()).then_some(CachedImageKeys { url, max_edge });
|
|
|
|
use_query(
|
|
Query::new(keys, CachedImageQuery)
|
|
.stale_time(IMAGE_STALE)
|
|
.clean_time(IMAGE_CLEAN),
|
|
)
|
|
}
|