Mountain/Command/TreeView/
RefreshTreeView.rs1
2use std::sync::Arc;
6
7use CommonLibrary::TreeView::TreeViewProvider::TreeViewProvider;
8use serde_json::{Value, json};
9use tauri::{AppHandle, Manager, State, Wry, command};
10
11use crate::{
12 ApplicationState::State::ApplicationState::ApplicationState,
13 Environment::MountainEnvironment::MountainEnvironment,
14 RunTime::ApplicationRunTime::ApplicationRunTime,
15 dev_log,
16};
17
18#[command]
19pub async fn RefreshTreeView(
20 ApplicationHandle:AppHandle<Wry>,
21
22 _State:State<'_, Arc<ApplicationState>>,
23
24 ViewId:String,
25
26 ItemsToRefresh:Option<Vec<String>>,
27) -> Result<Value, String> {
28 dev_log!("commands", "refreshing tree view '{}', items: {:?}", ViewId, ItemsToRefresh);
29
30 let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
31
32 let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
33
34 let RefreshValue:Option<Value> = ItemsToRefresh.and_then(|items| serde_json::to_value(items).ok());
35
36 match Environment.RefreshTreeView(ViewId.clone(), RefreshValue).await {
37 Ok(_) => Ok(json!({ "success": true })),
38
39 Err(Error) => {
40 let ErrorMessage = format!("Failed to refresh tree view '{}': {}", ViewId, Error);
41
42 dev_log!("commands", "error: {}", ErrorMessage);
43
44 Err(ErrorMessage)
45 },
46 }
47}