From f2c77194d6fc35fdc24ea4db86c583c27cb6db4e Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 23 Sep 2026 09:56:02 -0300 Subject: [PATCH] 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> --- .changes/opener-js-reveal-items-in-dir.md | 6 ++++++ .changes/opener-reveal-items-in-dir.md | 6 ++++++ plugins/opener/api-iife.js | 2 +- plugins/opener/build.rs | 2 +- plugins/opener/guest-js/index.ts | 12 ++++++------ .../permissions/autogenerated/reference.md | 10 +++++----- plugins/opener/permissions/default.toml | 2 +- plugins/opener/src/commands.rs | 3 +-- plugins/opener/src/lib.rs | 16 +++++++++++++--- ...eal_item_in_dir.rs => reveal_items_in_dir.rs} | 9 +++++---- 10 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 .changes/opener-js-reveal-items-in-dir.md create mode 100644 .changes/opener-reveal-items-in-dir.md rename plugins/opener/src/{reveal_item_in_dir.rs => reveal_items_in_dir.rs} (98%) diff --git a/.changes/opener-js-reveal-items-in-dir.md b/.changes/opener-js-reveal-items-in-dir.md new file mode 100644 index 000000000..47d0f7499 --- /dev/null +++ b/.changes/opener-js-reveal-items-in-dir.md @@ -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. diff --git a/.changes/opener-reveal-items-in-dir.md b/.changes/opener-reveal-items-in-dir.md new file mode 100644 index 000000000..61bf14eb0 --- /dev/null +++ b/.changes/opener-reveal-items-in-dir.md @@ -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`. diff --git a/plugins/opener/api-iife.js b/plugins/opener/api-iife.js index 57393c5fc..97fdd7aa7 100644 --- a/plugins/opener/api-iife.js +++ b/plugins/opener/api-iife.js @@ -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__})} diff --git a/plugins/opener/build.rs b/plugins/opener/build.rs index 64aecd91a..4362723e7 100644 --- a/plugins/opener/build.rs +++ b/plugins/opener/build.rs @@ -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() { tauri_plugin::Builder::new(COMMANDS) diff --git a/plugins/opener/guest-js/index.ts b/plugins/opener/guest-js/index.ts index 6b40da19c..255a1a5b9 100644 --- a/plugins/opener/guest-js/index.ts +++ b/plugins/opener/guest-js/index.ts @@ -76,7 +76,7 @@ export async function openPath(path: string, openWith?: string): Promise { } /** - * Reveal a path with the system's default explorer. + * Reveal one or more paths with the system's default explorer. * * #### Platform-specific: * @@ -84,16 +84,16 @@ export async function openPath(path: string, openWith?: string): Promise { * * @example * ```typescript - * import { revealItemInDir } from '@tauri-apps/plugin-opener'; - * await revealItemInDir('/path/to/file'); - * await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]); + * import { revealItemsInDir } from '@tauri-apps/plugin-opener'; + * await revealItemsInDir('/path/to/file'); + * await revealItemsInDir([ '/path/to/file', '/path/to/another/file' ]); * ``` * * @param path The path to reveal. * * @since 2.0.0 */ -export async function revealItemInDir(path: string | string[]): Promise { +export async function revealItemsInDir(path: string | string[]): Promise { 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 }) } diff --git a/plugins/opener/permissions/autogenerated/reference.md b/plugins/opener/permissions/autogenerated/reference.md index 05ed81955..4340dce48 100644 --- a/plugins/opener/permissions/autogenerated/reference.md +++ b/plugins/opener/permissions/autogenerated/reference.md @@ -6,7 +6,7 @@ as well as reveal file in directories using default file explorer #### This default permission set includes the following: - `allow-open-url` -- `allow-reveal-item-in-dir` +- `allow-reveal-items-in-dir` - `allow-default-urls` ## Permission Table @@ -73,12 +73,12 @@ Denies the open_url command without any pre-configured scope. -`opener:allow-reveal-item-in-dir` +`opener:allow-reveal-items-in-dir` -Enables the reveal_item_in_dir command without any pre-configured scope. +Enables the reveal_items_in_dir command without any pre-configured scope. @@ -86,12 +86,12 @@ Enables the reveal_item_in_dir command without any pre-configured scope. -`opener:deny-reveal-item-in-dir` +`opener:deny-reveal-items-in-dir` -Denies the reveal_item_in_dir command without any pre-configured scope. +Denies the reveal_items_in_dir command without any pre-configured scope. diff --git a/plugins/opener/permissions/default.toml b/plugins/opener/permissions/default.toml index 846d6e51b..dae643444 100644 --- a/plugins/opener/permissions/default.toml +++ b/plugins/opener/permissions/default.toml @@ -5,6 +5,6 @@ description = """This permission set allows opening `mailto:`, `tel:`, `https:// 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", ] diff --git a/plugins/opener/src/commands.rs b/plugins/opener/src/commands.rs index e22b41d41..f07704753 100644 --- a/plugins/opener/src/commands.rs +++ b/plugins/opener/src/commands.rs @@ -69,8 +69,7 @@ pub async fn open_path( } } -/// TODO: in the next major version, rename to `reveal_items_in_dir` #[tauri::command] -pub async fn reveal_item_in_dir(paths: Vec) -> crate::Result<()> { +pub async fn reveal_items_in_dir(paths: Vec) -> crate::Result<()> { crate::reveal_items_in_dir(&paths) } diff --git a/plugins/opener/src/lib.rs b/plugins/opener/src/lib.rs index d96244ca7..35a11fbbd 100644 --- a/plugins/opener/src/lib.rs +++ b/plugins/opener/src/lib.rs @@ -17,7 +17,7 @@ mod commands; mod config; mod error; mod open; -mod reveal_item_in_dir; +mod reveal_items_in_dir; mod scope; mod scope_entry; #[cfg(windows)] @@ -27,7 +27,7 @@ pub use error::Error; type Result = std::result::Result; 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 { // we use `fn() -> R` to silence the unused generic error @@ -153,10 +153,20 @@ impl Opener { .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>(&self, p: P) -> Result<()> { 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(&self, paths: I) -> Result<()> where I: IntoIterator, @@ -229,7 +239,7 @@ impl Builder { .invoke_handler(tauri::generate_handler![ commands::open_url, commands::open_path, - commands::reveal_item_in_dir, + commands::reveal_items_in_dir, ]); if self.open_js_links_on_click { diff --git a/plugins/opener/src/reveal_item_in_dir.rs b/plugins/opener/src/reveal_items_in_dir.rs similarity index 98% rename from plugins/opener/src/reveal_item_in_dir.rs rename to plugins/opener/src/reveal_items_in_dir.rs index b5da19060..d4192dde1 100644 --- a/plugins/opener/src/reveal_item_in_dir.rs +++ b/plugins/opener/src/reveal_items_in_dir.rs @@ -10,8 +10,6 @@ use std::path::{Path, PathBuf}; /// /// - **Android / iOS:** Unsupported. pub fn reveal_item_in_dir>(path: P) -> crate::Result<()> { - let path = canonicalize(path.as_ref())?; - #[cfg(any( windows, target_os = "macos", @@ -21,7 +19,7 @@ pub fn reveal_item_in_dir>(path: P) -> crate::Result<()> { target_os = "netbsd", target_os = "openbsd" ))] - return imp::reveal_items_in_dir(&[path]); + return imp::reveal_items_in_dir(&[canonicalize(path.as_ref())?]); #[cfg(not(any( windows, @@ -32,7 +30,10 @@ pub fn reveal_item_in_dir>(path: P) -> crate::Result<()> { target_os = "netbsd", target_os = "openbsd" )))] - Err(crate::Error::UnsupportedPlatform) + { + let _path = path; + Err(crate::Error::UnsupportedPlatform) + } } /// Reveal multiple paths in the system's default explorer.