Skip to main content

Mountain/RPC/CocoonService/Window/
CreateStatusBarItem.rs

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