Skip to content

Commit

Permalink
refacto setup hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph committed Nov 3, 2023
1 parent f397fc1 commit 956433f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn main() {
.setup(|app| {
tauri::async_runtime::block_on(async move {
let default_registry = Registry {
url: "https://raw.githubusercontent.com/premAI-io/prem-registry/dev/manifests.json".to_string(),
url: "https://raw.githubusercontent.com/premAI-io/prem-registry/v1/manifests.json".to_string(),
};

//Create a store with default registry if doesn't exist
Expand All @@ -282,18 +282,26 @@ fn main() {
.expect("failed to resolve app data dir")
.join("store.json");
if !store_path.exists() {
// Create store with keys and empty values
let mut registries: Vec<Registry> = Vec::new();
registries.push(default_registry);
let mut default_store = HashMap::new();
default_store.insert("registries".to_string(), serde_json::to_value(Vec::<Registry>::new()).unwrap());
default_store.insert("registries".to_string(), serde_json::to_value(registries).unwrap());
let store = StoreBuilder::new(app.handle(), store_path.clone()).defaults(default_store).build();
store.save().expect("failed to save store");
// Add default registry to store and fetch services
controller_binaries::add_registry(default_registry, app.handle(), app.state())
.await
.unwrap_or_default();
log::info!("Store created");
} else {
log::info!("Store already created");
}
// Fetch all registries
let mut store = StoreBuilder::new(app.handle(), store_path.clone()).build();
store.load().expect("Failed to load store");
if let Some(registries) = store.get("registries").cloned() {
match serde_json::from_value::<Vec<Registry>>(registries) {
Ok(registries) => {
utils::fetch_all_services_manifests(&registries, &app.state::<Arc<SharedState>>().clone())
.await
.expect("failed to fetch services")
}
Err(e) => println!("Error unwrapping registries: {:?}", e),
}
}
});
Ok(())
Expand Down

0 comments on commit 956433f

Please sign in to comment.