factor out a hot reloading connect function

This commit is contained in:
= committed 2023-01-11 16:43:41 -06:00
1 parent e5e1abbdac
commit 042b67b61b
11 files changed
+47 -112

No files matched your search

-31
View File
@@ -1,31 +0,0 @@
#![allow(dead_code)]
use dioxus_core::Template;
use interprocess::local_socket::LocalSocketStream;
use std::io::{BufRead, BufReader};
use tokio::sync::mpsc::UnboundedSender;
pub(crate) fn init(proxy: UnboundedSender<Template<'static>>) {
std::thread::spawn(move || {
let temp_file = std::env::temp_dir().join("@dioxusin");
if let Ok(socket) = LocalSocketStream::connect(temp_file.as_path()) {
let mut buf_reader = BufReader::new(socket);
loop {
let mut buf = String::new();
match buf_reader.read_line(&mut buf) {
Ok(_) => {
let template: Template<'static> =
serde_json::from_str(Box::leak(buf.into_boxed_str())).unwrap();
proxy.send(template).unwrap();
}
Err(err) => {
if err.kind() != std::io::ErrorKind::WouldBlock {
break;
}
}
}
}
}
});
}
-2
View File
@@ -18,8 +18,6 @@ pub mod adapters {
pub use adapters::*;
#[cfg(all(feature = "hot-reload", debug_assertions))]
mod hot_reload;
pub mod pool;
use futures_util::{SinkExt, StreamExt};
pub use pool::*;
+3 -1
View File
@@ -106,7 +106,9 @@ where
#[cfg(all(feature = "hot-reload", debug_assertions))]
let mut hot_reload_rx = {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
crate::hot_reload::init(tx);
dioxus_hot_reload::connect(move |template| {
let _ = tx.send(template);
});
rx
};