Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Command/TreeView/
RefreshTreeView.rs

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