@rescript-tauri/plugin-dialog

Tauri 2.x ネイティブダイアログプラグイン の ReScript バインディングです。open / save / message / ask / confirm を提供します。

注釈

本パッケージは main で機能完備済みです。初回 npm 公開は他のパッケージと合わせて予定されています。それまでは、ソースリポジトリ経由かワークスペースリンクで利用してください。

インストール

pnpm add @rescript-tauri/plugin-dialog @tauri-apps/plugin-dialog

@rescript-tauri/plugin-dialog@rescript-tauri/core@tauri-apps/plugin-dialog の両方を peerDependencies として宣言しています。

{
  "dependencies": [
    "@rescript-tauri/core",
    "@rescript-tauri/plugin-dialog"
  ]
}

Rust 側:

# src-tauri/Cargo.toml
[dependencies]
tauri-plugin-dialog = "2"
// src-tauri/src/main.rs
fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_dialog::init())
        .run(tauri::generate_context!())
        .expect("error while running app");
}

Capabilities

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "dialog:default"
  ]
}

dialog:default ですべてのダイアログ API をカバーできます。

最小例

open RescriptTauriPluginDialog

let pickedPath = await PluginDialog.openFile(~options={
  title: "Pick a file",
  filters: [{name: "Text", extensions: ["txt", "md"]}],
})
switch pickedPath->Nullable.toOption {
| Some(path) => Console.log("picked: " ++ path)
| None => Console.log("cancelled")
}

openFilepromise<Nullable.t<string>> を返します。Nullable.null は キャンセルを示すシグナルです。

公開 API

8 つの公開関数で上流の API 全体をカバーします:

関数

戻り値

備考

openFile

Nullable.t<string>

単一ファイルのピッカー

openFiles

Nullable.t<array<string>>

複数ファイルのピッカー

openDirectory

Nullable.t<string>

単一ディレクトリ

openDirectories

Nullable.t<array<string>>

複数ディレクトリ

save

Nullable.t<string>

保存先パスの選択

message

messageResultstring

情報 / 警告 / エラーのポップアップ

ask

bool

はい / いいえ の問い合わせ

confirm

bool

OK / キャンセル の問い合わせ

なぜ open* 関数が 4 つあるのか

上流の TypeScript の open(options)multiple / directory フラグに よって戻り値の型が変化します:

open({ multiple: true })
  // → string[] | null
open({ directory: false })
  // → string | null

ReScript のバインディングでは、phantom type やランタイム分岐なしにこの条件型戻り値を 表現できません。そこで API を 4 つの uncurried 関数に分割し、戻り値の型を バインディングレベルで固定しています。対応するオプションフラグ(multipledirectory)は openOptions レコードに 意図的に公開していません。必要な戻り値の形に合致する関数を 選んでください。

モバイル限定オプション

openOptions.pickerMode#document / #media / #image / #video)と openOptions.fileAccessMode#copy / #scoped)は、iOS / Android ビルドで後から利用できるようバインディングに残してあります。デスクトップでは下層プラグインが 無視するため害はありません。

互換性

コンポーネント

サポート範囲

上流の @tauri-apps/plugin-dialog

^2.7.0(peer)

Rust 側 tauri-plugin-dialog

2.x

@rescript-tauri/core

^0.1.0(peer)

ReScript

>=12.0.0

@rescript/core

>=1.6.0

OS

Linux / macOS / Windows

関連情報