DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
ThemesSet.rs1use std::sync::Arc;
4
5use serde_json::{Value, json};
6
7use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
8
9pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
10 use CommonLibrary::{
11 Configuration::{
12 ConfigurationProvider::ConfigurationProvider,
13 DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, ConfigurationTarget::ConfigurationTarget},
14 },
15 IPC::SkyEvent::SkyEvent,
16 };
17 use tauri::Emitter;
18
19 let ThemeId = Arguments
20 .first()
21 .and_then(|V| V.as_str())
22 .ok_or("themes:set requires themeId as first argument".to_string())?
23 .to_string();
24
25 RunTime
26 .Environment
27 .UpdateConfigurationValue(
28 "workbench.colorTheme".to_string(),
29 json!(ThemeId),
30 ConfigurationTarget::User,
31 ConfigurationOverridesDTO::default(),
32 None,
33 )
34 .await
35 .map_err(|Error| format!("themes:set failed: {}", Error))?;
36
37 let _ = RunTime
38 .Environment
39 .ApplicationHandle
40 .emit(SkyEvent::ThemeChange.AsStr(), json!({ "themeId": ThemeId }));
41
42 let ThemeKind = if ThemeId.to_ascii_lowercase().contains("light") {
54 if ThemeId.to_ascii_lowercase().contains("high") { 4i32 } else { 1i32 }
55 } else if ThemeId.to_ascii_lowercase().contains("high") {
56 3i32
57 } else {
58 2i32
59 };
60
61 let _ = crate::Vine::Client::SendNotification::Fn(
62 "cocoon-main".to_string(),
63 "$acceptActiveColorTheme".to_string(),
64 json!({ "id": ThemeId, "kind": ThemeKind }),
65 )
66 .await;
67
68 Ok(Value::Null)
69}