Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dominator-rust template into tauri #576

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Rizary
Copy link

@Rizary Rizary commented Jan 16, 2024

Adding dominator-rust project to create-tauri-app

Comment on lines +18 to +60
wasm-bindgen = "0.2.84"
js-sys = "0.3.61"
wasm-bindgen-futures= "0.4.34"
gloo-events = "0.1.2"
gloo-timers = { version = "0.2.6", features = ["futures"] }
gloo-net = "0.2.6"
wasm-logger = { version = "0.2.0", optional = true }
serde-wasm-bindgen = "0.5.0"
serde = "1.0.159"
serde_json = "1.0.95"
anyhow = "1.0.70"
cfg-if = "1.0.0"
log = "0.4.17"
console_error_panic_hook = { version = "0.1.7", optional = true }
futures = "0.3.28"
dominator = "0.5.32"
futures-signals = "0.3.32"
once_cell = "1.17.1"
dominator_helpers = "0.7.2"
rand = "0.8.5"
getrandom = { version = "0.2.8", features = ["js"] }
ed25519-dalek = {version = "2.0.0-rc.3", features = ["serde", "rand_core"]}
hex = "0.4.3"

[dependencies.web-sys]
version = "0.3.61"
features = [
"console",
"MouseEvent",
"Document",
"Element",
"HtmlAnchorElement",
"HtmlElement",
"HtmlButtonElement",
"HtmlImageElement",
"Node",
"Window",
"Performance",
"HtmlFormElement",
]
[features]
default = []
dev = ["wasm-logger", "console_error_panic_hook"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a huge amount of dependencies, are these all required or can we simplify this a bit?

devPath = http://localhost:1420
distDir = ../dist
withGlobalTauri = true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should also provide a beforeDevCommand and beforeBuildCommand

@@ -0,0 +1,20 @@
{
"name": "{% package_name %}-ui",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use of a package.json file in a Rust project? we should remove this file

async fn invoke(cmd: &str, name: JsValue) -> JsValue;

#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{% if alpha %}core{% else %}tauri{% endif %}"], js_name = invoke)]
async fn invoke2(cmd: &str);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this variant here

Comment on lines +25 to +28
#[derive(Clone, Serialize, Deserialize)]
struct Args {
name: String,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to GreetArgs so it can be consistent with other Rust templates

Suggested change
#[derive(Clone, Serialize, Deserialize)]
struct Args {
name: String,
}
#[derive(Serialize, Deserialize)]
struct GreetArgs<'a> {
name: &'a str,
}

Comment on lines +46 to +47
// let new_msg =
// invoke("greet", to_value(&GreetArgs { name: &name.get() }).unwrap()).await;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment should be removed?

Comment on lines +48 to +124
html!("div", {
.child(html!("div", {
.class(["body"])
.child(html!("div", {
.text("Welcome to the Tauri + Dominator starter template.")
}))
}))
.child(html!("div", {
.children(&mut [
html!("input" => HtmlInputElement, {
.prop_signal("value", state.input.signal_cloned())

.with_node!(element => {
.event(clone!(app => move |_: events::Input| {
log::info!("input: {}", element.value());
app.input.set(element.value());
}))
})
}),

html!("button", {
.text("Greet")
.event(clone!(app => move |_: events::Click| {
let app = app.clone();
let input = app.input.lock_ref();

if *input == "" {
app.clone().greet.set(None);

} else {

let input = input.to_string();
let args = Args {name: input.clone()};
let app = app.clone();
spawn_local(async move {
let name = invoke("greet", to_value(&args).unwrap()).await;
app.greet.set(name.as_string());
});
}
}))
}),

html!("div", {
.text_signal(app.greet.signal_ref(|greet| format!("{}", greet.clone().unwrap_or_default())))
}),

html!("button", {
.text("Greet2")
.event(clone!(app => move |_: events::Click| {
let app = app.clone();
let input = app.input.lock_ref();

if *input == "" {
app.clone().greet.set(None);

} else {

let input = input.to_string();
let args = Args {name: input.clone()};
let app = app.clone();
spawn_local(async move {
invoke2("greet2").await;
// app.greet.set(name.as_string());
});
}
}))
}),

html!("div", {
.text_signal(app.greet.signal_ref(|greet| format!("{}", greet.clone().unwrap_or_default())))
}),

])
}))
})
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We like to give a similar structure in all the templates so this should be changed to match other templates, the final result should look something like this
image

Comment on lines +13 to +14
init_logger();
std::panic::set_hook(Box::new(on_panic));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove all things related to loggings and keep the template as simple as possible

@Rizary
Copy link
Author

Rizary commented Jan 16, 2024

Hi @amrbashir , thank you for your input, very appreciate it. I'll address one by one soon. Just fyi on couple of things:

  1. I try the other rust based frontend template without success, hence this template just following my typical dev flow when using dominator as frontend. Other project, they add src-tauri as workspace in which I think it's not the best approach.
  2. there is package.json because on dev, trunk always copy over all the asset which cause some slowness on large project. Meanwhile, here I create several server to host the asset, so dev workflow is faster
  3. I have couple update that I'll push on another commit.

Thanks.

@amrbashir
Copy link
Member

I try the other rust based frontend template without success

Would like to hear more about this, as this would be a bug that needs to be fixed.

2. there is package.json because on dev, trunk always copy over all the asset which cause some slowness on large project. Meanwhile, here I create several server to host the asset, so dev workflow is faster

I would say this is an optimization for said larger projects to do, for create-tauri-app use-case, I'd like to keep the template as simple as possible so it is easier to add and modify later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants