DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Model/
TextfileWrite.rs1use std::sync::Arc;
7
8use serde_json::{Value, json};
9
10use crate::{
11 IPC::WindServiceHandlers::Utilities::JsonValueHelpers::arg_string,
12 RunTime::ApplicationRunTime::ApplicationRunTime,
13 dev_log,
14};
15
16pub async fn Fn(_runtime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
17 let Path = Arguments
18 .first()
19 .and_then(|V| V.as_str())
20 .ok_or_else(|| "textFile:write requires path as first argument".to_string())?
21 .to_string();
22
23 let Content = arg_string(&Arguments, 1);
24
25 tokio::fs::write(&Path, Content.as_bytes())
26 .await
27 .map_err(|Error| format!("textFile:write failed: {}", Error))?;
28
29 dev_log!("vfs", "textFile:write ok path={} bytes={}", Path, Content.len());
30
31 let FileUri = format!("file://{}", Path);
38
39 tokio::spawn(async move {
40 if let Err(Error) = crate::Vine::Client::SendNotification::Fn(
41 "cocoon-main".to_string(),
42 "$acceptModelSaved".to_string(),
43 json!({ "uri": FileUri }),
44 )
45 .await
46 {
47 dev_log!("vfs", "warn: [TextfileWrite] $acceptModelSaved notify failed: {:?}", Error);
48 }
49 });
50
51 Ok(Value::Null)
52}