finish desktop implementation
This commit is contained in:
1 parent
bb62254b6b
commit
8c6fceb0c7
2 files changed
+22
-18
No files matched your search
@@ -191,7 +191,7 @@ pub fn rsx(s: TokenStream) -> TokenStream {
|
|||||||
match CapturedContextBuilder::from_call_body(body) {
|
match CapturedContextBuilder::from_call_body(body) {
|
||||||
Ok(captured) => quote::quote! {
|
Ok(captured) => quote::quote! {
|
||||||
{
|
{
|
||||||
LazyNodes::new(|__cx|{
|
LazyNodes::new(move |__cx|{
|
||||||
let captured = #captured;
|
let captured = #captured;
|
||||||
let line_num = get_line_num();
|
let line_num = get_line_num();
|
||||||
let text = #rsx_text;
|
let text = #rsx_text;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ impl DesktopController {
|
|||||||
|
|
||||||
dom.base_scope().provide_context(window_context);
|
dom.base_scope().provide_context(window_context);
|
||||||
|
|
||||||
// allow other proccesses to send the new rsx text to the @dioxus ipc channel
|
// allow other proccesses to send the new rsx text to the @dioxusin ipc channel and recieve erros on the @dioxusout channel
|
||||||
#[cfg(feature = "hot_reload")]
|
#[cfg(feature = "hot_reload")]
|
||||||
{
|
{
|
||||||
use dioxus_rsx_interpreter::{
|
use dioxus_rsx_interpreter::{
|
||||||
@@ -68,17 +68,18 @@ impl DesktopController {
|
|||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
let latest_connection: Arc<Mutex<Option<BufReader<LocalSocketStream>>>> =
|
let latest_in_connection: Arc<Mutex<Option<BufReader<LocalSocketStream>>>> =
|
||||||
Arc::new(Mutex::new(None));
|
Arc::new(Mutex::new(None));
|
||||||
let latest_connection_handle = latest_connection.clone();
|
let latest_in_connection_handle = latest_in_connection.clone();
|
||||||
let latest_connection_handle2 = latest_connection.clone();
|
let latest_out_connection: Arc<Mutex<Option<BufReader<LocalSocketStream>>>> =
|
||||||
|
Arc::new(Mutex::new(None));
|
||||||
|
let latest_out_connection_handle = latest_out_connection.clone();
|
||||||
|
|
||||||
struct DesktopErrorHandler {
|
struct DesktopErrorHandler {
|
||||||
latest_connection: Arc<Mutex<Option<BufReader<LocalSocketStream>>>>,
|
latest_connection: Arc<Mutex<Option<BufReader<LocalSocketStream>>>>,
|
||||||
}
|
}
|
||||||
impl ErrorHandler for DesktopErrorHandler {
|
impl ErrorHandler for DesktopErrorHandler {
|
||||||
fn handle_error(&self, err: Error) {
|
fn handle_error(&self, err: Error) {
|
||||||
println!("reporting err: {err:?}");
|
|
||||||
if let Some(conn) = &mut *self.latest_connection.lock().unwrap() {
|
if let Some(conn) = &mut *self.latest_connection.lock().unwrap() {
|
||||||
if let Error::RecompileRequiredError(reason) = err {
|
if let Error::RecompileRequiredError(reason) = err {
|
||||||
conn.get_mut()
|
conn.get_mut()
|
||||||
@@ -87,50 +88,53 @@ impl DesktopController {
|
|||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("sending error");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RSX_CONTEXT.set_error_handler(DesktopErrorHandler {
|
RSX_CONTEXT.set_error_handler(DesktopErrorHandler {
|
||||||
latest_connection: latest_connection_handle,
|
latest_connection: latest_out_connection_handle,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// connect to processes for incoming data
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
if let Ok(listener) = LocalSocketListener::bind("@dioxus") {
|
if let Ok(listener) = LocalSocketListener::bind("@dioxusin") {
|
||||||
for conn in listener.incoming().filter_map(handle_error) {
|
for conn in listener.incoming().filter_map(handle_error) {
|
||||||
// conn.set_nonblocking(true);
|
*latest_in_connection_handle.lock().unwrap() =
|
||||||
println!("connected");
|
|
||||||
*latest_connection_handle2.lock().unwrap() =
|
|
||||||
Some(BufReader::new(conn));
|
Some(BufReader::new(conn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// connect to processes for outgoing errors
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
if let Ok(listener) = LocalSocketListener::bind("@dioxusout") {
|
||||||
|
for conn in listener.incoming().filter_map(handle_error) {
|
||||||
|
*latest_out_connection.lock().unwrap() = Some(BufReader::new(conn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
if let Some(conn) = &mut *latest_connection.lock().unwrap() {
|
if let Some(conn) = &mut *latest_in_connection.lock().unwrap() {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
println!("reading");
|
|
||||||
match conn.read_line(&mut buf) {
|
match conn.read_line(&mut buf) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("read");
|
|
||||||
let message: SetRsxMessage =
|
let message: SetRsxMessage =
|
||||||
serde_json::from_str(&buf).unwrap();
|
serde_json::from_str(&buf).unwrap();
|
||||||
println!("{:?}", message.location);
|
|
||||||
RSX_CONTEXT.insert(message.location, message.new_text);
|
RSX_CONTEXT.insert(message.location, message.new_text);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err.kind() != std::io::ErrorKind::WouldBlock {
|
if err.kind() != std::io::ErrorKind::WouldBlock {
|
||||||
println!("{err}");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// give the error handler time to take the mutex
|
// give the error handler time to take the mutex
|
||||||
std::thread::sleep(Duration::from_millis(10));
|
std::thread::sleep(Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user