* clean up logging to avoid random extra trace * fix race condition with updates * properly wire up verbose * fix bundling (macos) and logging * Add structured output * clean up clap names * extract out wire format * switch structured key to json * fix random println, fallback to `dioxus/platform` * clean up logging for run/build * clean up logging around project * remove manual exits * fix tokio runtime for mobile * rework dog app * rip out ssg * Switch dioxus/axum to dioxus/server * add android template inline * pre restructure for bundle prep * add the whole res directory * Better theme for the app * remove mobile demo now that most apps work natively * self-referential android * only use deep linking for assets * fix imports for android * clippy, fixup ios and android * I'm not boxing compiler message you can't make me * fix clippy on unix
52 lines
1.9 KiB
Rust
52 lines
1.9 KiB
Rust
use dioxus_core::{ScopeId, VirtualDom};
|
|
pub use dioxus_devtools_types::*;
|
|
use dioxus_signals::{GlobalKey, Writable};
|
|
use warnings::Warning;
|
|
|
|
/// Applies template and literal changes to the VirtualDom
|
|
///
|
|
/// Assets need to be handled by the renderer.
|
|
pub fn apply_changes(dom: &VirtualDom, msg: &HotReloadMsg) {
|
|
dom.runtime().on_scope(ScopeId::ROOT, || {
|
|
let ctx = dioxus_signals::get_global_context();
|
|
|
|
for template in &msg.templates {
|
|
let value = template.template.clone();
|
|
let key = GlobalKey::File {
|
|
file: template.key.file.as_str(),
|
|
line: template.key.line as _,
|
|
column: template.key.column as _,
|
|
index: template.key.index as _,
|
|
};
|
|
if let Some(mut signal) = ctx.get_signal_with_key(key.clone()) {
|
|
dioxus_signals::warnings::signal_read_and_write_in_reactive_scope::allow(|| {
|
|
dioxus_signals::warnings::signal_write_in_component_body::allow(|| {
|
|
signal.set(Some(value));
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/// Connect to the devserver and handle its messages with a callback.
|
|
///
|
|
/// This doesn't use any form of security or protocol, so it's not safe to expose to the internet.
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
pub fn connect(endpoint: String, mut callback: impl FnMut(DevserverMsg) + Send + 'static) {
|
|
std::thread::spawn(move || {
|
|
let (mut websocket, _req) = match tungstenite::connect(endpoint.clone()) {
|
|
Ok((websocket, req)) => (websocket, req),
|
|
Err(_) => return,
|
|
};
|
|
|
|
while let Ok(msg) = websocket.read() {
|
|
if let tungstenite::Message::Text(text) = msg {
|
|
if let Ok(msg) = serde_json::from_str(&text) {
|
|
callback(msg);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|