Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/UI/
ThemesSet.rs

1//! Wire method: `themes:set`.
2
3use 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	// Dual-emit to Cocoon so `vscode.window.onDidChangeActiveColorTheme`
43	// subscribers fire inside the Node extension host. Without this, the
44	// `sky://theme/change` Tauri emit above only reaches the renderer;
45	// Node-resident extensions (GitLens, Roo, rust-analyzer) that adapt
46	// their UI based on theme.kind never see the change. Cocoon's
47	// `Services/Handler/Notification/Handler.ts` maps
48	// `$acceptActiveColorTheme` → `Emitter.emit("window.didChangeActiveColorTheme",
49	// ...)` which `Window/Namespace.ts:1041` subscribers attach to via
50	// `MakeEventSubscriber`. Payload includes the workbench's theme kind
51	// (1=Light, 2=Dark, 3=HighContrast, 4=HighContrastLight) when
52	// discoverable from the theme id, otherwise just the id.
53	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}