Skip to content

Commit

Permalink
done: return from command works!
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyHappening committed May 25, 2023
1 parent dd3b196 commit d75328e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ wasm-bindgen = "=0.2.84"
js-sys = "=0.3.61"
console_log = "1.0.0"
log = "0.4.17"
wasm-bindgen-futures = "=0.4.34"

[features]
## For developing purposes, so my IDE compiles everything
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ don't run them together (unless you change the folders they output to).
## WIP:
This template works for me on my machine, but there are still a few issues
- There is still an error about conflicting build artifacts
- I haven't tested all of leptos' features using client side rendering (i.e. using trunk)


## Development:
I am developing a personal project, this is intended to give a foothold for others
who are trying to solve the same issues as me.

This article helped me: https://dev.to/stevepryde/create-a-desktop-app-in-rust-using-tauri-and-yew-2bhe

I am very happy to document this more, please, just add a github issue and I will!
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use leptos::*;
use leptos_app::app::*;
use log::info;
use leptos_app::app::*;
use log::info;

#[cfg(feature = "ssr")]
#[actix_web::main]
Expand Down Expand Up @@ -46,8 +46,8 @@ pub fn main() {
// prefer using `cargo leptos serve` instead
// to run: `trunk serve --open --features ssg`

console_log::init_with_level(log::Level::Debug).expect("error initializing logger");
console_error_panic_hook::set_once();
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");

info!("Running leptos application as ssg ...");

Expand All @@ -64,15 +64,24 @@ pub fn main() {
}

use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;

#[cfg(feature = "tauri")]
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = "window.__TAURI__.tauri.invoke")]
fn tauri_invoke(cmd: &str, args: js_sys::Object) -> String;
#[wasm_bindgen(js_name = "window.__TAURI__.tauri.invoke", catch)]
async fn tauri_invoke(cmd: &str, args: js_sys::Object) -> Result<JsValue, js_sys::Error>;
}

#[cfg(feature = "tauri")]
fn invoke_example_command() {
let ret = tauri_invoke("example_command", js_sys::Object::new());
info!("tauri_invoke returned: {}", ret);
use js_sys::JsString;

wasm_bindgen_futures::spawn_local(async {
let ret = tauri_invoke("command_example", js_sys::Object::new())
.await
.expect("No errors from js interop");
let str: String = JsString::from(ret).into();
info!("tauri_invoke returned: {}", str);
})
}

0 comments on commit d75328e

Please sign in to comment.