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