Skip to content

Commit 2eb135a

Browse files
authored
Merge pull request #71 from BrowserSync/overlay
overlay
2 parents d18fcec + 7bf34fb commit 2eb135a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+8004
-6568
lines changed

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
ui/dist
22
inject/dist
33
inject/vendor
4-
generated/
4+
generated/
5+
package-lock.json
6+
package.json

crates/bsnext_core/src/server/actor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ impl ServerActor {
4646

4747
(shutdown_complete, axum_server_handle_clone, client_sender)
4848
}
49+
pub fn client_sender(&self) -> Option<&tokio::sync::broadcast::Sender<ClientEvent>> {
50+
self.signals.as_ref().and_then(|s| s.client_sender.as_ref())
51+
}
4952
}
5053

5154
impl actix::Actor for ServerActor {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::server::actor::ServerActor;
2+
use bsnext_dto::{ClientEvent, DisplayMessageDTO};
3+
use bsnext_input::bs_live_built_in_task::ClientNotification;
4+
5+
#[derive(actix::Message, Debug)]
6+
#[rtype(result = "()")]
7+
pub enum Notification {
8+
Any(ClientNotification),
9+
}
10+
11+
impl actix::Handler<Notification> for ServerActor {
12+
type Result = ();
13+
14+
fn handle(&mut self, msg: Notification, _ctx: &mut Self::Context) -> Self::Result {
15+
let Some(client_sender) = self.client_sender() else {
16+
return tracing::error!("signals not ready, should they be?");
17+
};
18+
19+
match msg {
20+
Notification::Any(ClientNotification::DisplayMessage(dm)) => {
21+
let msg = DisplayMessageDTO {
22+
message: dm.message,
23+
reason: dm.reason,
24+
};
25+
match client_sender.send(ClientEvent::DisplayMessage(msg)) {
26+
Ok(_) => tracing::debug!("send ClientEvent::DisplayMessage to clients"),
27+
Err(e) => {
28+
tracing::error!("did not send ClientEvent::DisplayMessage to clients");
29+
tracing::error!(?e)
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}

crates/bsnext_core/src/server/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod error;
33
pub mod handler_change;
44
pub mod handler_client_config;
55
pub mod handler_listen;
6+
pub mod handler_notification;
67
pub mod handler_patch;
78
pub mod handler_routes_updated;
89
pub mod handler_stop;

crates/bsnext_core/src/server/router/pub_api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ async fn post_events(
7171
ClientEvent::WsConnection(_) => {
7272
todo!("handle ClientEvent::WsConnection in incoming event handler?")
7373
}
74+
ClientEvent::DisplayMessage(_) => {
75+
todo!("handle ClientEvent::DisplayMessage in incoming event handler...")
76+
}
7477
};
7578
match recv
7679
.send(IncomingEvents::FilesChanged(FilesChanged {

crates/bsnext_core/src/servers_supervisor/file_changed_handler.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::server::handler_change::{Change, ChangeWithSpan};
2+
use crate::server::handler_notification::Notification;
23
use crate::servers_supervisor::actor::ServersSupervisor;
4+
use actix::AsyncContext;
35
use bsnext_fs::FsEventContext;
6+
use bsnext_input::bs_live_built_in_task::ClientNotification;
47
use std::path::PathBuf;
58

69
#[derive(actix::Message)]
@@ -59,3 +62,27 @@ impl actix::Handler<FilesChanged> for ServersSupervisor {
5962
}
6063
}
6164
}
65+
66+
#[derive(Debug, Clone, actix::Message)]
67+
#[rtype(result = "()")]
68+
pub enum ServersNotification {
69+
FilesChanged(FilesChanged),
70+
ClientNotification(ClientNotification),
71+
}
72+
73+
impl actix::Handler<ServersNotification> for ServersSupervisor {
74+
type Result = ();
75+
76+
fn handle(&mut self, msg: ServersNotification, ctx: &mut Self::Context) -> Self::Result {
77+
tracing::debug!("looking at {} handlers", self.handlers.len());
78+
match msg {
79+
ServersNotification::FilesChanged(fc) => ctx.notify(fc),
80+
ServersNotification::ClientNotification(notification) => {
81+
for child in self.handlers.values() {
82+
let server_msg = Notification::Any(notification.to_owned());
83+
child.actor_address.do_send(server_msg);
84+
}
85+
}
86+
}
87+
}
88+
}

crates/bsnext_dto/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,14 @@ pub enum ClientEvent {
461461
Change(ChangeDTO),
462462
WsConnection(ClientConfigDTO),
463463
Config(ClientConfigDTO),
464+
DisplayMessage(DisplayMessageDTO),
465+
}
466+
467+
#[typeshare::typeshare]
468+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
469+
pub struct DisplayMessageDTO {
470+
pub message: String,
471+
pub reason: Option<String>,
464472
}
465473

466474
#[typeshare::typeshare]

crates/bsnext_input/src/bs_live_built_in_task.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::str::FromStr;
55
Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone, serde::Deserialize, serde::Serialize,
66
)]
77
pub enum BsLiveBuiltInTask {
8+
#[serde(rename = "notify-clients")]
9+
NotifyClients(ClientNotification),
810
#[serde(rename = "notify-server")]
911
NotifyServer,
1012
#[serde(rename = "ext-event")]
@@ -14,10 +16,18 @@ pub enum BsLiveBuiltInTask {
1416
impl FromStr for BsLiveBuiltInTask {
1517
type Err = anyhow::Error;
1618
fn from_str(s: &str) -> Result<Self, Self::Err> {
17-
match s {
18-
"notify-server" => Ok(Self::NotifyServer),
19-
"ext-event" => Ok(Self::PublishExternalEvent),
20-
_ => Err(anyhow::anyhow!("not a valid bslive builtin task")),
19+
match s.split_once(":") {
20+
Some(("notify-clients", message)) => Ok(Self::NotifyClients(
21+
ClientNotification::DisplayMessage(DisplayMessage {
22+
message: message.to_owned(),
23+
reason: None,
24+
}),
25+
)),
26+
_ => match s {
27+
"notify-server" => Ok(Self::NotifyServer),
28+
"ext-event" => Ok(Self::PublishExternalEvent),
29+
_ => Err(anyhow::anyhow!("not a valid bslive builtin task")),
30+
},
2131
}
2232
}
2333
}
@@ -26,9 +36,25 @@ impl Display for BsLiveBuiltInTask {
2636
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2737
match self {
2838
BsLiveBuiltInTask::NotifyServer => write!(f, "BsLiveTask::NotifyServer"),
39+
BsLiveBuiltInTask::NotifyClients(..) => write!(f, "BsLiveTask::NotifyClients"),
2940
BsLiveBuiltInTask::PublishExternalEvent => {
3041
write!(f, "BsLiveTask::PublishExternalEvent")
3142
}
3243
}
3344
}
3445
}
46+
47+
#[derive(
48+
Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone, serde::Deserialize, serde::Serialize,
49+
)]
50+
pub enum ClientNotification {
51+
DisplayMessage(DisplayMessage),
52+
}
53+
54+
#[derive(
55+
Debug, PartialEq, PartialOrd, Ord, Eq, Hash, Clone, serde::Deserialize, serde::Serialize,
56+
)]
57+
pub struct DisplayMessage {
58+
pub message: String,
59+
pub reason: Option<String>,
60+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::capabilities::Capabilities;
22
use actix::{Handler, Recipient, ResponseFuture};
3-
use bsnext_core::servers_supervisor::file_changed_handler::FilesChanged;
3+
use bsnext_core::servers_supervisor::file_changed_handler::ServersNotification;
44

55
#[derive(actix::Message)]
6-
#[rtype(result = "Result<Recipient<FilesChanged>, anyhow::Error>")]
6+
#[rtype(result = "Result<Recipient<ServersNotification>, anyhow::Error>")]
77
pub struct RequestServersAddr;
88

99
impl Handler<RequestServersAddr> for Capabilities {
10-
type Result = ResponseFuture<Result<Recipient<FilesChanged>, anyhow::Error>>;
10+
type Result = ResponseFuture<Result<Recipient<ServersNotification>, anyhow::Error>>;
1111

1212
#[tracing::instrument(skip_all, name = "RequestServersAddr")]
1313
fn handle(&mut self, _msg: RequestServersAddr, _ctx: &mut Self::Context) -> Self::Result {
14-
let addr: Recipient<FilesChanged> = self.servers_addr.clone().recipient();
14+
let addr: Recipient<ServersNotification> = self.servers_addr.clone().recipient();
1515
Box::pin(async move { Ok(addr) })
1616
}
1717
}

crates/bsnext_system/src/tasks/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::external_event_sender::ExternalEventSenderWithLogging;
2+
use crate::tasks::notify_clients::NotifyClientsReady;
23
use crate::tasks::notify_servers::NotifyServersReady;
34
use crate::tasks::sh_cmd::ShCmd;
45
use crate::tasks::task_spec::{TaskSpec, TreeDisplay};
@@ -15,6 +16,7 @@ use std::hash::{DefaultHasher, Hash, Hasher};
1516

1617
pub mod comms;
1718
mod into_recipient;
19+
pub mod notify_clients;
1820
pub mod notify_servers;
1921
pub mod resolve;
2022
pub mod sh_cmd;
@@ -88,6 +90,11 @@ impl AsActor for RunnableWithComms {
8890
let actor = a.start();
8991
actor.recipient()
9092
}
93+
Runnable::BsLiveTask(BsLiveBuiltInTask::NotifyClients(client)) => {
94+
let a = NotifyClientsReady::new(self.ctx.capabilities.recipient(), client);
95+
let actor = a.start();
96+
actor.recipient()
97+
}
9198
Runnable::BsLiveTask(BsLiveBuiltInTask::PublishExternalEvent) => {
9299
let actor = ExternalEventSenderWithLogging::new(self.ctx.capabilities.recipient());
93100
let addr = actor.start();
@@ -124,6 +131,9 @@ impl From<&RunOptItem> for Runnable {
124131
BsLiveBuiltInTask::PublishExternalEvent => {
125132
Self::BsLiveTask(BsLiveBuiltInTask::PublishExternalEvent)
126133
}
134+
BsLiveBuiltInTask::NotifyClients(notify_clients) => {
135+
Self::BsLiveTask(BsLiveBuiltInTask::NotifyClients(notify_clients.to_owned()))
136+
}
127137
},
128138
RunOptItem::Sh(sh) => Self::Sh(ShCmd::from(sh)),
129139
RunOptItem::ShImplicit(sh) => Self::Sh(ShCmd::new(sh.into())),

0 commit comments

Comments
 (0)