glory_cli/signal/
reload.rs1use glory_hot_reload::diff::Patches;
2use once_cell::sync::Lazy;
3use tokio::sync::broadcast;
4
5static RELOAD_CHANNEL: Lazy<broadcast::Sender<ReloadType>> = Lazy::new(|| broadcast::channel::<ReloadType>(1).0);
6
7#[derive(Debug, Clone)]
8pub enum ReloadType {
9 Full,
10 Style,
11 ViewPatches(String),
12}
13
14pub struct ReloadSignal {}
15
16impl ReloadSignal {
17 pub fn send_full() {
18 if let Err(e) = RELOAD_CHANNEL.send(ReloadType::Full) {
19 log::error!(r#"Error could not send reload "Full" due to: {e}"#);
20 }
21 }
22 pub fn send_style() {
23 if let Err(e) = RELOAD_CHANNEL.send(ReloadType::Style) {
24 log::error!(r#"Error could not send reload "Style" due to: {e}"#);
25 }
26 }
27
28 pub fn send_view_patches(view_patches: &Patches) {
29 match serde_json::to_string(view_patches) {
30 Ok(data) => {
31 if let Err(e) = RELOAD_CHANNEL.send(ReloadType::ViewPatches(data)) {
32 log::error!(r#"Error could not send reload "View Patches" due to: {e}"#);
33 }
34 }
35 Err(e) => log::error!(r#"Error could not send reload "View Patches" due to: {e}"#),
36 }
37 }
38
39 pub fn subscribe() -> broadcast::Receiver<ReloadType> {
40 RELOAD_CHANNEL.subscribe()
41 }
42}