Skip to main content

Mountain/RPC/CocoonService/Window/
SetStatusBarText.rs

1#![allow(non_snake_case)]
2
3//! Update the text of a status-bar entry. Re-issues `SetStatusBarEntry`
4//! so the stored DTO's `Text` field is refreshed in
5//! `ActiveStatusBarItems` (HashMap insert acts as create-or-update).
6
7use serde_json::json;
8use tauri::Emitter;
9use tonic::{Response, Status};
10use CommonLibrary::StatusBar::{DTO::StatusBarEntryDTO::StatusBarEntryDTO, StatusBarProvider::StatusBarProvider};
11
12use crate::{
13	RPC::CocoonService::CocoonServiceImpl,
14	Vine::Generated::{Empty, SetStatusBarTextRequest},
15	dev_log,
16};
17
18pub async fn Fn(Service:&CocoonServiceImpl, Request:SetStatusBarTextRequest) -> Result<Response<Empty>, Status> {
19	dev_log!(
20		"cocoon",
21		"[CocoonService] set_status_bar_text: id={} text={}",
22		Request.item_id,
23		Request.text
24	);
25
26	let Entry = StatusBarEntryDTO {
27		EntryIdentifier:Request.item_id.clone(),
28
29		ItemIdentifier:Request.item_id.clone(),
30
31		ExtensionIdentifier:String::new(),
32
33		Name:None,
34
35		Text:Request.text.clone(),
36
37		Tooltip:None,
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] set_status_bar_text trait failed: {}", Error);
56
57		let _ = Service
58			.environment
59			.ApplicationHandle
60			.emit("sky://statusbar/update", json!({ "id": Request.item_id, "text": Request.text }));
61	}
62
63	Ok(Response::new(Empty {}))
64}