From 5399e543e96ce5e556bef5e035e07534b1aff89f Mon Sep 17 00:00:00 2001 From: amrbashir Date: Thu, 7 Nov 2024 22:19:05 +0200 Subject: [PATCH] implement revealItemInDir in JS --- plugins/opener/Cargo.toml | 10 +++++----- plugins/opener/api-iife.js | 2 +- plugins/opener/guest-js/index.ts | 24 ++++++++++++++++++++---- plugins/opener/src/commands.rs | 8 ++++++-- plugins/opener/src/reveal_item_in_dir.rs | 2 +- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/plugins/opener/Cargo.toml b/plugins/opener/Cargo.toml index b162c830..e5a3fcf7 100644 --- a/plugins/opener/Cargo.toml +++ b/plugins/opener/Cargo.toml @@ -45,11 +45,11 @@ dunce = { workspace = true } [target."cfg(windows)".dependencies.windows] version = "0.54" features = [ - "Win32_Foundation", - "Win32_UI_Shell_Common", - "Win32_UI_WindowsAndMessaging", - "Win32_System_Com", - "Win32_System_Registry", + "Win32_Foundation", + "Win32_UI_Shell_Common", + "Win32_UI_WindowsAndMessaging", + "Win32_System_Com", + "Win32_System_Registry", ] [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\"))".dependencies] diff --git a/plugins/opener/api-iife.js b/plugins/opener/api-iife.js index 5b37b44e..345837b2 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){"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__})} diff --git a/plugins/opener/guest-js/index.ts b/plugins/opener/guest-js/index.ts index 0435fcc4..d586572f 100644 --- a/plugins/opener/guest-js/index.ts +++ b/plugins/opener/guest-js/index.ts @@ -39,8 +39,6 @@ import { invoke } from '@tauri-apps/api/core' * ``` * * @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. * Defaults to the system default application for the specified path type. * @@ -52,6 +50,24 @@ export async function open(path: string, openWith?: string): Promise { 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 }) } diff --git a/plugins/opener/src/commands.rs b/plugins/opener/src/commands.rs index 0cd58451..0190ccdb 100644 --- a/plugins/opener/src/commands.rs +++ b/plugins/opener/src/commands.rs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +use std::path::PathBuf; + use tauri::{ ipc::{CommandScope, GlobalScope}, AppHandle, Runtime, @@ -32,11 +34,13 @@ pub async fn open( ); if scope.is_allowed(&path)? { - crate::open::open(path, with) + crate::open(path, with) } else { Err(Error::NotAllowed(path)) } } #[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) +} diff --git a/plugins/opener/src/reveal_item_in_dir.rs b/plugins/opener/src/reveal_item_in_dir.rs index ca4b2ac9..70f6cc75 100644 --- a/plugins/opener/src/reveal_item_in_dir.rs +++ b/plugins/opener/src/reveal_item_in_dir.rs @@ -4,7 +4,7 @@ use std::path::Path; -/// Show +/// Reveal a path the system's default explorer. /// /// ## Platform-specific: ///