Switched self-updater to packages, stop creating releases

This commit is contained in:
2023-01-25 16:33:34 +01:00
parent 78f4e0f681
commit 6953d6075c
2 changed files with 11 additions and 52 deletions

View File

@@ -6,37 +6,27 @@ use std::path::Path;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Commit {
id: String
struct Pipeline {
sha: String
}
#[derive(Debug, Deserialize)]
struct Link {
direct_asset_url: String
}
#[derive(Debug, Deserialize)]
struct Assets {
links: Vec<Link>
}
#[derive(Debug, Deserialize)]
struct ReleaseEntry {
commit: Commit,
assets: Assets
struct PackageEntry {
version: String,
pipeline: Pipeline
}
pub fn check_for_updates(version: &str) {
print!("Checking for updates... ");
let resp: Vec<ReleaseEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/releases").send().unwrap().json().unwrap();
let resp: Vec<PackageEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap();
let newest = resp.first().unwrap();
if newest.commit.id != version {
if newest.pipeline.sha != version {
println!("New version exists");
let exe = current_exe().unwrap();
let temp = Path::new("temp");
print!("Downloading... ");
attohttpc::get(newest.assets.links.first().unwrap().direct_asset_url.clone()).send().unwrap().write_to(File::create(temp).unwrap()).unwrap();
attohttpc::get(format!("https://gitlab.mattv.de/api/v4/projects/43/packages/generic/installer/{}/installer-amd64", newest.version)).send().unwrap().write_to(File::create(temp).unwrap()).unwrap();
println!("Done");
fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();