Skip to content

Commit

Permalink
chore: init icons in background during start (#176)
Browse files Browse the repository at this point in the history
* chore: init icons in background during start

* chore: update release notes
  • Loading branch information
medcl authored Feb 24, 2025
1 parent 65d1e05 commit 7731008
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/content.en/docs/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ThemeChangedPayload>(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::<ThemeChangedPayload>(event.payload()) {
// // switch_tray_icon(app.app_handle(), payload.is_dark_mode);
// println!("Theme changed: is_dark_mode = {}", payload.is_dark_mode);
// }
// });

#[cfg(desktop)]
{
Expand All @@ -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();
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/local/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand Down
26 changes: 2 additions & 24 deletions src-tauri/src/server/datasource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn save_datasource_to_cache(server_id: &str, datasources: Vec<DataSource>) {

pub fn get_datasources_from_cache(server_id: &str) -> Option<HashMap<String, DataSource>> {
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())
}
Expand Down Expand Up @@ -89,7 +89,6 @@ pub async fn get_datasources_by_server<R: Runtime>(
_app_handle: AppHandle<R>,
id: String,
) -> Result<Vec<DataSource>, String> {
// dbg!("get_datasources_by_server: id = {}", &id);

// Perform the async HTTP request outside the cache lock
let resp = HttpClient::get(&id, "/datasource/_search")
Expand All @@ -101,31 +100,10 @@ pub async fn get_datasources_by_server<R: Runtime>(

// Parse the search results from the response
let datasources: Vec<DataSource> = 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<Connector> into HashMap<String, Connector>
// let connectors_map: HashMap<String, Connector> = 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());

Expand Down
3 changes: 0 additions & 3 deletions src-tauri/src/server/http_client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7731008

Please sign in to comment.