Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Window/
CreateStatusBarItem.rs

1//! Register a status-bar entry through the `StatusBarProvider` trait so
2//! the entry lives in
3//! `ApplicationState::Feature::Markers::ActiveStatusBarItems`. Without this
4//! registration the workbench has no memory of the entry and
5//! the first `SetStatusBarText::Fn` call rebroadcasts a fresh entry
6//! (state leak). Falls back to a direct Sky emit on trait failure.
7
8use serde_json::json;
9use tauri::Emitter;
10use tonic::{Response, Status};
11use CommonLibrary::StatusBar::{DTO::StatusBarEntryDTO::StatusBarEntryDTO, StatusBarProvider::StatusBarProvider};
12
13use crate::{
14	RPC::CocoonService::CocoonServiceImpl,
15	Vine::Generated::{CreateStatusBarItemRequest, CreateStatusBarItemResponse},
16	dev_log,
17};
18
19pub async fn Fn(
20	Service:&CocoonServiceImpl,
21
22	Request:CreateStatusBarItemRequest,
23) -> Result<Response<CreateStatusBarItemResponse>, Status> {
24	dev_log!("cocoon", "[CocoonService] create_status_bar_item: {}", Request.id);
25
26	let Entry = StatusBarEntryDTO {
27		EntryIdentifier:Request.id.clone(),
28
29		ItemIdentifier:Request.id.clone(),
30
31		ExtensionIdentifier:String::new(),
32
33		Name:None,
34
35		Text:Request.text.clone(),
36
37		Tooltip:if Request.tooltip.is_empty() { None } else { Some(json!(Request.tooltip)) },
38
39		HasTooltipProvider:false,
40
41		Command:None,
42
43		Color:None,
44
45		BackgroundColor:None,
46
47		IsAlignedLeft:true,
48
49		Priority:None,
50
51		AccessibilityInformation:None,
52	};
53
54	if let Err(Error) = Service.environment.SetStatusBarEntry(Entry).await {
55		dev_log!("cocoon", "warn: [CocoonService] create_status_bar_item trait failed: {}", Error);
56
57		let _ = Service.environment.ApplicationHandle.emit(
58			"sky://statusbar/create",
59			json!({ "id": Request.id, "text": Request.text, "tooltip": Request.tooltip }),
60		);
61	}
62
63	Ok(Response::new(CreateStatusBarItemResponse { item_id:Request.id.clone() }))
64}