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

Added invoke command for vanilla example #16

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading