@tauri-apps/plugin-opener
使用默认应用程序打开文件和 URL。
安全
此 API 具有作用域配置,强制您限制要打开的文件和 URL。
限制访问 open | open
API
在配置对象上,open: true
表示 open API 可以与任何 URL 一起使用,因为参数已使用 ^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+
正则表达式进行验证。您可以通过将布尔值更改为字符串来更改该正则表达式,例如 open: ^https://github.com/
。
函数
openPath()
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#L66
openUrl()
function openUrl(url, openWith?): Promise<void>
使用系统的默认应用程序或使用 openWith 指定的应用程序打开 URL。
参数
参数 | 类型 | 描述 |
---|---|---|
url | string | 要打开的 URL。 |
openWith ? | string | 用于打开 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#L41
revealItemInDir()
function revealItemInDir(path): Promise<unknown>
使用系统的默认资源管理器显示路径。
平台特定
- Android / iOS: 不支持。
参数
参数 | 类型 | 描述 |
---|---|---|
path | string | 要显示的路径。 |
返回值
Promise
<unknown
>
示例
import { revealItemInDir } from '@tauri-apps/plugin-opener';await revealItemInDir('/path/to/file');
始于
2.0.0
来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/opener/guest-js/index.ts#L90
© 2025 Tauri Contributors. CC-BY / MIT