DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
Theme.rs1#![allow(non_snake_case, unused_variables)]
2use std::sync::Arc;
10
11use CommonLibrary::IPC::SkyEvent::SkyEvent;
12use serde_json::{Value, json};
13
14use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
15
16pub async fn ThemesGetActive(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
17 use CommonLibrary::Configuration::{
18 ConfigurationProvider::ConfigurationProvider,
19 DTO::ConfigurationOverridesDTO::ConfigurationOverridesDTO,
20 };
21
22 let ThemeId = RunTime
23 .Environment
24 .GetConfigurationValue(Some("workbench.colorTheme".to_string()), ConfigurationOverridesDTO::default())
25 .await
26 .map_err(|Error| format!("themes:getActive failed: {}", Error))?;
27
28 let Id = ThemeId.as_str().unwrap_or("Default Dark Modern").to_string();
29
30 let (Kind, TypeNum) = if Id.to_lowercase().contains("high contrast light") {
34 ("highContrastLight", 4u8)
35 } else if Id.to_lowercase().contains("high contrast") {
36 ("highContrast", 3u8)
37 } else if Id.to_lowercase().contains("light") {
38 ("light", 1u8)
39 } else {
40 ("dark", 2u8)
41 };
42
43 Ok(json!({
44 "id": Id,
45 "label": Id,
46 "kind": Kind,
48 "type": TypeNum,
52 "semanticHighlighting": false,
55 }))
56}
57
58pub async fn ThemesList(_runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
59 let Themes = vec![
60 json!({ "id": "Default Dark Modern", "label": "Default Dark Modern", "kind": "dark" }),
61 json!({ "id": "Default Light Modern", "label": "Default Light Modern", "kind": "light" }),
62 json!({ "id": "Default Dark+", "label": "Default Dark+", "kind": "dark" }),
63 json!({ "id": "Default Light+", "label": "Default Light+", "kind": "light" }),
64 json!({ "id": "High Contrast", "label": "High Contrast", "kind": "highContrast" }),
65 json!({ "id": "High Contrast Light", "label": "High Contrast Light", "kind": "highContrastLight" }),
66 ];
67
68 Ok(json!(Themes))
69}
70
71pub async fn ThemesSet(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
72 use CommonLibrary::Configuration::{
73 ConfigurationProvider::ConfigurationProvider,
74 DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, ConfigurationTarget::ConfigurationTarget},
75 };
76 use tauri::Emitter;
77
78 let ThemeId = Arguments
79 .first()
80 .and_then(|V| V.as_str())
81 .ok_or("themes:set requires themeId as first argument".to_string())?
82 .to_string();
83
84 RunTime
85 .Environment
86 .UpdateConfigurationValue(
87 "workbench.colorTheme".to_string(),
88 json!(ThemeId),
89 ConfigurationTarget::User,
90 ConfigurationOverridesDTO::default(),
91 None,
92 )
93 .await
94 .map_err(|Error| format!("themes:set failed: {}", Error))?;
95
96 let _ = RunTime
97 .Environment
98 .ApplicationHandle
99 .emit(SkyEvent::ThemeChange.AsStr(), json!({ "themeId": ThemeId }));
100
101 Ok(Value::Null)
102}