@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 | 字串 | 要開啟的路徑。 |
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
Source: 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 | 字串 | 要開啟的 URL。 |
openWith ? | 字串 | 用於開啟 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
Source: 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 | 字串 | 要顯示的路徑。 |
回傳
Promise
<unknown
>
範例
import { revealItemInDir } from '@tauri-apps/plugin-opener';await revealItemInDir('/path/to/file');
起始版本
2.0.0
Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/opener/guest-js/index.ts#L90
© 2025 Tauri Contributors. CC-BY / MIT