@tauri-apps/plugin-opener
使用默认应用程序打开文件和 URL。
该 API 具有作用域配置,强制您限制可以打开的文件和 URL。
在配置对象中,open: true 意味着 open API 可以与任何 URL 一起使用,因为参数通过 ^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+ 正则表达式进行验证。您可以通过将布尔值更改为字符串来修改该正则表达式,例如 open: ^https://github.com/。
function openPath(path, openWith?): Promise<void>使用系统默认应用程序或 openWith 指定的应用程序打开路径。
| 参数 | 类型 | 描述 |
|---|---|---|
path | string | 要打开的路径。 |
openWith? | string | 用于打开该路径的应用程序。如果未指定,则默认为指定路径类型的系统默认应用程序。 |
Promise<void>
import { openPath } from '@tauri-apps/plugin-opener';
// opens a file using the default program:await openPath('/path/to/file');// opens a file using `vlc` command on Windows.await openPath('C:/path/to/file', 'vlc');2.0.0
来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/opener/guest-js/index.ts#L71
function openUrl(url, openWith?): Promise<void>使用系统默认应用程序或 openWith 指定的应用程序打开 URL。
| 参数 | 类型 | 描述 |
|---|---|---|
url | string | URL | 要打开的 URL。 |
openWith? | string | 用于打开该 URL 的应用程序。如果未指定,则默认为指定 URL 类型的系统默认应用程序。在移动设备上,openWith 可以提供为 inAppBrowser,以在应用内浏览器中打开 URL。否则,它将在系统默认浏览器中打开该 URL。 |
Promise<void>
import { openUrl } from '@tauri-apps/plugin-opener';
// opens the given URL on the default browser:await openUrl('https://github.com/tauri-apps/tauri');// opens the given URL using `firefox`:await openUrl('https://github.com/tauri-apps/tauri', 'firefox');2.0.0
来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/opener/guest-js/index.ts#L42
function revealItemInDir(path): Promise<void>使用系统默认资源管理器显示路径。
平台特定
- Android / iOS: 不支持。
| 参数 | 类型 | 描述 |
|---|---|---|
path | string | string[] | 要显示的路径。 |
Promise<void>
import { revealItemInDir } from '@tauri-apps/plugin-opener';await revealItemInDir('/path/to/file');await revealItemInDir([ '/path/to/file', '/path/to/another/file' ]);2.0.0
来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/opener/guest-js/index.ts#L96
© 2026 Tauri 贡献者。CC-BY / MIT