Skip to content

Commit

Permalink
docs(opener): add basic usage guide to readme (#2167)
Browse files Browse the repository at this point in the history
* docs(opener): add basic usage guide to readme

* Add missing `Ok(())` and `?`

* Register plugin first
  • Loading branch information
Legend-Master authored Dec 9, 2024
1 parent 5b8efde commit f7ad349
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions plugins/opener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,42 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:

```javascript
import { openUrl, openPath, revealItemInDir } from '@tauri-apps/plugin-opener'

// Opens the URL in the default browser
await openUrl('https://example.com')
// Or with a specific browser/app
await openUrl('https://example.com', 'firefox')

// Opens the path with the system's default app
await openPath('/path/to/file')
// Or with a specific app
await openPath('/path/to/file', 'firefox')

// Reveal a path with the system's default explorer
await revealItemInDir('/path/to/file')
```

### Usage from Rust

You can also use those APIs from Rust:

```rust
use tauri_plugin_opener::OpenerExt;

fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.setup(|app| {
let opener = app.opener();
opener.open_url("https://example.com", Some("firefox"))?;
opener.open_path("/path/to/file", Some("firefox"))?;
opener.reveal_item_in_dir("/path/to/file")?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion plugins/opener/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
}

/**
* Reveal a path the system's default explorer.
* Reveal a path with the system's default explorer.
*
* #### Platform-specific:
*
Expand Down
1 change: 1 addition & 0 deletions plugins/store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn main() {
// Note that values must be serde_json::Value instances,
// otherwise, they will not be compatible with the JavaScript bindings.
store.set("a".to_string(), json!("b"));
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down

0 comments on commit f7ad349

Please sign in to comment.