Skip to main content

Mountain/RPC/CocoonService/Window/
SetStatusBarText.rs

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