feat: add update functionality to useref

This commit is contained in:
Jonathan Kelley committed 2021-10-04 10:22:20 -04:00
1 parent 5502429626
commit a2b0c50a34
16 files changed
+77 -47

No files matched your search

+2 -1
View File
@@ -30,8 +30,9 @@ impl<'a> DesktopConfig<'a> {
}
}
pub fn with_edits(&mut self, edits: Vec<DomEdit<'a>>) {
pub fn with_edits(&mut self, edits: Vec<DomEdit<'a>>) -> &mut Self {
self.manual_edits = Some(edits);
self
}
pub fn with_prerendered(&mut self, content: String) -> &mut Self {
+1 -1
View File
@@ -9,7 +9,7 @@
<div id="_dioxusroot">
</div>
</body>
<script type="text/javascript" src="/index.js">
<script type="text/javascript" src="index.js">
</script>
</html>
+4
View File
@@ -153,6 +153,10 @@ class Interpreter {
this.root.addEventListener(event_name, (event) => {
const target = event.target;
const val = target.getAttribute(`dioxus-event-${event_name}`);
if (val == null) {
return;
}
const fields = val.split(".");
const scope_id = parseInt(fields[0]);
const real_id = parseInt(fields[1]);
+5 -14
View File
@@ -93,7 +93,7 @@ pub fn run<T: Properties + 'static + Send + Sync>(
let locked_receiver = Rc::new(RefCell::new(event_rx));
let webview = WebViewBuilder::new(window)?
.with_url("wry://src/index.html")?
.with_url("wry://index.html")?
.with_rpc_handler(move |_window: &Window, mut req: RpcRequest| {
//
match req.method.as_str() {
@@ -130,20 +130,11 @@ pub fn run<T: Properties + 'static + Send + Sync>(
use wry::http::ResponseBuilder;
// Remove url scheme
let path = request.uri().replace("wry://", "");
// Read the file content from file path
let content = read(canonicalize(&path)?)?;
// Return asset contents and mime types based on file extentions
// If you don't want to do this manually, there are some crates for you.
// Such as `infer` and `mime_guess`.
let (data, meta) = if path.ends_with(".html") {
(content, "text/html")
} else if path.ends_with(".js") {
(content, "text/javascript")
} else if path.ends_with(".png") {
(content, "image/png")
} else {
unimplemented!();
let (data, meta) = match path.as_str() {
"index.html" => (include_bytes!("./index.html").to_vec(), "text/html"),
"index.html/index.js" => (include_bytes!("./index.js").to_vec(), "text/javascript"),
_ => unimplemented!("path {}", path),
};
ResponseBuilder::new().mimetype(meta).body(data)