diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index 5109ef5..20aabfd 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -19,6 +19,7 @@ Information about release notes of Coco Server is provided here. ### Improvements - Improve app startup, init application search in background #172 - Refactoring login #173 +- Init icons in background during start #176 ## 0.1.0 (2015-02-16) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 6bd2a91..92337c3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -134,12 +134,12 @@ pub fn run() { #[cfg(target_os = "macos")] app.set_activation_policy(ActivationPolicy::Accessory); - app.listen("theme-changed", move |event| { - if let Ok(payload) = serde_json::from_str::(event.payload()) { - // switch_tray_icon(app.app_handle(), payload.is_dark_mode); - println!("Theme changed: is_dark_mode = {}", payload.is_dark_mode); - } - }); + // app.listen("theme-changed", move |event| { + // if let Ok(payload) = serde_json::from_str::(event.payload()) { + // // switch_tray_icon(app.app_handle(), payload.is_dark_mode); + // println!("Theme changed: is_dark_mode = {}", payload.is_dark_mode); + // } + // }); #[cfg(desktop)] { @@ -151,9 +151,9 @@ pub fn run() { } } - app.deep_link().on_open_url(|event| { - dbg!(event.urls()); - }); + // app.deep_link().on_open_url(|event| { + // dbg!(event.urls()); + // }); let main_window = app.get_webview_window(MAIN_WINDOW_LABEL).unwrap(); let settings_window = app.get_webview_window(SETTINGS_WINDOW_LABEL).unwrap(); @@ -173,11 +173,14 @@ pub fn run() { .build(ctx) .expect("error while running tauri application"); + // Create a single Tokio runtime instance let rt = RT::new().expect("Failed to create Tokio runtime"); let app_handle = app.handle().clone(); rt.spawn(async move { init_app_search_source(&app_handle).await; + let _ = server::connector::refresh_all_connectors(&app_handle).await; + let _ = server::datasource::refresh_all_datasources(&app_handle).await; }); app.run(|app_handle, event| match event { diff --git a/src-tauri/src/local/application.rs b/src-tauri/src/local/application.rs index 0b81401..5391cdf 100644 --- a/src-tauri/src/local/application.rs +++ b/src-tauri/src/local/application.rs @@ -250,7 +250,7 @@ impl ApplicationSearchSource { .to_lowercase(); // to_lowercase returns a String, which is owned //TODO, replace this hard-coded name to actual local app name in case it may change - if search_word.is_empty() || search_word.eq("coco ai") { + if search_word.is_empty() || search_word.eq("coco-ai") { continue; } @@ -353,6 +353,8 @@ impl SearchSource for ApplicationSearchSource { // Attach icon if available if let Some(icon_path) = self.icons.get(file_path_str.as_str()) { + // doc.icon = Some(format!("file://{}", icon_path.to_string_lossy())); + // dbg!(&doc.icon); if let Ok(icon_data) = read_icon_and_encode(icon_path) { doc.icon = Some(format!("data:image/png;base64,{}", icon_data)); } diff --git a/src-tauri/src/server/datasource.rs b/src-tauri/src/server/datasource.rs index 0bb1748..773eefb 100644 --- a/src-tauri/src/server/datasource.rs +++ b/src-tauri/src/server/datasource.rs @@ -24,7 +24,7 @@ pub fn save_datasource_to_cache(server_id: &str, datasources: Vec) { pub fn get_datasources_from_cache(server_id: &str) -> Option> { let cache = DATASOURCE_CACHE.read().unwrap(); // Acquire read lock - // dbg!("cache: {:?}", &cache); + // dbg!("cache: {:?}", &cache); let server_cache = cache.get(server_id)?; // Get the server's cache Some(server_cache.clone()) } @@ -89,7 +89,6 @@ pub async fn get_datasources_by_server( _app_handle: AppHandle, id: String, ) -> Result, String> { - // dbg!("get_datasources_by_server: id = {}", &id); // Perform the async HTTP request outside the cache lock let resp = HttpClient::get(&id, "/datasource/_search") @@ -101,31 +100,10 @@ pub async fn get_datasources_by_server( // Parse the search results from the response let datasources: Vec = parse_search_results(resp).await.map_err(|e| { - // dbg!("Error parsing search results: {}", &e); + dbg!("Error parsing search results: {}", &e); e.to_string() })?; - // let connectors=fetch_connectors_by_server(id.as_str()).await?; - // - // // Convert the Vec into HashMap - // let connectors_map: HashMap = connectors - // .into_iter() - // .map(|connector| (connector.id.clone(), connector)) // Assuming Connector has an `id` field - // .collect(); - // - // for datasource in datasources.iter_mut() { - // if let Some(connector) = &datasource.connector { - // if let Some(connector_id) = connector.id.as_ref() { - // if let Some(existing_connector) = connectors_map.get(connector_id) { - // // If found in cache, update the connector's info - // datasource.connector_info = Some(existing_connector.clone()); - // } - // } - // } - // } - - // dbg!("Parsed datasources: {:?}", &datasources); - // Save the updated datasources to cache save_datasource_to_cache(&id, datasources.clone()); diff --git a/src-tauri/src/server/http_client.rs b/src-tauri/src/server/http_client.rs index d1956e9..89e5fd2 100644 --- a/src-tauri/src/server/http_client.rs +++ b/src-tauri/src/server/http_client.rs @@ -1,7 +1,4 @@ -// use lazy_static::lazy_static; -// use tauri::AppHandle; use crate::server::servers::{get_server_by_id, get_server_token}; -// use std::future::Future; use std::time::Duration; use once_cell::sync::Lazy;