Skip to content

Commit

Permalink
chore: Added invoke command for vanilla example (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
tillmann-crabnebula authored Oct 25, 2023
1 parent 9ce6cac commit c718488
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ fn main() {
.expect("error while running tauri application")
}
```

To invoke a custom command from your own or remote system you can use `curl` or similar tooling.
See [`examples/vanilla`](examples/vanilla/) to test this on your system.

An example command to invoke the `exit` command in the example Tauri app exposing port `18436` (randomly chosen port) could look like:

```sh
curl localhost:18436/main -H 'Content-Type: application/json' -d '{ "__tauriModule": "Process", "cmd": "exit", "callback": 1234, "error": 1234, "message": {"cmd": "exit", "exitCode": 1 } }'
```


8 changes: 3 additions & 5 deletions examples/vanilla/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ fn my_command(args: u64) -> Result<String, ()> {
}

fn main() {
let http = tauri_invoke_http::Invoke::new(if cfg!(feature = "custom-protocol") {
if cfg!(windows) { ["https://tauri.localhost"] } else { ["tauri://localhost"] }
} else {
["http://127.0.0.1:1430"]
});
/// Allow from all origins for testing purposes.
/// Should be allow listed to reduce risks of accidential exposure to other networks.
let http = tauri_invoke_http::Invoke::new(["*"]});
tauri::Builder::default()
.invoke_system(http.initialization_script(), http.responder())
.setup(move |app| {
Expand Down
4 changes: 3 additions & 1 deletion examples/vanilla/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"active": false
},
"allowlist": {
"all": false
"process" : {
"exit" : true
}
},
"windows": [
{
Expand Down

0 comments on commit c718488

Please sign in to comment.