Skip to main content

Mountain/Environment/StatusBarProvider/
EntryManagement.rs

1//! # StatusBarProvider - Entry Management
2//!
3//! Implementation of status bar entry creation and disposal for
4//! [`MountainEnvironment`]
5
6use CommonLibrary::{
7	Error::CommonError::CommonError,
8	IPC::SkyEvent::SkyEvent,
9	StatusBar::DTO::StatusBarEntryDTO::StatusBarEntryDTO,
10};
11use serde_json::json;
12use tauri::Emitter;
13
14use super::super::{MountainEnvironment::MountainEnvironment, Utility};
15use crate::dev_log;
16
17/// Entry management operations implementation for MountainEnvironment
18pub(super) async fn set_status_bar_entry_impl(
19	env:&MountainEnvironment,
20
21	entry:StatusBarEntryDTO,
22) -> Result<(), CommonError> {
23	dev_log!("lifecycle", "[StatusBarProvider] Setting entry: {}", entry.EntryIdentifier);
24
25	let mut items_guard = env
26		.ApplicationState
27		.Feature
28		.Markers
29		.ActiveStatusBarItems
30		.lock()
31		.map_err(Utility::ErrorMapping::MapApplicationStateLockErrorToCommonError)?;
32
33	items_guard.insert(entry.EntryIdentifier.clone(), entry.clone());
34
35	drop(items_guard);
36
37	let payload = json!({
38		"id": entry.EntryIdentifier,
39		"itemId": entry.ItemIdentifier,
40		"extensionId": entry.ExtensionIdentifier,
41		"name": entry.Name,
42		"text": entry.Text,
43		"tooltip": entry.Tooltip,
44		"command": entry.Command,
45		"color": entry.Color,
46		"backgroundColor": entry.BackgroundColor,
47		"alignment": if entry.IsAlignedLeft { 0 } else { 1 },
48		"priority": entry.Priority,
49		"accessibilityInformation": entry.AccessibilityInformation,
50	});
51
52	env.ApplicationHandle
53		.emit(SkyEvent::StatusBarSetEntry.AsStr(), payload)
54		.map_err(|error| CommonError::UserInterfaceInteraction { Reason:error.to_string() })
55}
56
57/// Removes a status bar item from the UI.
58pub(super) async fn dispose_status_bar_entry_impl(
59	env:&MountainEnvironment,
60
61	entry_identifier:String,
62) -> Result<(), CommonError> {
63	dev_log!("lifecycle", "[StatusBarProvider] Disposing entry: {}", entry_identifier);
64
65	env.ApplicationState
66		.Feature
67		.Markers
68		.ActiveStatusBarItems
69		.lock()
70		.map_err(Utility::ErrorMapping::MapApplicationStateLockErrorToCommonError)?
71		.remove(&entry_identifier);
72
73	env.ApplicationHandle
74		.emit(SkyEvent::StatusBarDisposeEntry.AsStr(), json!({ "id": entry_identifier }))
75		.map_err(|error| CommonError::UserInterfaceInteraction { Reason:error.to_string() })
76}