Skip to main content

Mountain/IPC/WindServiceHandlers/UI/
DecorationsGet.rs

1//! Wire method: `decorations:get`.
2//! Reads a URI decoration from cache, then falls back to a registered
3//! FileDecoration provider via Cocoon gRPC.
4
5use std::sync::Arc;
6
7use serde_json::Value;
8use CommonLibrary::LanguageFeature::LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry;
9
10use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
11
12pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13	let Uri = Arguments
14		.first()
15		.and_then(|V| V.as_str())
16		.ok_or("decorations:get requires uri".to_string())?;
17
18	if let Some(Cached) = RunTime.Environment.ApplicationState.Feature.Decorations.GetDecoration(Uri) {
19		return Ok(Cached);
20	}
21
22	if let Ok(ParsedUri) = url::Url::parse(Uri) {
23		match RunTime.Environment.ProvideFileDecoration(ParsedUri).await {
24			Ok(Some(Result)) => {
25				RunTime
26					.Environment
27					.ApplicationState
28					.Feature
29					.Decorations
30					.SetDecoration(Uri, Result.clone());
31
32				return Ok(Result);
33			},
34
35			Ok(None) => {},
36
37			Err(E) => {
38				crate::dev_log!("decorations", "warn: [DecorationsGet] provider error for {}: {}", Uri, E);
39			},
40		}
41	}
42
43	Ok(Value::Null)
44}