Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
22 changes: 15 additions & 7 deletions plugins/opener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<!-- description -->

| Platform | Supported |
| -------- | --------- |
| Linux | ✓ |
| Windows | ✓ |
| macOS | ✓ |
| Android | ? |
| iOS | ? |
| Platform | Supported | Notes |
|----------|-----------|---------------------------------------------------------------------------|
| Linux | ✓ | |
| Windows | ✓ | Revealing multiple files placed in different directories is not supported |
| macOS | ✓ | |
| Android | ? | |
| iOS | ? | |

## Install

Expand Down Expand Up @@ -75,6 +75,10 @@ await openPath('/path/to/file', 'firefox')

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

// Reveal multiple paths with the system's default explorer
// Note: on Windows, files have to be in the same directory
await revealItemsInDir([ '/path/to/file', '/path/to/another/file' ])
```

### Usage from Rust
Expand Down Expand Up @@ -102,6 +106,10 @@ fn main() {

// Reveal a path with the system's default explorer
opener.reveal_item_in_dir("/path/to/file")?;

// Reveal multiple paths with the system's default explorer
// Note: on Windows, files have to be in the same directory
opener.reveal_items_in_dir(&["/path/to/file"])?;
Ok(())
})
.run(tauri::generate_context!())
Expand Down
2 changes: 1 addition & 1 deletion plugins/opener/api-iife.js

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

7 changes: 6 additions & 1 deletion plugins/opener/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ fn _f() {
};
}

const COMMANDS: &[&str] = &["open_url", "open_path", "reveal_item_in_dir"];
const COMMANDS: &[&str] = &[
"open_url",
"open_path",
"reveal_item_in_dir",
"reveal_items_in_dir",
];

fn main() {
tauri_plugin::Builder::new(COMMANDS)
Expand Down
22 changes: 22 additions & 0 deletions plugins/opener/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,25 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
export async function revealItemInDir(path: string) {
return invoke('plugin:opener|reveal_item_in_dir', { path })
}

/**
* Reveal paths with the system's default explorer.
*
* #### Platform-specific:
*
* - **Android / iOS:** Unsupported.
* - **Windows:** Only supports revealing items in the same directory.
*
* @example
* ```typescript
* import { revealItemsInDir } from '@tauri-apps/plugin-opener';
* await revealItemsInDir(['/path/to/file']);
* ```
*
* @param paths The paths to reveal.
*
* @since 2.0.0
*/
export async function revealItemsInDir(paths: string[]) {
return invoke('plugin:opener|reveal_items_in_dir', { paths })
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-reveal-items-in-dir"
description = "Enables the reveal_items_in_dir command without any pre-configured scope."
commands.allow = ["reveal_items_in_dir"]

[[permission]]
identifier = "deny-reveal-items-in-dir"
description = "Denies the reveal_items_in_dir command without any pre-configured scope."
commands.deny = ["reveal_items_in_dir"]
27 changes: 27 additions & 0 deletions plugins/opener/permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ as well as reveal file in directories using default file explorer

- `allow-open-url`
- `allow-reveal-item-in-dir`
- `allow-reveal-items-in-dir`
- `allow-default-urls`

## Permission Table
Expand Down Expand Up @@ -106,6 +107,32 @@ Enables the reveal_item_in_dir command without any pre-configured scope.

Denies the reveal_item_in_dir command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`opener:allow-reveal-items-in-dir`

</td>
<td>

Enables the reveal_items_in_dir command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`opener:deny-reveal-items-in-dir`

</td>
<td>

Denies the reveal_items_in_dir command without any pre-configured scope.

</td>
</tr>
</table>
1 change: 1 addition & 0 deletions plugins/opener/permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ as well as reveal file in directories using default file explorer"""
permissions = [
"allow-open-url",
"allow-reveal-item-in-dir",
"allow-reveal-items-in-dir",
"allow-default-urls",
]
16 changes: 14 additions & 2 deletions plugins/opener/permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,22 @@
"markdownDescription": "Denies the reveal_item_in_dir command without any pre-configured scope."
},
{
"description": "This permission set allows opening `mailto:`, `tel:`, `https://` and `http://` urls using their default application\nas well as reveal file in directories using default file explorer\n#### This default permission set includes:\n\n- `allow-open-url`\n- `allow-reveal-item-in-dir`\n- `allow-default-urls`",
"description": "Enables the reveal_items_in_dir command without any pre-configured scope.",
"type": "string",
"const": "allow-reveal-items-in-dir",
"markdownDescription": "Enables the reveal_items_in_dir command without any pre-configured scope."
},
{
"description": "Denies the reveal_items_in_dir command without any pre-configured scope.",
"type": "string",
"const": "deny-reveal-items-in-dir",
"markdownDescription": "Denies the reveal_items_in_dir command without any pre-configured scope."
},
{
"description": "This permission set allows opening `mailto:`, `tel:`, `https://` and `http://` urls using their default application\nas well as reveal file in directories using default file explorer\n#### This default permission set includes:\n\n- `allow-open-url`\n- `allow-reveal-item-in-dir`\n- `allow-reveal-items-in-dir`\n- `allow-default-urls`",
"type": "string",
"const": "default",
"markdownDescription": "This permission set allows opening `mailto:`, `tel:`, `https://` and `http://` urls using their default application\nas well as reveal file in directories using default file explorer\n#### This default permission set includes:\n\n- `allow-open-url`\n- `allow-reveal-item-in-dir`\n- `allow-default-urls`"
"markdownDescription": "This permission set allows opening `mailto:`, `tel:`, `https://` and `http://` urls using their default application\nas well as reveal file in directories using default file explorer\n#### This default permission set includes:\n\n- `allow-open-url`\n- `allow-reveal-item-in-dir`\n- `allow-reveal-items-in-dir`\n- `allow-default-urls`"
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/opener/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ pub async fn open_path<R: Runtime>(
pub async fn reveal_item_in_dir(path: PathBuf) -> crate::Result<()> {
crate::reveal_item_in_dir(path)
}

#[tauri::command]
pub async fn reveal_items_in_dir(paths: Vec<PathBuf>) -> crate::Result<()> {
crate::reveal_items_in_dir(&paths)
}
15 changes: 12 additions & 3 deletions plugins/opener/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use error::Error;
type Result<T> = std::result::Result<T, Error>;

pub use open::{open_path, open_url};
pub use reveal_item_in_dir::reveal_item_in_dir;
pub use reveal_item_in_dir::{reveal_item_in_dir, reveal_items_in_dir};

pub struct Opener<R: Runtime> {
// we use `fn() -> R` to silence the unused generic error
Expand Down Expand Up @@ -146,7 +146,15 @@ impl<R: Runtime> Opener<R> {
}

pub fn reveal_item_in_dir<P: AsRef<Path>>(&self, p: P) -> Result<()> {
crate::reveal_item_in_dir::reveal_item_in_dir(p)
reveal_item_in_dir(p)
}

pub fn reveal_items_in_dir<I, P>(&self, paths: I) -> Result<()>
where
I: IntoIterator<Item = P>,
P: AsRef<Path>,
{
reveal_items_in_dir(paths)
}
}

Expand Down Expand Up @@ -213,7 +221,8 @@ impl Builder {
.invoke_handler(tauri::generate_handler![
commands::open_url,
commands::open_path,
commands::reveal_item_in_dir
commands::reveal_item_in_dir,
commands::reveal_items_in_dir,
]);

if self.open_js_links_on_click {
Expand Down
Loading
Loading