WIP: Dioxus-webview
This commit is contained in:
1 parent
28ac37a8b2
commit
9c01736895
9 files changed
+113
-20
No files matched your search
@@ -9,6 +9,7 @@ members = [
|
|||||||
"packages/core-macro",
|
"packages/core-macro",
|
||||||
"packages/router",
|
"packages/router",
|
||||||
"packages/ssr",
|
"packages/ssr",
|
||||||
|
"packages/webview",
|
||||||
# "packages/macro",
|
# "packages/macro",
|
||||||
# TODO @Jon, share the validation code
|
# TODO @Jon, share the validation code
|
||||||
# "packages/web",
|
# "packages/web",
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ fn main() {
|
|||||||
/// This macro makes writing functional components elegant, similar to how Rocket parses URIs.
|
/// This macro makes writing functional components elegant, similar to how Rocket parses URIs.
|
||||||
///
|
///
|
||||||
/// You don't actually *need* this macro to be productive, but it makes life easier, and components cleaner.
|
/// You don't actually *need* this macro to be productive, but it makes life easier, and components cleaner.
|
||||||
/// This approach also integrates well with tools like Rust-Analyzer
|
/// This approach also integrates well with tools like Rust-Analyzer.
|
||||||
|
///
|
||||||
|
/// Notice that Context is normally generic over props, but RA doesn't care when in proc-macro mode.
|
||||||
|
/// Also notice that ctx.props still works like you would expect, so migrating to the macro is easy.
|
||||||
#[fc]
|
#[fc]
|
||||||
fn example(ctx: &Context, name: String) -> VNode {
|
fn example(ctx: &Context, name: String) -> VNode {
|
||||||
html! { <div> "Hello, {name}!" </div> }
|
html! { <div> "Hello, {name}!" </div> }
|
||||||
|
|||||||
@@ -76,8 +76,9 @@ async fn fibsum(req: Request<()>) -> tide::Result<tide::Response> {
|
|||||||
<div class="font-medium text-6xl">
|
<div class="font-medium text-6xl">
|
||||||
{format!("{}",fib_n)}
|
{format!("{}",fib_n)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
// Try another
|
||||||
<div class="flex flex-row justify-between mt-6">
|
<div class="flex flex-row justify-between mt-6">
|
||||||
<a href=format!("http://localhost:8080/fib/{}", other_fib_to_try) class="underline">
|
<a href=format!("http://localhost:8080/fib/{}", other_fib_to_try) class="underline">
|
||||||
{"Click to try another number"}
|
{"Click to try another number"}
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ fn function_component_impl(
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
let ret_type = quote_spanned!(return_type.span()=> VNode);
|
let ret_type = quote_spanned!(return_type.span()=> VNode);
|
||||||
// let ret_type = quote_spanned!(return_type.span()=> ::VNode);
|
|
||||||
// let ret_type = quote_spanned!(return_type.span()=> ::yew::html::Html);
|
|
||||||
|
|
||||||
let quoted = quote! {
|
let quoted = quote! {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@@ -69,22 +67,6 @@ fn function_component_impl(
|
|||||||
}
|
}
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub use __component_blah::component as #function_name;
|
pub use __component_blah::component as #function_name;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #vis struct #function_name;
|
|
||||||
|
|
||||||
// impl ::yew_functional::FunctionProvider for #function_name {
|
|
||||||
// type TProps = #props_type;
|
|
||||||
|
|
||||||
// fn run(#arg) -> #ret_type {
|
|
||||||
// #block
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #(#attrs)*
|
|
||||||
// #vis type #component_name = ::yew_functional::FunctionComponent<#function_name>;
|
|
||||||
};
|
};
|
||||||
// let quoted = quote! {
|
// let quoted = quote! {
|
||||||
// #[doc(hidden)]
|
// #[doc(hidden)]
|
||||||
@@ -149,6 +131,31 @@ impl Parse for FunctionComponent {
|
|||||||
// Extract the "context" object
|
// Extract the "context" object
|
||||||
let props_type = validate_context_arg(&first_arg)?;
|
let props_type = validate_context_arg(&first_arg)?;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Extract the rest of the function arguments into a struct body
|
||||||
|
We require all inputs are strongly typed with names so we can destructure into the function body when expanded
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
// let rest = inputs
|
||||||
|
// .map(|f| {
|
||||||
|
// //
|
||||||
|
// match f {
|
||||||
|
// FnArg::Typed(pat) => {
|
||||||
|
// match *pat.pat {
|
||||||
|
// syn::Pat::Type(asd) => {}
|
||||||
|
// _ => {}
|
||||||
|
// };
|
||||||
|
// //
|
||||||
|
// }
|
||||||
|
// FnArg::Receiver(_) => {}
|
||||||
|
// }
|
||||||
|
// // let name = f
|
||||||
|
// let stream = f.into_token_stream();
|
||||||
|
// (stream)
|
||||||
|
// })
|
||||||
|
// .collect::<Vec<_>>();
|
||||||
|
|
||||||
// Collect the rest of the args into a list of definitions to be used by the inline struct
|
// Collect the rest of the args into a list of definitions to be used by the inline struct
|
||||||
|
|
||||||
// Checking after param parsing may make it a little inefficient
|
// Checking after param parsing may make it a little inefficient
|
||||||
|
|||||||
@@ -149,9 +149,29 @@ pub mod virtual_dom {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub struct Context<'source, T> {
|
pub struct Context<'source, T> {
|
||||||
|
/// Direct access to the properties used to create this component.
|
||||||
pub props: &'source T,
|
pub props: &'source T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, T> Context<'a, T> {
|
||||||
|
/// Access a parent context
|
||||||
|
pub fn parent_context<C>(&self) -> C {
|
||||||
|
todo!("Context API is not ready yet")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a subscription that schedules a future render for the reference component
|
||||||
|
pub fn subscribe(&self) -> impl FnOnce() -> () {
|
||||||
|
todo!("Subscription API is not ready yet");
|
||||||
|
|| {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `Enter` API is an internal way of tracking the location in the Dioxus Virtual DOM
|
||||||
|
/// The Context object consumes itself, producing a new lifetime without reallocating
|
||||||
|
fn enter(self) -> Self {
|
||||||
|
todo!("Entrance API for reusing Context object not ready yet")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Properties {}
|
pub trait Properties {}
|
||||||
|
|
||||||
// Auto derive for pure components
|
// Auto derive for pure components
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Dioxus-Web
|
||||||
|
|
||||||
|
Build interactive user experiences directly in the web browser!
|
||||||
|
|
||||||
|
Dioxus-web provides a `WebsysRenderer` for the Dioxus Virtual Dom that handles events, progresses components, and updates the actual DOM using web-sys methods.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "dioxus-webview"
|
||||||
|
version = "0.0.0"
|
||||||
|
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
webview = "0.1.1"
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Dioxus-webview
|
||||||
|
|
||||||
|
Dioxus-webview bridges virtual and Webview DOMs together to make simple, portable, desktop applications.
|
||||||
|
|
||||||
|
Dioxus-webview is an attempt at making a simpler "Tauri" where creating desktop applications is as simple as:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// main.rs
|
||||||
|
fn main() {
|
||||||
|
dioxus_webview::new(|ctx| {
|
||||||
|
let (count, set_count) = use_state(ctx, || 0);
|
||||||
|
html! {
|
||||||
|
<div>
|
||||||
|
<h1> "Dioxus Desktop Demo" </h1>
|
||||||
|
<p> "Count is {count}"</p>
|
||||||
|
<button onclick=|_| set_count(count + 1) >
|
||||||
|
"Click to increment"
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.configure_webview(|view| {
|
||||||
|
// custom webview config options
|
||||||
|
})
|
||||||
|
.launch();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and then to create a native .app:
|
||||||
|
|
||||||
|
```
|
||||||
|
dioxus bundle --platform macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
## Goals
|
||||||
|
|
||||||
|
Because the host VirtualDOM is running in its own native process, native applications can unlock their full potential. Dioxus-webview is designed to be a 100% rust alternative to ElectronJS without the memory overhead or bloat of ElectronJS apps.
|
||||||
|
|
||||||
|
By bridging the native process, desktop apps can access full multithreading power, peripheral support, hardware access, and native filesystem controls without the hassle of web technologies. Our goal with Dioxus-webview is to make it easy to ship both a web and native application, and quickly see large performance boosts without having to re-write the whole stack. As the dioxus ecosystem grows, we hope to see 3rd parties providing wrappers for storage, offline mode, etc that supports both web and native technologies.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user