@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 | 字符串 | 要打开的路径。 |
openWith ? | 字符串 | 用于打开路径的应用程序。如果未指定,则默认为指定路径类型的系统默认应用程序。 |
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 ? | 字符串 | 用于打开 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<unknown>
使用系统默认浏览器显示路径。
平台特定
- Android / iOS: 不支持。
参数 | 类型 | 描述 |
---|---|---|
path | 字符串 | 要显示的路径。 |
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#L95
© 2025 Tauri 贡献者。CC-BY / MIT