Skip to main content

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};
9use ::Vine::Generated::{Empty, SetStatusBarTextRequest};
10
11use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
12
13pub async fn Fn(Service:&CocoonServiceImpl, Request:SetStatusBarTextRequest) -> Result<Response<Empty>, Status> {
14	dev_log!(
15		"cocoon",
16		"[CocoonService] set_status_bar_text: id={} text={}",
17		Request.item_id,
18		Request.text
19	);
20
21	let Entry = StatusBarEntryDTO {
22		EntryIdentifier:Request.item_id.clone(),
23
24		ItemIdentifier:Request.item_id.clone(),
25
26		ExtensionIdentifier:String::new(),
27
28		Name:None,
29
30		Text:Request.text.clone(),
31
32		Tooltip:None,
33
34		HasTooltipProvider:false,
35
36		Command:None,
37
38		Color:None,
39
40		BackgroundColor:None,
41
42		IsAlignedLeft:true,
43
44		Priority:None,
45
46		AccessibilityInformation:None,
47	};
48
49	if let Err(Error) = Service.environment.SetStatusBarEntry(Entry).await {
50		dev_log!("cocoon", "warn: [CocoonService] set_status_bar_text trait failed: {}", Error);
51
52		let _ = Service
53			.environment
54			.ApplicationHandle
55			.emit("sky://statusbar/update", json!({ "id": Request.item_id, "text": Request.text }));
56	}
57
58	Ok(Response::new(Empty {}))
59}