Skip to content

Commit

Permalink
implement revealItemInDir in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Nov 7, 2024
1 parent 8555563 commit 5399e54
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
10 changes: 5 additions & 5 deletions plugins/opener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion plugins/opener/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions plugins/opener/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -52,6 +50,24 @@ export async function open(path: string, openWith?: string): Promise<void> {
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 })
}
8 changes: 6 additions & 2 deletions plugins/opener/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -32,11 +34,13 @@ pub async fn open<R: Runtime>(
);

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)
}
2 changes: 1 addition & 1 deletion plugins/opener/src/reveal_item_in_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::path::Path;

/// Show
/// Reveal a path the system's default explorer.
///
/// ## Platform-specific:
///
Expand Down

0 comments on commit 5399e54

Please sign in to comment.