-
Notifications
You must be signed in to change notification settings - Fork 97
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/src | ||
/public | ||
/Cargo.toml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
[package] | ||
name = "{% package_name %}-ui" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# Enable a small amount of optimization in debug mode | ||
[profile.dev] | ||
opt-level = 1 | ||
|
||
# Enable high optimizations for dependencies, but not for our code: | ||
[profile.dev.package."*"] | ||
opt-level = 3 | ||
|
||
[dependencies] | ||
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"] | ||
|
||
[workspace] | ||
members = ["src-tauri"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Tauri + Dominator | ||
|
||
This template should help get you started developing with Tauri and Dominator. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[build] | ||
target = "./index.html" | ||
|
||
[watch] | ||
ignore = ["./src-tauri"] | ||
|
||
[serve] | ||
address = "{% if mobile %}0.0.0.0{% else %}127.0.0.1{% endif %}" | ||
port = 1420 | ||
open = false{% if mobile %} | ||
ws_protocol = "ws"{% endif %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2019-2022 Tauri Programme within The Commons Conservancy | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# SPDX-License-Identifier: MIT | ||
devPath = http://localhost:1420 | ||
distDir = ../dist | ||
withGlobalTauri = true | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should also provide a |
||
[files] | ||
tauri.svg = public/tauri.svg | ||
styles.css = styles.css |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | ||
<title>GUI</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "{% package_name %}-ui", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use of a |
||
"version": "0.1.0", | ||
"scripts": { | ||
"start": "npm-run-all --parallel localmedia:serve trunk:serve:dev tauri:dev", | ||
"localmedia:serve": "cd public && http-server -g -b --cors -p 9000", | ||
"trunk:serve:dev": "cross-env RUSTFLAGS=--cfg=web_sys_unstable_apis trunk serve --features dev --watch .", | ||
"tauri:dev": "tauri dev", | ||
"build": "cross-env RUSTFLAGS=--cfg=web_sys_unstable_apis trunk build --release" | ||
}, | ||
"dependencies": { | ||
"@tauri-apps/api": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"@tauri-apps/cli": "^1.5.9", | ||
"cross-env": "^7.0.3", | ||
"http-server": "^14.1.1", | ||
"npm-run-all": "^4.1.5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,124 @@ | ||||||||||||||||||
use std::sync::Arc; | ||||||||||||||||||
|
||||||||||||||||||
use serde::{Deserialize, Serialize}; | ||||||||||||||||||
use serde_wasm_bindgen::to_value; | ||||||||||||||||||
use wasm_bindgen::prelude::*; | ||||||||||||||||||
use wasm_bindgen_futures::spawn_local; | ||||||||||||||||||
use dominator::DomBuilder; | ||||||||||||||||||
pub use dominator::{clone, events, html, svg, with_node, Dom}; | ||||||||||||||||||
pub use futures_signals::{ | ||||||||||||||||||
map_ref, | ||||||||||||||||||
signal::{Mutable, Signal, SignalExt}, | ||||||||||||||||||
signal_vec::{MutableVec, SignalVec, SignalVecExt}, | ||||||||||||||||||
}; | ||||||||||||||||||
use web_sys::HtmlInputElement; | ||||||||||||||||||
|
||||||||||||||||||
#[wasm_bindgen] | ||||||||||||||||||
extern "C" { | ||||||||||||||||||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "{% if alpha %}core{% else %}tauri{% endif %}"])] | ||||||||||||||||||
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); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this variant here |
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
#[derive(Clone, Serialize, Deserialize)] | ||||||||||||||||||
struct Args { | ||||||||||||||||||
name: String, | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||||||||||||||||||
pub struct App { | ||||||||||||||||||
greet: Mutable<Option<String>>, | ||||||||||||||||||
input: Mutable<String> | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
impl App { | ||||||||||||||||||
pub fn new() -> Arc<Self> { | ||||||||||||||||||
Arc::new(Self { | ||||||||||||||||||
greet: Mutable::new(None), | ||||||||||||||||||
input: Mutable::new(String::new()) | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
pub fn render(app: Arc<Self>) -> Dom { | ||||||||||||||||||
let state = app.clone(); | ||||||||||||||||||
// let new_msg = | ||||||||||||||||||
// invoke("greet", to_value(&GreetArgs { name: &name.get() }).unwrap()).await; | ||||||||||||||||||
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment should be removed? |
||||||||||||||||||
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()))) | ||||||||||||||||||
}), | ||||||||||||||||||
|
||||||||||||||||||
]) | ||||||||||||||||||
})) | ||||||||||||||||||
}) | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+48
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
There was a problem hiding this comment.
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?