1
2
3
4
5
6
7
8
9
10
| import { openPath, openUrl } 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');
// 用默认程序打开 URL:
await openUrl('https://tauri.app');
|
注意 app 是 App 或 AppHandle 的实例。
1
2
3
4
5
6
7
8
| use tauri_plugin_opener::OpenerExt;
// 用默认程序打开文件:
app.opener().open_path("/path/to/file", None::<&str>);
// 在 Windows 上用 `vlc` 命令打开文件:
app.opener().open_path("C:/path/to/file", Some("vlc"));
// 用默认程序打开 URL:
app.opener().open_url("https://tauri.app", None::<&str>);
|