Merge pull request #133 from mrxiaozhuox/master
The desktop app will default open link in browser
This commit is contained in:
4 files changed
+65
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
dioxus::desktop::launch(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn app(cx: Scope) -> Element {
|
||||||
|
cx.render(rsx! (
|
||||||
|
div {
|
||||||
|
p {
|
||||||
|
a {
|
||||||
|
href: "http://dioxuslabs.com/",
|
||||||
|
"default link"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
a {
|
||||||
|
href: "http://dioxuslabs.com/",
|
||||||
|
prevent_default: "onclick",
|
||||||
|
onclick: |_| {
|
||||||
|
println!("Hello Dioxus");
|
||||||
|
},
|
||||||
|
"custom event link",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ tokio = { version = "1.12.0", features = [
|
|||||||
], optional = true, default-features = false }
|
], optional = true, default-features = false }
|
||||||
dioxus-core-macro = { path = "../core-macro", version ="^0.1.6"}
|
dioxus-core-macro = { path = "../core-macro", version ="^0.1.6"}
|
||||||
dioxus-html = { path = "../html", features = ["serialize"], version ="^0.1.4"}
|
dioxus-html = { path = "../html", features = ["serialize"], version ="^0.1.4"}
|
||||||
|
webbrowser = "0.5.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["tokio_runtime"]
|
default = ["tokio_runtime"]
|
||||||
|
|||||||
@@ -343,6 +343,7 @@ class Interpreter {
|
|||||||
this.listeners[event_name] = true;
|
this.listeners[event_name] = true;
|
||||||
|
|
||||||
this.root.addEventListener(event_name, (event) => {
|
this.root.addEventListener(event_name, (event) => {
|
||||||
|
|
||||||
const target = event.target;
|
const target = event.target;
|
||||||
const real_id = target.getAttribute(`dioxus-id`);
|
const real_id = target.getAttribute(`dioxus-id`);
|
||||||
|
|
||||||
@@ -356,6 +357,25 @@ class Interpreter {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type == "submit") {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == "click") {
|
||||||
|
event.preventDefault();
|
||||||
|
if (should_prevent_default !== `onclick`) {
|
||||||
|
if(element.tagName == "A") {
|
||||||
|
const href = event.target.getAttribute("href")
|
||||||
|
if (href !== "" && href !== null && href !== undefined) {
|
||||||
|
rpc.call("browser_open", {
|
||||||
|
mounted_dom_id: parseInt(real_id),
|
||||||
|
href: event.target.getAttribute("href")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (real_id == null) {
|
if (real_id == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -374,7 +394,9 @@ class Interpreter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetAttribute(edit) {
|
SetAttribute(edit) {
|
||||||
|
|
||||||
// console.log("setting attr", edit);
|
// console.log("setting attr", edit);
|
||||||
|
|
||||||
const name = edit.field;
|
const name = edit.field;
|
||||||
const value = edit.value;
|
const value = edit.value;
|
||||||
const ns = edit.ns;
|
const ns = edit.ns;
|
||||||
|
|||||||
@@ -187,6 +187,20 @@ pub fn launch_with_props<P: 'static + Send>(
|
|||||||
is_ready.store(true, std::sync::atomic::Ordering::Relaxed);
|
is_ready.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
let _ = proxy.send_event(UserWindowEvent::Update);
|
let _ = proxy.send_event(UserWindowEvent::Update);
|
||||||
}
|
}
|
||||||
|
"browser_open" => {
|
||||||
|
let data = req.params.unwrap();
|
||||||
|
log::trace!("Open browser: {:?}", data);
|
||||||
|
if let Some(arr) = data.as_array() {
|
||||||
|
if let Some(temp) = arr[0].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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|||||||
Reference in new issue
Block a user