mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-26 11:18:38 +00:00
feat: function to check for updates
This commit is contained in:
parent
096cc888b2
commit
6f142d9ee5
7 changed files with 68 additions and 2 deletions
|
@ -30,3 +30,6 @@ openxr = { git = "https://github.com/galister/openxrs", rev = "af4a55d", feature
|
|||
ash = "0.38.0"
|
||||
sha2 = "0.10.8"
|
||||
tokio = { version = "1.39.3", features = ["process"] }
|
||||
|
||||
[features]
|
||||
appimage = []
|
||||
|
|
2
dist/appimage/build_appimage.sh
vendored
2
dist/appimage/build_appimage.sh
vendored
|
@ -7,7 +7,7 @@ if [[ ! -f Cargo.toml ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
meson setup appimage_build -Dprefix=/usr -Dprofile=default
|
||||
meson setup appimage_build -Dprefix=/usr -Dprofile=default -Dappimage=true
|
||||
DESTDIR="$PWD/AppDir" ninja -C appimage_build install
|
||||
curl -SsLO https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
|
||||
chmod +x linuxdeploy-x86_64.AppImage
|
||||
|
|
|
@ -8,3 +8,9 @@ option(
|
|||
value: 'default',
|
||||
description: 'The build profile. One of "default" or "development".'
|
||||
)
|
||||
option(
|
||||
'appimage',
|
||||
type: 'boolean',
|
||||
value: false,
|
||||
description: 'Enable AppImage specific features.'
|
||||
)
|
||||
|
|
|
@ -25,7 +25,7 @@ fn sync_client() -> reqwest::blocking::Client {
|
|||
.expect("Failed to build reqwest::blocking::Client")
|
||||
}
|
||||
|
||||
fn async_client() -> reqwest::Client {
|
||||
pub fn async_client() -> reqwest::Client {
|
||||
reqwest::Client::builder()
|
||||
.timeout(TIMEOUT)
|
||||
.default_headers(headers())
|
||||
|
|
|
@ -44,6 +44,9 @@ pub mod vulkaninfo;
|
|||
pub mod xdg;
|
||||
pub mod xr_devices;
|
||||
|
||||
#[cfg(feature = "appimage")]
|
||||
pub mod updater;
|
||||
|
||||
fn restore_steam_xr_files() {
|
||||
let active_runtime = get_current_active_runtime();
|
||||
let openvrpaths = get_current_openvrpaths();
|
||||
|
|
|
@ -23,6 +23,16 @@ else
|
|||
message('Building in debug mode')
|
||||
endif
|
||||
|
||||
features = []
|
||||
|
||||
if get_option('appimage') == true
|
||||
features += 'appimage'
|
||||
endif
|
||||
|
||||
if features.length() > 0
|
||||
cargo_options += ['--features', ','.join(features)]
|
||||
endif
|
||||
|
||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||
|
||||
cargo_build = custom_target(
|
||||
|
|
44
src/updater.rs
Normal file
44
src/updater.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use anyhow::bail;
|
||||
use reqwest::Method;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{constants::VERSION, downloader::async_client};
|
||||
|
||||
const GITLAB_PROJ_ID: &str = "46446166";
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
struct GitLabCommit {
|
||||
id: String,
|
||||
}
|
||||
|
||||
type GitLabCommitList = Vec<GitLabCommit>;
|
||||
|
||||
pub async fn check_updates_available() -> anyhow::Result<bool> {
|
||||
let client = async_client();
|
||||
if VERSION.contains("-") {
|
||||
// dev releases, check commits
|
||||
let shorthash = VERSION.split('-').last().unwrap_or_default();
|
||||
let url = format!(
|
||||
"https://gitlab.com/api/v4/projects/{GITLAB_PROJ_ID}/repository/commits?ref_name=main"
|
||||
);
|
||||
let res = client.request(Method::GET, url).send().await?;
|
||||
match res.error_for_status() {
|
||||
Err(e) => Err(e.into()),
|
||||
Ok(res) => {
|
||||
let text = res.text().await?;
|
||||
let commit_list: GitLabCommitList = serde_json::from_str(&text)?;
|
||||
if commit_list
|
||||
.get(0)
|
||||
.is_some_and(|c| c.id.starts_with(shorthash))
|
||||
{
|
||||
Ok(false)
|
||||
} else {
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// stable releases, check tags
|
||||
bail!("Not implemented yet!")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue