Mountain/Command/
TreeView.rs1#![allow(non_snake_case, non_camel_case_types)]
7
8use std::sync::Arc;
9
10use Common::{Environment::Requires::Requires, TreeView::TreeViewProvider::TreeViewProvider as CommonTreeViewProvider};
11use serde_json::{Value, json};
12use tauri::{AppHandle, Manager, State, Wry, command};
13
14use crate::{
15 ApplicationState::ApplicationState::ApplicationState,
16 Environment::MountainEnvironment::MountainEnvironment,
17 RunTime::ApplicationRunTime::ApplicationRunTime,
18};
19
20#[command]
24pub async fn GetTreeViewChildren(
25 ApplicationHandle:AppHandle<Wry>,
26
27 _State:State<'_, Arc<ApplicationState>>,
28
29 ViewId:String,
30
31 ElementHandle:Option<String>,
32) -> Result<Value, String> {
33 log::debug!(
34 "[DispatchLogic] Getting TreeView children for '{}', element: {:?}",
35 ViewId,
36 ElementHandle
37 );
38
39 let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
40
41 let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
42
43 let TreeProvider:Arc<dyn CommonTreeViewProvider> = Environment.Require();
44
45 match TreeProvider.GetChildren(ViewId, ElementHandle).await {
46 Ok(Children) => Ok(json!(Children)),
47
48 Err(Error) => {
49 let ErrorMessage = format!("Failed to get children for tree view: {}", Error);
50
51 log::error!("{}", ErrorMessage);
52
53 Err(ErrorMessage)
54 },
55 }
56}