slow going
parent
f7ca241cbc
commit
62eefeea0f
|
|
@ -1875,6 +1875,10 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lib"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.151"
|
||||
|
|
@ -2237,6 +2241,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
|
|||
name = "pa-home-video-blue-extractinator-2"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"lib",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
|
|
@ -2249,6 +2254,7 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"js-sys",
|
||||
"leptos",
|
||||
"lib",
|
||||
"serde",
|
||||
"serde-wasm-bindgen 0.6.3",
|
||||
"wasm-bindgen",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ edition = "2021"
|
|||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[dependencies]
|
||||
lib = { path = "./src-lib" }
|
||||
leptos = { version = "0.5", features = ["csr"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde-wasm-bindgen = "0.6"
|
||||
|
|
|
|||
|
|
@ -1,16 +1,25 @@
|
|||
pub mod video;
|
||||
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
pub fn analyze(file: &str) -> String {
|
||||
match _analyze(file) {
|
||||
Ok(result) => result,
|
||||
Err(msg) => msg,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
fn _analyze(file: &str) -> Result<String, String> {
|
||||
eprintln!("analyzing {}", file);
|
||||
Err(format!("not impl"))
|
||||
}
|
||||
|
||||
pub fn clipify(file: &str) -> String {
|
||||
match _clipify(file) {
|
||||
Ok(result) => result,
|
||||
Err(msg) => msg,
|
||||
}
|
||||
}
|
||||
|
||||
fn _clipify(file: &str) -> Result<String, String> {
|
||||
eprintln!("clipifying {}", file);
|
||||
Err(format!("not impl"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ edition = "2021"
|
|||
tauri-build = { version = "1.5", features = [] }
|
||||
|
||||
[dependencies]
|
||||
lib = { path = "../src-lib" }
|
||||
tauri = { version = "1.5", features = ["shell-open"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
use lib;
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
fn analyze(file: &str) -> String {
|
||||
lib::analyze(file)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn clipify(file: &str) -> String {
|
||||
lib::clipify(file)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.invoke_handler(tauri::generate_handler![analyze, clipify])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
|
|
|||
159
src/app.rs
159
src/app.rs
|
|
@ -1,76 +1,131 @@
|
|||
use leptos::leptos_dom::ev::SubmitEvent;
|
||||
use leptos::leptos_dom::ev;
|
||||
use leptos::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_wasm_bindgen::to_value;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use lib;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "tauri"])]
|
||||
async fn invoke(cmd: &str, args: JsValue) -> JsValue;
|
||||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "tauri"])]
|
||||
async fn invoke(cmd: &str, args: JsValue) -> JsValue;
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct GreetArgs<'a> {
|
||||
name: &'a str,
|
||||
struct Args<'a> {
|
||||
file: &'a str,
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
let (name, set_name) = create_signal(String::new());
|
||||
let (greet_msg, set_greet_msg) = create_signal(String::new());
|
||||
let (file, set_file) = create_signal(String::new());
|
||||
let (err, set_err) = create_signal(String::new());
|
||||
|
||||
let update_name = move |ev| {
|
||||
let v = event_target_value(&ev);
|
||||
set_name.set(v);
|
||||
};
|
||||
let update_file = move |ev| {
|
||||
let v = event_target_value(&ev);
|
||||
set_file.set(v);
|
||||
};
|
||||
|
||||
let greet = move |ev: SubmitEvent| {
|
||||
ev.prevent_default();
|
||||
spawn_local(async move {
|
||||
if name.get().is_empty() {
|
||||
return;
|
||||
}
|
||||
let (analyze_result, set_analyze_result) = create_signal(String::new());
|
||||
let (clipify_result, set_clipify_result) = create_signal(String::new());
|
||||
|
||||
let args = to_value(&GreetArgs { name: &name.get() }).unwrap();
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
let new_msg = invoke("greet", args).await.as_string().unwrap();
|
||||
set_greet_msg.set(new_msg);
|
||||
});
|
||||
};
|
||||
let noop = move |ev: ev::SubmitEvent| { ev.prevent_default(); };
|
||||
|
||||
view! {
|
||||
<main class="container">
|
||||
<div class="row">
|
||||
<a href="https://tauri.app" target="_blank">
|
||||
<img src="public/tauri.svg" class="logo tauri" alt="Tauri logo"/>
|
||||
</a>
|
||||
<a href="https://docs.rs/leptos/" target="_blank">
|
||||
<img src="public/leptos.svg" class="logo leptos" alt="Leptos logo"/>
|
||||
</a>
|
||||
</div>
|
||||
let analyze = move |ev: ev::MouseEvent| {
|
||||
ev.prevent_default();
|
||||
spawn_local(async move {
|
||||
if file.get_untracked().is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
<p>"Click on the Tauri and Leptos logos to learn more."</p>
|
||||
let args = to_value(&Args { file: &file.get_untracked() }).unwrap();
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
match invoke("analyze", args).await.as_string() {
|
||||
Some(new_analyze_result) => set_analyze_result.set(new_analyze_result),
|
||||
None => set_err.set("analyze result failed".to_string()),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
<p>
|
||||
"Recommended IDE setup: "
|
||||
<a href="https://code.visualstudio.com/" target="_blank">"VS Code"</a>
|
||||
" + "
|
||||
<a href="https://github.com/tauri-apps/tauri-vscode" target="_blank">"Tauri"</a>
|
||||
" + "
|
||||
<a href="https://github.com/rust-lang/rust-analyzer" target="_blank">"rust-analyzer"</a>
|
||||
</p>
|
||||
let clipify = move |ev: ev::MouseEvent| {
|
||||
ev.prevent_default();
|
||||
spawn_local(async move {
|
||||
if file.get_untracked().is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
<form class="row" on:submit=greet>
|
||||
<input
|
||||
id="greet-input"
|
||||
placeholder="Enter a name..."
|
||||
on:input=update_name
|
||||
/>
|
||||
<button type="submit">"Greet"</button>
|
||||
let args = to_value(&Args { file: &file.get_untracked() }).unwrap();
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
match invoke("clipify", args).await.as_string() {
|
||||
Some(new_clipify_result) => set_clipify_result.set(new_clipify_result),
|
||||
None => set_err.set("clipify result failed".to_string()),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
view! {
|
||||
<main class="container">
|
||||
<div class="row">
|
||||
<form class="row" on:submit=noop>
|
||||
<input
|
||||
type="file"
|
||||
on:input=update_file
|
||||
/>
|
||||
<button type="submit" on:click=analyze>"Analyze"</button>
|
||||
<button type="button" on:click=clipify>"Clipify"</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<p><b>{ move || greet_msg.get() }</b></p>
|
||||
</main>
|
||||
}
|
||||
<div class="row">
|
||||
<p><b style="color: red;">{ move || err.get() }</b></p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<div class="row">
|
||||
<h2>Analysis</h2>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p><b>{ move || analyze_result.get() }FOO</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<div class="row">
|
||||
<h2>Clipified</h2>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p><b>{ move || clipify_result.get() }BAR</b></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
/*
|
||||
<p>"Click on the Tauri and Leptos logos to learn more."</p>
|
||||
|
||||
<p>
|
||||
"Recommended IDE setup: "
|
||||
<a href="https://code.visualstudio.com/" target="_blank">"VS Code"</a>
|
||||
" + "
|
||||
<a href="https://github.com/tauri-apps/tauri-vscode" target="_blank">"Tauri"</a>
|
||||
" + "
|
||||
<a href="https://github.com/rust-lang/rust-analyzer" target="_blank">"rust-analyzer"</a>
|
||||
</p>
|
||||
|
||||
<form class="row" on:submit=greet>
|
||||
<input
|
||||
id="greet-input"
|
||||
placeholder="Enter a name..."
|
||||
on:input=update_name
|
||||
/>
|
||||
<button type="submit">"Greet"</button>
|
||||
</form>
|
||||
|
||||
<p><b>{ move || greet_msg.get() }</b></p>
|
||||
*/
|
||||
</main>
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue