Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
Theme.rs

1#![allow(non_snake_case, unused_variables)]
2//! Theme IPC handlers. `themes:getActive` / `themes:list` / `themes:set`
3//! drive the workbench's colour-theme picker and the RunTime theme swap.
4//!
5//! Source of truth: `workbench.colorTheme` inside `ConfigurationProvider`.
6//! A `themes:set` writes the key and emits `SkyEvent::ThemeChange` so
7//! Monaco and the Sky shell re-tint in-place without a window reload.
8
9use 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	// Infer kind from id string.
31	// `ColorThemeKind` numeric values from VS Code:
32	//   Light = 1, Dark = 2, HighContrast = 3, HighContrastLight = 4
33	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` is the string variant used by Land's own UI layer.
47		"kind": Kind,
48		// `type` is the numeric `ColorThemeKind` enum that VS Code's
49		// workbench (`ThemeService`, `TokenizationRegistry`) reads to decide
50		// syntax highlighting colour sets.
51		"type": TypeNum,
52		// Minimal tokenization / color fields; workbench falls back to
53		// built-in defaults for missing entries.
54		"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}