跳到主要內容
Tauri

Opener

此插件允許您在指定的或預設的應用程式中開啟檔案和 URL。它也支援在系統的檔案總管中「顯示」檔案。

支援平台

此插件需要至少 1.77.2 的 Rust 版本

平台 層級 備註
windows
linux
macos
android

僅允許透過 open 開啟 URL

ios

僅允許透過 open 開啟 URL

設定

安裝 opener 插件以開始使用。

使用專案的套件管理器新增依賴

npm run tauri add opener

使用方式

shell 插件在 JavaScript 和 Rust 中都可用。

import { openPath } from '@tauri-apps/plugin-opener';
// when using `"withGlobalTauri": true`, you may use
// const { openPath } = window.__TAURI__.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');

權限

預設情況下,所有潛在危險的插件命令和範圍都被封鎖且無法存取。您必須修改 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"
}
]
}
]
}

預設權限

此權限集允許使用預設應用程式開啟 mailto:tel:https://http:// URL,以及使用預設檔案總管顯示目錄中的檔案

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

權限表

識別符 描述

opener:allow-default-urls

這會啟用使用預設應用程式開啟 mailto:tel:https://http:// URL。

opener:allow-open-path

啟用 open_path 命令,而無需任何預先設定的範圍。

opener:deny-open-path

拒絕 open_path 命令,而無需任何預先設定的範圍。

opener:allow-open-url

啟用 open_url 命令,而無需任何預先設定的範圍。

opener:deny-open-url

拒絕 open_url 命令,而無需任何預先設定的範圍。

opener:allow-reveal-item-in-dir

啟用 reveal_item_in_dir 命令,而無需任何預先設定的範圍。

opener:deny-reveal-item-in-dir

拒絕 reveal_item_in_dir 命令,而無需任何預先設定的範圍。


© 2025 Tauri 貢獻者。CC-BY / MIT