mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-24 21:40:48 +02:00
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:
co-authored by
Tony
parent
9c550e267d
commit
f2c77194d6
@@ -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__})}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
*
|
||||
@@ -84,16 +84,16 @@ export async function openPath(path: string, openWith?: string): Promise<void> {
|
||||
*
|
||||
* @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<void> {
|
||||
export async function revealItemsInDir(path: string | string[]): Promise<void> {
|
||||
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:
|
||||
|
||||
- `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.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`opener:allow-reveal-item-in-dir`
|
||||
`opener:allow-reveal-items-in-dir`
|
||||
|
||||
</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>
|
||||
</tr>
|
||||
@@ -86,12 +86,12 @@ Enables the reveal_item_in_dir command without any pre-configured scope.
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`opener:deny-reveal-item-in-dir`
|
||||
`opener:deny-reveal-items-in-dir`
|
||||
|
||||
</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>
|
||||
</tr>
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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]
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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<T> = std::result::Result<T, Error>;
|
||||
|
||||
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> {
|
||||
// we use `fn() -> R` to silence the unused generic error
|
||||
@@ -153,10 +153,20 @@ impl<R: Runtime> Opener<R> {
|
||||
.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<()> {
|
||||
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<()>
|
||||
where
|
||||
I: IntoIterator<Item = P>,
|
||||
@@ -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 {
|
||||
|
||||
+5
-4
@@ -10,8 +10,6 @@ use std::path::{Path, PathBuf};
|
||||
///
|
||||
/// - **Android / iOS:** Unsupported.
|
||||
pub fn reveal_item_in_dir<P: AsRef<Path>>(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<P: AsRef<Path>>(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<P: AsRef<Path>>(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.
|
||||
Reference in New Issue
Block a user