feat: move interpreter code into desktop
This commit is contained in:
1 parent
50faa7dd08
commit
c86cbd69da
3 files changed
+21
-18
No files matched your search
@@ -184,8 +184,15 @@ fn build_webview(
|
|||||||
.with_url("dioxus://index.html/")
|
.with_url("dioxus://index.html/")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.with_ipc_handler(move |_window: &Window, payload: String| {
|
.with_ipc_handler(move |_window: &Window, payload: String| {
|
||||||
parse_ipc_message(&payload)
|
let message = match parse_ipc_message(&payload) {
|
||||||
.map(|message| match message.method() {
|
Some(message) => message,
|
||||||
|
None => {
|
||||||
|
log::error!("Failed to parse IPC message: {}", payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match message.method() {
|
||||||
"eval_result" => {
|
"eval_result" => {
|
||||||
let result = message.params();
|
let result = message.params();
|
||||||
eval_sender.send(result).unwrap();
|
eval_sender.send(result).unwrap();
|
||||||
@@ -210,10 +217,7 @@ fn build_webview(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
})
|
}
|
||||||
.unwrap_or_else(|| {
|
|
||||||
log::warn!("invalid IPC message received");
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.with_custom_protocol(String::from("dioxus"), move |r| {
|
.with_custom_protocol(String::from("dioxus"), move |r| {
|
||||||
protocol::desktop_handler(
|
protocol::desktop_handler(
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export function main(rootname = "main") {
|
|
||||||
let root = window.document.getElementById(rootname);
|
|
||||||
if (root != null) {
|
|
||||||
window.interpreter = new Interpreter(root);
|
|
||||||
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use dioxus_interpreter_js::INTERPRETER_JS;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use wry::{
|
use wry::{
|
||||||
http::{status::StatusCode, Request, Response},
|
http::{status::StatusCode, Request, Response},
|
||||||
@@ -6,13 +7,18 @@ use wry::{
|
|||||||
|
|
||||||
fn module_loader(root_name: &str) -> String {
|
fn module_loader(root_name: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
"
|
r#"
|
||||||
<script>
|
<script>
|
||||||
import(\"./index.js\").then(function (module) {{
|
{INTERPRETER_JS}
|
||||||
module.main(\"{}\");
|
|
||||||
}});
|
let rootname = "{}";
|
||||||
|
let root = window.document.getElementById(rootname);
|
||||||
|
if (root != null) {{
|
||||||
|
window.interpreter = new Interpreter(root);
|
||||||
|
window.ipc.postMessage(serializeIpcMessage("initialize"));
|
||||||
|
}}
|
||||||
</script>
|
</script>
|
||||||
",
|
"#,
|
||||||
root_name
|
root_name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user