Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Window/
SetStatusBarText.rs

1//! Update the text of a status-bar entry. Re-issues `SetStatusBarEntry`
2//! so the stored DTO's `Text` field is refreshed in
3//! `ActiveStatusBarItems` (HashMap insert acts as create-or-update).
4
5use serde_json::json;
6use tauri::Emitter;
7use tonic::{Response, Status};
8use CommonLibrary::StatusBar::{DTO::StatusBarEntryDTO::StatusBarEntryDTO, StatusBarProvider::StatusBarProvider};
9
10use crate::{
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{Empty, SetStatusBarTextRequest},
13	dev_log,
14};
15
16pub async fn Fn(Service:&CocoonServiceImpl, Request:SetStatusBarTextRequest) -> Result<Response<Empty>, Status> {
17	dev_log!(
18		"cocoon",
19		"[CocoonService] set_status_bar_text: id={} text={}",
20		Request.item_id,
21		Request.text
22	);
23
24	let Entry = StatusBarEntryDTO {
25		EntryIdentifier:Request.item_id.clone(),
26
27		ItemIdentifier:Request.item_id.clone(),
28
29		ExtensionIdentifier:String::new(),
30
31		Name:None,
32
33		Text:Request.text.clone(),
34
35		Tooltip:None,
36
37		HasTooltipProvider:false,
38
39		Command:None,
40
41		Color:None,
42
43		BackgroundColor:None,
44
45		IsAlignedLeft:true,
46
47		Priority:None,
48
49		AccessibilityInformation:None,
50	};
51
52	if let Err(Error) = Service.environment.SetStatusBarEntry(Entry).await {
53		dev_log!("cocoon", "warn: [CocoonService] set_status_bar_text trait failed: {}", Error);
54
55		let _ = Service
56			.environment
57			.ApplicationHandle
58			.emit("sky://statusbar/update", json!({ "id": Request.item_id, "text": Request.text }));
59	}
60
61	Ok(Response::new(Empty {}))
62}