Skip to content

Commit

Permalink
Merge branch 'main' into feat/petals-services-python
Browse files Browse the repository at this point in the history
  • Loading branch information
filopedraz authored Nov 4, 2023
2 parents 9fa393b + a29c188 commit d726a72
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,17 @@ fn main() {
})
.setup(|app| {
tauri::async_runtime::block_on(async move {
// Determine the URL based on whether the app is in debug or release mode
let url = if cfg!(debug_assertions) {
// Debug mode URL
"https://raw.githubusercontent.com/premAI-io/prem-registry/dev/manifests.json"
} else {
// Release mode URL
"https://raw.githubusercontent.com/premAI-io/prem-registry/v1/manifests.json"
};

utils::fetch_services_manifests(
"https://raw.githubusercontent.com/premAI-io/prem-registry/dev/manifests.json",
url,
app.state::<Arc<SharedState>>().deref().clone(),
)
.await
Expand Down
83 changes: 78 additions & 5 deletions src-tauri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,90 @@ pub fn get_binary_url(binaries_url: &HashMap<String, Option<String>>) -> Result<
err!("Unsupported OS")
} else if is_macos() {
if is_x86_64() {
binaries_url.get("x86_64-apple-darwin")
binaries_url.get("x86_64-apple-darwin").cloned().flatten()
} else if is_aarch64() {
binaries_url.get("aarch64-apple-darwin")
binaries_url.get("aarch64-apple-darwin").cloned().flatten()
} else {
err!("Unsupported architecture")
}
.or_else(|| binaries_url.get("universal-apple-darwin"))
.with_context(|| "No binary available for platform")?
.clone()
.or_else(|| {
binaries_url
.get("universal-apple-darwin")
.cloned()
.flatten()
})
.with_context(|| "Service not supported on your platform")
} else {
err!("Unsupported platform")
}
}

#[cfg(all(test, target_os = "macos"))]
mod tests {
use super::get_binary_url;
use std::collections::HashMap;

#[test]
fn binary_url_test_universal_only() {
let url = get_binary_url(&HashMap::from_iter([(
"universal-apple-darwin".to_string(),
Some("randome_url.com".to_string()),
)]))
.unwrap();
assert_eq!(url, "randome_url.com");
}

#[test]
fn binary_url_test_universal_only_option() {
let url = get_binary_url(&HashMap::from_iter([
(
"universal-apple-darwin".to_string(),
Some("randome_url.com".to_string()),
),
("aarch64-apple-darwin".to_string(), None),
("x86_64-apple-darwin".to_string(), None),
]))
.unwrap();
assert_eq!(url, "randome_url.com");
}

#[test]
fn binary_url_test_with_non_universal() {
let url = get_binary_url(&HashMap::from_iter([
(
"universal-apple-darwin".to_string(),
Some("randome_url.com//universal".to_string()),
),
(
"aarch64-apple-darwin".to_string(),
Some("randome_url.com//not_universal".to_string()),
),
(
"x86_64-apple-darwin".to_string(),
Some("randome_url.com//not_universal".to_string()),
),
]))
.unwrap();
assert_eq!(url, "randome_url.com//not_universal");
}

#[test]
#[should_panic]
fn binary_url_test_empty() {
let url = get_binary_url(&HashMap::from_iter([])).unwrap();
assert_eq!(url, "randome_url.com");
}

#[test]
fn binary_url_all_none() {
let err = get_binary_url(&HashMap::from_iter([
("universal-apple-darwin".to_string(), None),
("aarch64-apple-darwin".to_string(), None),
("x86_64-apple-darwin".to_string(), None),
]));
assert_eq!(
err.err().map(|err| err.to_string()).unwrap_or_default(),
"Service not supported on your platform"
);
}
}

0 comments on commit d726a72

Please sign in to comment.