feat: start checks

This commit is contained in:
2025-03-16 17:55:38 +00:00
parent 08d6a2a2fe
commit 8d55e92fc9
26 changed files with 456 additions and 211 deletions

View File

@ -12,9 +12,9 @@ use crate::download_handler::DownloadHandler;
pub struct PackageStore {
store: HashMap<PkgKey, Package>,
has_fetched: bool,
app: AppHandle,
dlh: DownloadHandler
dlh: DownloadHandler,
offline: bool,
}
#[derive(Clone, Serialize, Deserialize)]
@ -31,9 +31,9 @@ impl PackageStore {
pub fn new(app: AppHandle) -> PackageStore {
PackageStore {
store: HashMap::new(),
has_fetched: false,
app: app.clone(),
dlh: DownloadHandler::new(app)
dlh: DownloadHandler::new(app),
offline: true
}
}
@ -75,11 +75,7 @@ impl PackageStore {
Ok(())
}
pub async fn fetch_listings(&mut self) -> Result<()> {
if self.has_fetched {
return Ok(());
}
pub async fn fetch_listings() -> Result<Vec<rainy::V1Package>> {
use async_compression::futures::bufread::GzipDecoder;
use futures::{
io::{self, BufReader, ErrorKind},
@ -87,6 +83,7 @@ impl PackageStore {
};
let response = reqwest::get("https://rainy.patafour.zip/c/ongeki/api/v1/package/").await?;
let reader = response
.bytes_stream()
.map_err(|e| io::Error::new(ErrorKind::Other, e))
@ -96,9 +93,14 @@ impl PackageStore {
let mut data = String::new();
decoder.read_to_string(&mut data).await?;
let listings: Vec<rainy::V1Package> = serde_json::from_str(&data)
.expect("Invalid JSON");
Ok(serde_json::from_str(&data)?)
}
pub fn is_offline(&self) -> bool {
self.offline
}
pub fn process_fetched_listings(&mut self, listings: Vec<rainy::V1Package>) {
for listing in listings {
// This is None if the package has no versions for whatever reason
if let Some(r) = Package::from_rainy(listing) {
@ -114,9 +116,7 @@ impl PackageStore {
}
}
self.has_fetched = true;
Ok(())
self.offline = false;
}
pub async fn install_package(&mut self, key: &PkgKey, force: bool, install_deps: bool) -> Result<InstallResult> {