implement revealItemInDir in JS

pull/2019/head
amrbashir 9 months ago
parent 8555563919
commit 5399e543e9
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -45,11 +45,11 @@ dunce = { workspace = true }
[target."cfg(windows)".dependencies.windows] [target."cfg(windows)".dependencies.windows]
version = "0.54" version = "0.54"
features = [ features = [
"Win32_Foundation", "Win32_Foundation",
"Win32_UI_Shell_Common", "Win32_UI_Shell_Common",
"Win32_UI_WindowsAndMessaging", "Win32_UI_WindowsAndMessaging",
"Win32_System_Com", "Win32_System_Com",
"Win32_System_Registry", "Win32_System_Registry",
] ]
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies] [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies]

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PLUGIN_OPENER__=function(n){"use strict";async function e(n,e={},_){return window.__TAURI_INTERNALS__.invoke(n,e,_)}return"function"==typeof SuppressedError&&SuppressedError,n.open=async function(n,_){await e("plugin:opener|open",{path:n,with:_})},n.revealInDir=async function(){return e("plugin:opener|reveal_item_in_dir")},n}({});Object.defineProperty(window.__TAURI__,"opener",{value:__TAURI_PLUGIN_OPENER__})} if("__TAURI__"in window){var __TAURI_PLUGIN_OPENER__=function(n){"use strict";async function e(n,e={},_){return window.__TAURI_INTERNALS__.invoke(n,e,_)}return"function"==typeof SuppressedError&&SuppressedError,n.open=async function(n,_){await e("plugin:opener|open",{path:n,with:_})},n.revealItemInDir=async function(n){return e("plugin:opener|reveal_item_in_dir",{path:n})},n}({});Object.defineProperty(window.__TAURI__,"opener",{value:__TAURI_PLUGIN_OPENER__})}

@ -39,8 +39,6 @@ import { invoke } from '@tauri-apps/api/core'
* ``` * ```
* *
* @param path The path or URL to open. * @param path The path or URL to open.
* This value is matched against the string regex defined on `tauri.conf.json > plugins > opener > open`,
* which defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
* @param openWith The app to open the file or URL with. * @param openWith The app to open the file or URL with.
* Defaults to the system default application for the specified path type. * Defaults to the system default application for the specified path type.
* *
@ -52,6 +50,24 @@ export async function open(path: string, openWith?: string): Promise<void> {
with: openWith with: openWith
}) })
} }
export async function revealInDir() {
return invoke('plugin:opener|reveal_item_in_dir') /**
* Reveal a path the system's default explorer.
*
* #### Platform-specific:
*
* - **Android / iOS:** Unsupported.
*
* @example
* ```typescript
* import { revealItemInDir } from '@tauri-apps/plugin-opener';
* await revealItemInDir('/path/to/file');
* ```
*
* @param path The path to reveal.
*
* @since 2.0.0
*/
export async function revealItemInDir(path: string) {
return invoke('plugin:opener|reveal_item_in_dir', { path })
} }

@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use std::path::PathBuf;
use tauri::{ use tauri::{
ipc::{CommandScope, GlobalScope}, ipc::{CommandScope, GlobalScope},
AppHandle, Runtime, AppHandle, Runtime,
@ -32,11 +34,13 @@ pub async fn open<R: Runtime>(
); );
if scope.is_allowed(&path)? { if scope.is_allowed(&path)? {
crate::open::open(path, with) crate::open(path, with)
} else { } else {
Err(Error::NotAllowed(path)) Err(Error::NotAllowed(path))
} }
} }
#[tauri::command] #[tauri::command]
pub async fn reveal_item_in_dir() {} pub async fn reveal_item_in_dir(path: PathBuf) -> crate::Result<()> {
crate::reveal_item_in_dir(path)
}

@ -4,7 +4,7 @@
use std::path::Path; use std::path::Path;
/// Show /// Reveal a path the system's default explorer.
/// ///
/// ## Platform-specific: /// ## Platform-specific:
/// ///

Loading…
Cancel
Save