feat: move interpreter code into desktop
This commit is contained in:
1 parent
50faa7dd08
commit
c86cbd69da
3 files changed
+42
-39
No files matched your search
+31
-27
@@ -184,36 +184,40 @@ 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,
|
||||||
"eval_result" => {
|
None => {
|
||||||
let result = message.params();
|
log::error!("Failed to parse IPC message: {}", payload);
|
||||||
eval_sender.send(result).unwrap();
|
return;
|
||||||
}
|
}
|
||||||
"user_event" => {
|
};
|
||||||
_ = event_tx.unbounded_send(message.params());
|
|
||||||
}
|
match message.method() {
|
||||||
"initialize" => {
|
"eval_result" => {
|
||||||
is_ready.store(true, std::sync::atomic::Ordering::Relaxed);
|
let result = message.params();
|
||||||
let _ = proxy.send_event(UserWindowEvent::EditsReady);
|
eval_sender.send(result).unwrap();
|
||||||
}
|
}
|
||||||
"browser_open" => {
|
"user_event" => {
|
||||||
let data = message.params();
|
_ = event_tx.unbounded_send(message.params());
|
||||||
log::trace!("Open browser: {:?}", data);
|
}
|
||||||
if let Some(temp) = data.as_object() {
|
"initialize" => {
|
||||||
if temp.contains_key("href") {
|
is_ready.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
let url = temp.get("href").unwrap().as_str().unwrap();
|
let _ = proxy.send_event(UserWindowEvent::EditsReady);
|
||||||
if let Err(e) = webbrowser::open(url) {
|
}
|
||||||
log::error!("Open Browser error: {:?}", e);
|
"browser_open" => {
|
||||||
}
|
let data = message.params();
|
||||||
|
log::trace!("Open browser: {:?}", data);
|
||||||
|
if let Some(temp) = data.as_object() {
|
||||||
|
if temp.contains_key("href") {
|
||||||
|
let url = temp.get("href").unwrap().as_str().unwrap();
|
||||||
|
if let Err(e) = webbrowser::open(url) {
|
||||||
|
log::error!("Open Browser error: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
})
|
_ => (),
|
||||||
.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