跳转到内容
Tauri

指定打开应用

此插件允许你使用特定或者默认的应用程序打开文件或者 URL。它还可以在系统文件管理器中“显示”这些文件。

支持的平台

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android

Only allows to open URLs via open

ios

Only allows to open URLs via open

设置

首先安装“指定打开应用”插件。

使用项目的包管理器来添加依赖:

npm run tauri add opener

用法

此插件有 JavaScript 和 Rust 两种调用方式。

import { openPath } from '@tauri-apps/plugin-opener';
// 当配置为 `"withGlobalTauri": true` 时,你可以使用下面方式引入此插件
// const { openPath } = window.__TAURI__.opener;
// 使用默认的应用来打开文件
await openPath('/path/to/file');
// 在 Windows 上使用 `vlc` 打开文件
await openPath('C:/path/to/file', 'vlc');

权限

默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 capabilities 文件夹中的配置来启用它们。

参见能力概览以获取更多信息,以及插件的分步导览来调整插件权限。

src-tauri/capabilities/default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
{
"identifier": "opener:allow-open-path",
"allow": [
{
"path": "/path/to/file"
}
]
}
]
}

Default Permission

This permission set allows opening mailto:, tel:, https:// and http:// urls using their default application as well as reveal file in directories using default file explorer

  • allow-open-url
  • allow-reveal-item-in-dir
  • allow-default-urls

Permission Table

Identifier Description

opener:allow-default-urls

This enables opening mailto:, tel:, https:// and http:// urls using their default application.

opener:allow-open-path

Enables the open_path command without any pre-configured scope.

opener:deny-open-path

Denies the open_path command without any pre-configured scope.

opener:allow-open-url

Enables the open_url command without any pre-configured scope.

opener:deny-open-url

Denies the open_url command without any pre-configured scope.

opener:allow-reveal-item-in-dir

Enables the reveal_item_in_dir command without any pre-configured scope.

opener:deny-reveal-item-in-dir

Denies the reveal_item_in_dir command without any pre-configured scope.


© 2025 Tauri Contributors. CC-BY / MIT