Opener(ファイル・オープン)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
このプラグインを使用すると、ファイルや 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 |
| ios | | Only allows to open URLs via |
はじめに、「opener」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add openeryarn run tauri add openerpnpm tauri add openerdeno task tauri add openerbun tauri add openercargo tauri add opener-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-opener -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_opener::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-openeryarn add @tauri-apps/plugin-openerpnpm add @tauri-apps/plugin-openerdeno add npm:@tauri-apps/plugin-openerbun add @tauri-apps/plugin-opener
「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');app は App または AppHandle のインスタンスであることに注意してください。
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"));デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
以下にスコープ設定例を二つ示します。path と url はどちらも glob pattern syntax(グロブ・パターン構文)を使用して、許可されるファイルパスと URL を定義します。
グロブ・パターン glob pattern: ワイルドカードでファイル名のセットを検索・照合するために指定する文字パターンのこと《wikipedia》
最初の例は、openPath() 関数の特定のパスにアクセス権限を追加する方法を示します:
{ "$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" }, { "path": "$APPDATA/file" } ] } ]}二例目は、openUrl() 関数に対して、https://tauri.app URL そのものと、カスタム指定されているすべての URL(OS に認識されている必要があります)にアクセス権限を追加する方法を示します:
{ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "main-capability", "description": "Capability for the main window", "windows": ["main"], "permissions": [ { "identifier": "opener:allow-open-url", "allow": [ { "url": "https://tauri.app" }, { "url": "custom:*" } ] } ]}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
This default permission set includes the following:
allow-open-urlallow-reveal-item-in-dirallow-default-urls
Permission Table
| Identifier | Description |
|---|---|
|
|
This enables opening |
|
|
Enables the open_path command without any pre-configured scope. |
|
|
Denies the open_path command without any pre-configured scope. |
|
|
Enables the open_url command without any pre-configured scope. |
|
|
Denies the open_url command without any pre-configured scope. |
|
|
Enables the reveal_item_in_dir command without any pre-configured scope. |
|
|
Denies the reveal_item_in_dir command without any pre-configured scope. |
【※ この日本語版は、「Aug 9, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT