refactor(opener)!: rename reveal_item_in_dir command to reveal_items_in_dir (#3608)

* refactor(opener)!: rename reveal_item_in_dir command to reveal_items_in_dir

The `allow-reveal-item-in-dir` and `deny-reveal-item-in-dir` permissions
are now `allow-reveal-items-in-dir` and `deny-reveal-items-in-dir`. The
`revealItemInDir` JavaScript function and the Rust `Opener` methods are
unchanged.

* cr

* retain rust api

* fix build

* update docs, rename ts api

* cr

* Apply suggestion from @Legend-Master

---------

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>
This commit is contained in:
Lucas Fernandes Nogueira
2026-09-23 09:56:02 -03:00
committed by GitHub
co-authored by Tony
parent 9c550e267d
commit f2c77194d6
10 changed files with 45 additions and 23 deletions
@@ -0,0 +1,6 @@
---
"opener": major
"opener-js": major
---
**Breaking:** Renamed the `revealItemInDir` function to `revealItemsInDir`, which accepts a single path or an array of paths.
+6
View File
@@ -0,0 +1,6 @@
---
"opener": major
"opener-js": major
---
**Breaking:** Renamed the `reveal_item_in_dir` command to `reveal_items_in_dir`, so the `allow-reveal-item-in-dir` and `deny-reveal-item-in-dir` permissions are now `allow-reveal-items-in-dir` and `deny-reveal-items-in-dir`.
+1 -1
View File
@@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_OPENER__=function(n,e){"use strict";return n.openPath=async function(n,_){await e.invoke("plugin:opener|open_path",{path:n,with:_})},n.openUrl=async function(n,_){await e.invoke("plugin:opener|open_url",{url:n,with:_})},n.revealItemInDir=async function(n){const _="string"==typeof n?[n]:n;return e.invoke("plugin:opener|reveal_item_in_dir",{paths:_})},n}({},window.__TAURI__.core);Object.defineProperty(window.__TAURI__,"opener",{value:__TAURI_PLUGIN_OPENER__})} if("__TAURI__"in window){var __TAURI_PLUGIN_OPENER__=function(n,e){"use strict";return n.openPath=async function(n,_){await e.invoke("plugin:opener|open_path",{path:n,with:_})},n.openUrl=async function(n,_){await e.invoke("plugin:opener|open_url",{url:n,with:_})},n.revealItemsInDir=async function(n){const _="string"==typeof n?[n]:n;return e.invoke("plugin:opener|reveal_items_in_dir",{paths:_})},n}({},window.__TAURI__.core);Object.defineProperty(window.__TAURI__,"opener",{value:__TAURI_PLUGIN_OPENER__})}
+1 -1
View File
@@ -106,7 +106,7 @@ fn _f() {
}; };
} }
const COMMANDS: &[&str] = &["open_url", "open_path", "reveal_item_in_dir"]; const COMMANDS: &[&str] = &["open_url", "open_path", "reveal_items_in_dir"];
fn main() { fn main() {
tauri_plugin::Builder::new(COMMANDS) tauri_plugin::Builder::new(COMMANDS)
+6 -6
View File
@@ -76,7 +76,7 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
} }
/** /**
* Reveal a path with the system's default explorer. * Reveal one or more paths with the system's default explorer.
* *
* #### Platform-specific: * #### Platform-specific:
* *
@@ -84,16 +84,16 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
* *
* @example * @example
* ```typescript * ```typescript
* import { revealItemInDir } from '@tauri-apps/plugin-opener'; * import { revealItemsInDir } from '@tauri-apps/plugin-opener';
* await revealItemInDir('/path/to/file'); * await revealItemsInDir('/path/to/file');
* await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]); * await revealItemsInDir([ '/path/to/file', '/path/to/another/file' ]);
* ``` * ```
* *
* @param path The path to reveal. * @param path The path to reveal.
* *
* @since 2.0.0 * @since 2.0.0
*/ */
export async function revealItemInDir(path: string | string[]): Promise<void> { export async function revealItemsInDir(path: string | string[]): Promise<void> {
const paths = typeof path === 'string' ? [path] : path const paths = typeof path === 'string' ? [path] : path
return invoke('plugin:opener|reveal_item_in_dir', { paths }) return invoke('plugin:opener|reveal_items_in_dir', { paths })
} }
@@ -6,7 +6,7 @@ as well as reveal file in directories using default file explorer
#### This default permission set includes the following: #### This default permission set includes the following:
- `allow-open-url` - `allow-open-url`
- `allow-reveal-item-in-dir` - `allow-reveal-items-in-dir`
- `allow-default-urls` - `allow-default-urls`
## Permission Table ## Permission Table
@@ -73,12 +73,12 @@ Denies the open_url command without any pre-configured scope.
<tr> <tr>
<td> <td>
`opener:allow-reveal-item-in-dir` `opener:allow-reveal-items-in-dir`
</td> </td>
<td> <td>
Enables the reveal_item_in_dir command without any pre-configured scope. Enables the reveal_items_in_dir command without any pre-configured scope.
</td> </td>
</tr> </tr>
@@ -86,12 +86,12 @@ Enables the reveal_item_in_dir command without any pre-configured scope.
<tr> <tr>
<td> <td>
`opener:deny-reveal-item-in-dir` `opener:deny-reveal-items-in-dir`
</td> </td>
<td> <td>
Denies the reveal_item_in_dir command without any pre-configured scope. Denies the reveal_items_in_dir command without any pre-configured scope.
</td> </td>
</tr> </tr>
+1 -1
View File
@@ -5,6 +5,6 @@ description = """This permission set allows opening `mailto:`, `tel:`, `https://
as well as reveal file in directories using default file explorer""" as well as reveal file in directories using default file explorer"""
permissions = [ permissions = [
"allow-open-url", "allow-open-url",
"allow-reveal-item-in-dir", "allow-reveal-items-in-dir",
"allow-default-urls", "allow-default-urls",
] ]
+1 -2
View File
@@ -69,8 +69,7 @@ pub async fn open_path<R: Runtime>(
} }
} }
/// TODO: in the next major version, rename to `reveal_items_in_dir`
#[tauri::command] #[tauri::command]
pub async fn reveal_item_in_dir(paths: Vec<PathBuf>) -> crate::Result<()> { pub async fn reveal_items_in_dir(paths: Vec<PathBuf>) -> crate::Result<()> {
crate::reveal_items_in_dir(&paths) crate::reveal_items_in_dir(&paths)
} }
+13 -3
View File
@@ -17,7 +17,7 @@ mod commands;
mod config; mod config;
mod error; mod error;
mod open; mod open;
mod reveal_item_in_dir; mod reveal_items_in_dir;
mod scope; mod scope;
mod scope_entry; mod scope_entry;
#[cfg(windows)] #[cfg(windows)]
@@ -27,7 +27,7 @@ pub use error::Error;
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;
pub use open::{open_path, open_url}; pub use open::{open_path, open_url};
pub use reveal_item_in_dir::{reveal_item_in_dir, reveal_items_in_dir}; pub use reveal_items_in_dir::{reveal_item_in_dir, reveal_items_in_dir};
pub struct Opener<R: Runtime> { pub struct Opener<R: Runtime> {
// we use `fn() -> R` to silence the unused generic error // we use `fn() -> R` to silence the unused generic error
@@ -153,10 +153,20 @@ impl<R: Runtime> Opener<R> {
.map_err(Into::into) .map_err(Into::into)
} }
/// Reveal the given path in the system's default explorer.
///
/// ## Platform-specific:
///
/// - **Android / iOS:** Unsupported.
pub fn reveal_item_in_dir<P: AsRef<Path>>(&self, p: P) -> Result<()> { pub fn reveal_item_in_dir<P: AsRef<Path>>(&self, p: P) -> Result<()> {
reveal_item_in_dir(p) reveal_item_in_dir(p)
} }
/// Reveal one or more paths in the system's default explorer.
///
/// ## Platform-specific:
///
/// - **Android / iOS:** Unsupported.
pub fn reveal_items_in_dir<I, P>(&self, paths: I) -> Result<()> pub fn reveal_items_in_dir<I, P>(&self, paths: I) -> Result<()>
where where
I: IntoIterator<Item = P>, I: IntoIterator<Item = P>,
@@ -229,7 +239,7 @@ impl Builder {
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
commands::open_url, commands::open_url,
commands::open_path, commands::open_path,
commands::reveal_item_in_dir, commands::reveal_items_in_dir,
]); ]);
if self.open_js_links_on_click { if self.open_js_links_on_click {
@@ -10,8 +10,6 @@ use std::path::{Path, PathBuf};
/// ///
/// - **Android / iOS:** Unsupported. /// - **Android / iOS:** Unsupported.
pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> { pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> {
let path = canonicalize(path.as_ref())?;
#[cfg(any( #[cfg(any(
windows, windows,
target_os = "macos", target_os = "macos",
@@ -21,7 +19,7 @@ pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> {
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd"
))] ))]
return imp::reveal_items_in_dir(&[path]); return imp::reveal_items_in_dir(&[canonicalize(path.as_ref())?]);
#[cfg(not(any( #[cfg(not(any(
windows, windows,
@@ -32,7 +30,10 @@ pub fn reveal_item_in_dir<P: AsRef<Path>>(path: P) -> crate::Result<()> {
target_os = "netbsd", target_os = "netbsd",
target_os = "openbsd" target_os = "openbsd"
)))] )))]
Err(crate::Error::UnsupportedPlatform) {
let _path = path;
Err(crate::Error::UnsupportedPlatform)
}
} }
/// Reveal multiple paths in the system's default explorer. /// Reveal multiple paths in the system's default explorer.