Skip to content

Commit f7ad349

Browse files
docs(opener): add basic usage guide to readme (#2167)
* docs(opener): add basic usage guide to readme * Add missing `Ok(())` and `?` * Register plugin first
1 parent 5b8efde commit f7ad349

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

plugins/opener/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,42 @@ fn main() {
7070
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
7171

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

75+
// Opens the URL in the default browser
76+
await openUrl('https://example.com')
77+
// Or with a specific browser/app
78+
await openUrl('https://example.com', 'firefox')
79+
80+
// Opens the path with the system's default app
81+
await openPath('/path/to/file')
82+
// Or with a specific app
83+
await openPath('/path/to/file', 'firefox')
84+
85+
// Reveal a path with the system's default explorer
86+
await revealItemInDir('/path/to/file')
87+
```
88+
89+
### Usage from Rust
90+
91+
You can also use those APIs from Rust:
92+
93+
```rust
94+
use tauri_plugin_opener::OpenerExt;
95+
96+
fn main() {
97+
tauri::Builder::default()
98+
.plugin(tauri_plugin_opener::init())
99+
.setup(|app| {
100+
let opener = app.opener();
101+
opener.open_url("https://example.com", Some("firefox"))?;
102+
opener.open_path("/path/to/file", Some("firefox"))?;
103+
opener.reveal_item_in_dir("/path/to/file")?;
104+
Ok(())
105+
})
106+
.run(tauri::generate_context!())
107+
.expect("error while running tauri application");
108+
}
74109
```
75110

76111
## Contributing

plugins/opener/guest-js/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
7171
}
7272

7373
/**
74-
* Reveal a path the system's default explorer.
74+
* Reveal a path with the system's default explorer.
7575
*
7676
* #### Platform-specific:
7777
*

plugins/store/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fn main() {
128128
// Note that values must be serde_json::Value instances,
129129
// otherwise, they will not be compatible with the JavaScript bindings.
130130
store.set("a".to_string(), json!("b"));
131+
Ok(())
131132
})
132133
.run(tauri::generate_context!())
133134
.expect("error while running tauri application");

0 commit comments

Comments
 (0)