i18n(ja) JA texts for third 6 files in Plugins Sections (part 3) (#3566)

Co-authored-by: paul valladares <85648028+dreyfus92@users.noreply.github.com>
This commit is contained in:
Junichi TAKAI (たかい じゅんいち)
2025-11-09 10:33:56 +09:00
committed by GitHub
parent 0f4db0be99
commit 16d9a9196d
6 changed files with 1598 additions and 0 deletions

View File

@@ -0,0 +1,397 @@
---
title: Loggingログ記録
description: 設定可能なログ記録。
plugin: log
i18nReady: true
---
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} />
Tauri アプリ用の設定可能なログ記録。
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「log」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定" >
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
{ ' ' }
<CommandTabs
npm="npm run tauri add log"
yarn="yarn run tauri add log"
pnpm="pnpm tauri add log"
deno="deno task tauri add log"
bun="bun tauri add log"
cargo="cargo tauri add log"
/>
</TabItem>
<TabItem label = "手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-log
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={4}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_log::Builder::new().build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
3. お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします
<CommandTabs
npm = "npm install @tauri-apps/plugin-log"
yarn = "yarn add @tauri-apps/plugin-log"
pnpm = "pnpm add @tauri-apps/plugin-log"
deno = "deno add npm:@tauri-apps/plugin-log"
bun = "bun add @tauri-apps/plugin-log"
/>
</Steps>
</TabItem>
</Tabs>
## 使用法
<Steps>
1. まず、プラグインを Tauri に登録する必要があります。
```rust title="src-tauri/src/lib.rs" {1} {6-14}
use tauri_plugin_log::{Target, TargetKind};
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_log::Builder::new().build())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
2. すると、プラグインのすべての API は JavaScript ゲスト・バインディングを通じて利用できるようになります:
```javascript
import {
warn,
debug,
trace,
info,
error,
attachConsole,
attachLogger,
} from '@tauri-apps/plugin-log';
// `"withGlobalTauri": true` を使用する場合は、
// const { warn, debug, trace, info, error, attachConsole, attachLogger } = window.__TAURI__.log; を使用できます
```
</Steps>
## ログの記録
<Tabs syncKey="lang">
<TabItem label="JavaScript">
プラグインの `warn`、`debug`、`trace`、`info`、`error` API のいずれかを使用して、JavaScript コードから「ログ記録」を生成します。
```js
import { warn, debug, trace, info, error } from '@tauri-apps/plugin-log';
trace('Trace');
info('Info');
error('Error');
```
すべての `console` メッセージを「log」プラグインに自動転送するには、次のように書き換えます
```ts
import { warn, debug, trace, info, error } from '@tauri-apps/plugin-log';
function forwardConsole(
fnName: 'log' | 'debug' | 'info' | 'warn' | 'error',
logger: (message: string) => Promise<void>
) {
const original = console[fnName];
console[fnName] = (message) => {
original(message);
logger(message);
};
}
forwardConsole('log', trace);
forwardConsole('debug', debug);
forwardConsole('info', info);
forwardConsole('warn', warn);
forwardConsole('error', error);
```
</TabItem>
<TabItem label="Rust">
Rust 側で自分のログを作成するには、[`log` crate] を使用します:
```rust
log::error!("something bad happened!");
log::info!("Tauri is awesome!");
```
[`log` crate] を `Cargo.toml` ファイルに追加する必要があることに注意してください。
```toml
[dependencies]
log = "0.4"
```
</TabItem>
</Tabs>
## ログの対象(ターゲット)
「log」プラグイン・ビルダーには、すべてのアプリケーション・ログの共通の送り先を設定できる `targets` 関数があります。
:::note
デフォルトでは、このプラグインは「stdout」標準出力と「アプリケーション・ログ・ディレクトリ」内のファイルにログを記録します。
自分のログ・ターゲットだけを使用するには、`clear_targets` を呼び出してください。
```rust
tauri_plugin_log::Builder::new()
.clear_targets()
.build()
```
:::
### ログのターミナル出力
すべてのログをターミナルに転送するには、`Stdout` または `Stderr` をターゲットとして有効化します。
```rust
tauri_plugin_log::Builder::new()
.target(tauri_plugin_log::Target::new(
tauri_plugin_log::TargetKind::Stdout,
))
.build()
```
このターゲットはデフォルトで有効化されています。
### Webview コンソールへのログ出力
Webview コンソールにすべての Rust ログを表示するには、`Webview` ターゲットを有効にし、フロントエンドで `attachConsole` を実行します:
```rust
tauri_plugin_log::Builder::new()
.target(tauri_plugin_log::Target::new(
tauri_plugin_log::TargetKind::Webview,
))
.build()
```
```js
import { attachConsole } from '@tauri-apps/plugin-log';
const detach = await attachConsole();
// コンソールへのログ出力が不要になった場合には、detach() を呼び出してください。
```
### 永続ログ
すべてのログをファイルに書き込むには、`LogDir` または `Folder` ターゲットのいずれかを使用します。
<TranslationNote lang="ja">
**永続ログ** persisting log 通常 persistent log システムやアプリケーションが終了・再起動してもログ・データの履歴を保持する仕組み。
</TranslationNote>
- `LogDir`:
```rust
tauri_plugin_log::Builder::new()
.target(tauri_plugin_log::Target::new(
tauri_plugin_log::TargetKind::LogDir {
file_name: Some("logs".to_string()),
},
))
.build()
```
`LogDir` ターゲットを使用すると、すべてのログは推奨されるログ・ディレクトリに保存されます。
次の表は、プラットフォームごとのログの場所を示しています:
| Platform | Value | 設定例 |
| -------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------- |
| Linux | `$XDG_DATA_HOME/{bundleIdentifier}/logs` or `$HOME/.local/share/{bundleIdentifier}/logs` | `/home/alice/.local/share/com.tauri.dev/logs` |
| macOS | `{homeDir}/Library/Logs/{bundleIdentifier}` | `/Users/Alice/Library/Logs/com.tauri.dev` |
| Windows | `{FOLDERID_LocalAppData}/{bundleIdentifier}/logs` | `C:\Users\Alice\AppData\Local\com.tauri.dev\logs` |
- `Folder`:
`Folder` ターゲットを使用すると、ファイル・システム内のカスタムな場所にログを書き込むことができます。
```rust
tauri_plugin_log::Builder::new()
.target(tauri_plugin_log::Target::new(
tauri_plugin_log::TargetKind::Folder {
path: std::path::PathBuf::from("/path/to/logs"),
file_name: None,
},
))
.build()
```
デフォルトの `file_name` は「アプリケーション名」です。
#### ログ・ファイルの動作設定
デフォルトでは、ログ・ファイルは最大サイズに到達すると破棄されます。
最大ファイル・サイズは、ビルダーの `max_file_size` 関数を使用して設定できます:
```rust
tauri_plugin_log::Builder::new()
.max_file_size(50_000 /* bytes */)
.build()
```
Tauri は、ログ・ファイルがサイズ上限に達したときに、以前のファイルを破棄するのではなく、自動的にログ・ファイルを入れ替えます。
この動作は `rotation_strategy`(入れ替え方式)を使用して設定できます:
```rust
tauri_plugin_log::Builder::new()
.rotation_strategy(tauri_plugin_log::RotationStrategy::KeepAll)
.build()
```
### ログ・フィルター
デフォルトでは**すべての**ログが処理されます。ログの量を減らし、関連する情報のみをフィルタリングする方法がいくつかあります。
### 最大ログ・レベル
最大ログ・レベルを設定するには、`level` 関数を使用します:
```rust
tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Info)
.build()
```
上記の設定例では、「デバッグ・ログ」と「トレース・ログ」は _info情報_ よりもレベルが低いため破棄されます。
個々のモジュールごとにそれぞれ最大レベルを定義することもできます:
```rust
tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Info)
// コマンド・モジュールのみ詳細ログ
.level_for("my_crate_name::commands", log::LevelFilter::Trace)
.build()
```
これらの API は [`log` crate] を使用するため、`Cargo.toml` ファイルに追加する必要があることに注意してください:
```toml
[dependencies]
log = "0.4"
```
### ターゲット・フィルター
メタデータをチェックして不要なログを破棄するように `filter` 関数を定義できます:
```rust
tauri_plugin_log::Builder::new()
// ターゲット "hyper" のログを除外します
.filter(|metadata| metadata.target() != "hyper")
.build()
```
### 書式設定(フォーマット)
「log」プラグインは、各ログ・レコードを `DATE[TARGET][LEVEL] MESSAGE` のようなフォーマットに書式設定します。
カスタム・フォーマットの機能は `format` で提供されます。
```rust
tauri_plugin_log::Builder::new()
.format(|out, message, record| {
out.finish(format_args!(
"[{} {}] {}",
record.level(),
record.target(),
message
))
})
.build()
```
#### ログの日付
デフォルトでは、「log」プラグインは UTC タイムゾーンを使用して日付を指定します。
ただし、`timezone_strategy` を使用してローカル・タイムゾーンを使用するように設定できます。
<TranslationNote lang="ja">
**UTC** 協定世界時coordinated universal time。所謂「国際標準時」。日本標準時は、「UTC+9 時間」となります。《[wikipedia](https://ja.wikipedia.org/wiki/協定世界時)》
</TranslationNote>
```rust
tauri_plugin_log::Builder::new()
.timezone_strategy(tauri_plugin_log::TimezoneStrategy::UseLocal)
.build()
```
## アクセス権限 Permissions
デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、`capabilities` 設定でアクセス権限を変更する必要があります。
詳細については「[セキュリティ・レベル Capabilities](/ja/security/capabilities/)」の章を参照してください。また、プラグインのアクセス権限を設定するには「[プライグン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」の章のステップ・バイ・ステップ・ガイドを参照してください。
```json title="src-tauri/capabilities/default.json" ins={6}
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": ["log:default"]
}
```
<PluginPermissions plugin={frontmatter.plugin} />
[`log` crate]: https://crates.io/crates/log
<div style="text-align: right;">
【※ この日本語版は、「Jul 3, 2025 英語版」に基づいています】
</div>

View File

@@ -0,0 +1,455 @@
---
title: NFC近距離無線通信
description: Android および iOS で NFC タグを読み書きします。
plugin: nfc
i18nReady: true
---
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} />
Android および iOS で NFC タグを読み書きします。
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「nfc」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定">
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
{' '}
<CommandTabs
npm="npm run tauri add nfc"
yarn="yarn run tauri add nfc"
pnpm="pnpm tauri add nfc"
bun="bun tauri add nfc"
cargo="cargo tauri add nfc"
/>
</TabItem>
<TabItem label="手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-nfc --target 'cfg(any(target_os = "android", target_os = "ios"))'
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={5-6}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
#[cfg(mobile)]
app.handle().plugin(tauri_plugin_nfc::init());
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
3. お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします
<CommandTabs
npm="npm install @tauri-apps/plugin-nfc"
yarn="yarn add @tauri-apps/plugin-nfc"
pnpm="pnpm add @tauri-apps/plugin-nfc"
deno="deno add npm:@tauri-apps/plugin-nfc"
bun="bun add @tauri-apps/plugin-nfc"
/>
</Steps>
</TabItem>
</Tabs>
## 設定
「NFC」プラグインは、iOS では「ネイティブ設定」OS 固有の設定)が必要です。
### iOS
iOS で NFC API にアクセスするには、対象の iOS バージョンに適合させ、Info.plist ファイルで使用方法の説明を設定し、アプリケーションに NFC 機能を追加する必要があります。
#### 対象 IOS バージョン
「NFC」プラグインには **iOS 14** 以降が必要です。これは Tauri CLI v2.8 以降で作成された Tauri アプリケーションではデフォルトですが、あなたの Xcode プロジェクトを編集して設定可能です。
`src-tauri/gen/apple/<project-name>.xcodeproj/project.pbxproj` ファイルで、すべての `IPHONEOS_DEPLOYMENT_TARGET` プロパティを `14.0` に設定します:
```title="src-tauri/gen/apple/<project-name>.xcodeproj/project.pbxproj"
/* Begin XCBuildConfiguration section */
<random-id> /* release */ = {
isa = XCBuildConfiguration;
buildSettings = {
...
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
};
name = release;
};
<random-id> /* debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
...
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
};
name = debug;
};
```
あるいは、Xcode の `General > Minimum Deployments > iOS` (一般 > 最小デプロイメント > iOS設定で「デプロイメント・ターゲット」公開対象を設定することもできます。
<TranslationNote lang="ja">
**デプロイメント** deployment 「展開・配置」 開発したソフトウェアやアプリケーションなどを、ユーザーが使えるように、実際の運用環境本番環境に配置・公開して、利用可能な状態にする一連の作業やプロセス全般を指す用語。《参考[英辞郎](https://eowf.alc.co.jp/search?q=deployment)、[wikipedia](https://ja.wikipedia.org/wiki/ソフトウェアデプロイメント)》
</TranslationNote>
#### Info.plist
iOS では、「NFC」プラグインに `NFCReaderUsageDescription` 情報プロパティ・リストの値が必要です。この値で、あなたのアプリがなぜ NFC タグのスキャンや書き込みを必要とするのか、その理由を説明する必要があります。
`src-tauri/Info.ios.plist` ファイルに次のスニペットを追加します:
```xml title=src-tauri/Info.ios.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NFCReaderUsageDescription</key>
<string>Read and write various NFC tags</string> // 様々な NFC タグの読み取りと書き込み
</dict>
</plist>
```
#### NFC 機能
さらに、iOS では NFC 機能をアプリケーションに関連付ける必要があります。
この機能は、Xcode のプロジェクト設定内の「Signing & Capabilities」署名と機能タブで「+ Capability」+ 機能ボタンをクリックし、「Near Field Communication Tag Reading」近距離無線通信タグ読み取り機能を選択することで追加できます。
(詳細については、[Add a capability to a target](ターゲットに機能を追加する)を参照してください。)
あるいは、`gen/apple/<app-name>_iOS/<app-name>_iOS.entitlements` ファイルに以下の設定を追加することでも追加できます:
```xml title="gen/apple/<app-name>_iOS/<app-name>_iOS.entitlements"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>TAG</string>
</array>
</dict>
</plist>
```
## 使用法
「NFC」プラグインは JavaScript と Rust の両方で利用可能で、これにより NFC タグをスキャンしたり、NFC タグに書き込んだりすることができます。
### NFCがサポートされているかどうかの確認
すべてのモバイル・デバイスに NFC タグのスキャン機能が搭載されているわけではありません。スキャンおよび書き込み API を使用する前に、NFC が利用できるかを確認する必要があります。
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import { isAvailable } from '@tauri-apps/plugin-nfc';
const canScanNfc = await isAvailable();
```
</TabItem>
<TabItem label="Rust">
```rust
tauri::Builder::default()
.setup(|app| {
#[cfg(mobile)]
{
use tauri_plugin_nfc::NfcExt;
app.handle().plugin(tauri_plugin_nfc::init());
let can_scan_nfc = app.nfc().is_available()?;
}
Ok(())
})
```
</TabItem>
</Tabs>
### NFC タグのスキャン
このプラグインは、一般的な NFC タグや、NDEFNFCデータ交換フォーマットメッセージを持つ NFC タグをスキャンできます。
NDEF は、入力データを NFC タグにカプセル化(格納)するための標準形式です。
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import { scan } from '@tauri-apps/plugin-nfc';
const scanType = {
type: 'ndef', // または 'tag',
};
const options = {
keepSessionAlive: false,
// iOSの「NFC スキャン」ダイアログに表示されるメッセージを設定
message: 'Scan a NFC tag',
successMessage: 'NFC tag successfully scanned',
};
const tag = await scan(scanType, options);
```
</TabItem>
<TabItem label="Rust">
```rust
tauri::Builder::default()
.setup(|app| {
#[cfg(mobile)]
{
use tauri_plugin_nfc::NfcExt;
app.handle().plugin(tauri_plugin_nfc::init());
let tag = app
.nfc()
.scan(tauri_plugin_nfc::ScanRequest {
kind: tauri_plugin_nfc::ScanKind::Ndef {
mime_type: None,
uri: None,
tech_list: None,
},
keep_session_alive: false,
})?
.tag;
}
Ok(())
})
```
</TabItem>
</Tabs>
:::note
`keepSessionAlive` オプションは、スキャンした NFC タグに後から直接書き込むことを可能にします。
このオプションを指定しない場合は、次の `write()` 呼び出しでセッションが再作成されます。
これは、アプリがタグを再スキャンしようとすることを意味します。
:::
#### フィルター
NFC スキャナーは、特定の URI 形式、MIME タイプ、または NFC タグの各技術を利用したタグもフィルタリングすることができます。
この場合、スキャンでは指定されたフィルタリング条件に一致するタグのみが検出されます。
<TranslationNote lang="ja">
**URI 形式** Uniform Resource Identifier 統一資源識別子URL と URN
**MINE タイプ** Multipurpose Internet Mail Extensions 多目的インターネットメール拡張書式。
</TranslationNote>
:::note
フィルタリングは Android でのみ利用可能で、スキャンした NFC タグの内容は常に確認する必要があります。
MIME タイプでは大文字と小文字が区別があるため、小文字で指定する必要があります。
:::
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import { scan, TechKind } from '@tauri-apps/plugin-nfc';
const techLists = [
// NfcF 方式Felica 方式)を用いて何でもキャプチャします
[TechKind.NfcF],
// NDEFNFC データ変換フォーマット)のデータ内容(ペイロード)を用いてすべての MIFARE Classics をキャプチャします
[TechKind.NfcA, TechKind.MifareClassic, TechKind.Ndef],
];
const tag = await scan({
type: 'ndef', // または 'tag'
mimeType: 'text/plain',
uri: {
scheme: 'https',
host: 'my.domain.com',
pathPrefix: '/app',
},
techLists,
});
```
</TabItem>
<TabItem label="Rust">
```rust
tauri::Builder::default()
.setup(|app| {
#[cfg(mobile)]
{
use tauri_plugin_nfc::NfcExt;
app.handle().plugin(tauri_plugin_nfc::init());
let tag = app
.nfc()
.scan(tauri_plugin_nfc::ScanRequest {
kind: tauri_plugin_nfc::ScanKind::Ndef {
mime_type: Some("text/plain".to_string()),
uri: Some(tauri_plugin_nfc::UriFilter {
scheme: Some("https".to_string()),
host: Some("my.domain.com".to_string()),
path_prefix: Some("/app".to_string()),
}),
tech_list: Some(vec![
vec![tauri_plugin_nfc::TechKind::Ndef],
]),
},
})?
.tag;
}
Ok(())
})
```
</TabItem>
</Tabs>
<TranslationNote lang="ja">
**NFC の通信方式**: 大きく分けると三種類あります:
- Type-A 方式NFC-A 国際標準で普及版(データ暗号化なし)
- Type-B 方式NFC-B 国際標準の高セキュリティ版
- Type-F 方式NFC-F 日本の主流方式Felica
**MIFARE** マイフェア NXPセミコンダクターズが開発した非接触 IC カードRFID の通信規格(国際規格)。その中の MIFARE Classic 規格は設計が古く、セキュリティに脆弱性が発見されており、新規採用は非推奨。《参考 [wikipedia](https://ja.wikipedia.org/wiki/MIFARE)》
</TranslationNote>
### NFC タグへの書き込み
`write` API を使用して、NFC タグにペイロード(デジタル・データ)を書き込むことができます。
もし `keepSessionAlive: true` を用いてスキャンされたタグがない場合(「[NFC タグのスキャン](#nfc-タグのスキャン)」項の Note 欄参照)、アプリケーションは最初に NFC タグをスキャンします。
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import { write, textRecord, uriRecord } from '@tauri-apps/plugin-nfc';
const payload = [uriRecord('https://tauri.app'), textRecord('some payload')];
const options = {
// 「種類 kind」は、スキャンされたタグセッションが稼働していない場合にのみ必要です
// その形式は scan() に渡される引数と同じです
kind: {
type: 'ndef',
},
// iOSの「Scan NFCNFC をスキャン)」ダイアログに表示されるメッセージを設定します
message: 'Scan a NFC tag',
successfulReadMessage: 'NFC tag successfully scanned',
successMessage: 'NFC tag successfully written',
};
await write(payload, options);
```
</TabItem>
<TabItem label="Rust">
:::caution
Rust API は、現在、NFC ペイロードを書き込むための低レベルのインターフェースのみを提供しています。
この API は近いうちに強化される予定です。
:::
```rust
tauri::Builder::default()
.setup(|app| {
#[cfg(mobile)]
{
use tauri_plugin_nfc::NfcExt;
app.handle().plugin(tauri_plugin_nfc::init());
app
.nfc()
.write(vec![
tauri_plugin_nfc::NfcRecord {
format: tauri_plugin_nfc::NFCTypeNameFormat::NfcWellKnown,
kind: vec![0x55], // URI の記録
id: vec![],
payload: vec![], // ここにペイロードを挿入
}
])?;
}
Ok(())
})
```
</TabItem>
</Tabs>
## アクセス権限 Permissions
デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、`capabilities` 設定でアクセス権限を変更する必要があります。
詳細については「[セキュリティ・レベル Capabilities](/ja/security/capabilities/)」の章を参照してください。また、プラグインのアクセス権限を設定するには「[プライグン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」の章のステップ・バイ・ステップ・ガイドを参照してください。
```json title="src-tauri/capabilities/default.json" ins={4}
{
"permissions": [
...,
"nfc:default",
]
}
```
<PluginPermissions plugin={frontmatter.plugin} />
[Add a capability to a target]: https://help.apple.com/xcode/mac/current/#/dev88ff319e7
<div style="text-align: right;">
【※ この日本語版は、「Aug 16, 2025 英語版」に基づいています】
</div>

View File

@@ -0,0 +1,329 @@
---
title: Notifications通知
description: ネイティブ通知をユーザーに送信します。
i18nReady: true
plugin: notification
---
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import PluginPermissions from '@components/PluginPermissions.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} />
「notification通知」プラグインを使用して、ユーザーにネイティブ通知を送信します。
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「notifications」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定">
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
<CommandTabs npm="npm run tauri add notification"
yarn="yarn run tauri add notification"
pnpm="pnpm tauri add notification"
bun="bun tauri add notification"
deno="deno task tauri add notification"
cargo="cargo tauri add notification" />
</TabItem>
<TabItem label="手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-notification
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={4}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_notification::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
3. JavaScript で「noficication通知」を使用する場合は、npm パッケージもインストールしてください:
<CommandTabs
npm="npm install @tauri-apps/plugin-notification"
yarn="yarn add @tauri-apps/plugin-notification"
pnpm="pnpm add @tauri-apps/plugin-notification"
deno="bun add npm:@tauri-apps/plugin-notification"
bun="bun add @tauri-apps/plugin-notification"
/>
</Steps>
</TabItem>
</Tabs>
## 使用法
以下に「notification」プラグインの使用方法の例をいくつか示します
- [ユーザーへ Notification通知を送信](#notification通知を送信)
- [Notification通知にアクションを追加](#actionsアクション)
- [Notification通知に添付ファイルを追加](#attachments添付ファイル)
- [特定のチャンネルで Notification通知を送信](#channelsチャンネル)
「notification」プラグインは JavaScript と Rust の両方で利用できます。
### Notification通知を送信
「通知 notification」を送信するには、次の手順に従ってください
<Steps>
1. アクセス権限が与えられているかどうかを確認します
2. アクセス権限が与えられていない場合はその許可を要求します
3. 「通知」を送信します
</Steps>
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import {
isPermissionGranted,
requestPermission,
sendNotification,
} from '@tauri-apps/plugin-notification';
// `"withGlobalTauri": true` を使用する場合は、
// const { isPermissionGranted, requestPermission, sendNotification, } = window.__TAURI__.notification; を使用できます
// 通知を送信するためのアクセス権限はありますか?
let permissionGranted = await isPermissionGranted();
// アクセス権限が設定されていない場合はアクセス権限を要求する必要があります
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
// アクセス権限が付与され次第、通知が送信されます
if (permissionGranted) {
sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' });
}
```
</TabItem>
<TabItem label="Rust">
```rust
tauri::Builder::default()
.plugin(tauri_plugin_notification::init())
.setup(|app| {
use tauri_plugin_notification::NotificationExt;
app.notification()
.builder()
.title("Tauri")
.body("Tauri is awesome")
.show()
.unwrap();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
```
</TabItem>
</Tabs>
### Actionsアクション
:::caution[Mobile のみ]
「Actions」API はモバイル・プラットフォームでのみ利用できます。
:::
Actionsアクションは、notification通知にインタラクティブ対話型のボタンや入力機能を追加します。これらを使用することで、ユーザーにとって応答性のよい使用感を実現できます。
#### アクションタイプの登録
インタラクティブな要素を定義するには、アクション・タイプを登録します:
```javascript
import { registerActionTypes } from '@tauri-apps/plugin-notification';
await registerActionTypes([
{
id: 'messages',
actions: [
{
id: 'reply',
title: 'Reply',
input: true,
inputButtonTitle: 'Send',
inputPlaceholder: 'Type your reply...',
},
{
id: 'mark-read',
title: 'Mark as Read',
foreground: false,
},
],
},
]);
```
#### アクション・プロパティ(属性)
| プロパティ(属性) | 説明 |
| ------------------------ | ---------------------------------- |
| `id` | アクションの一意の識別子 |
| `title` | アクションボタンのテキストを表示 |
| `requiresAuthentication` | デバイス認証が必要 |
| `foreground` | トリガーされるとアプリを前面に配置 |
| `destructive` | iOS ではアクションが赤で表示 |
| `input` | テキスト入力を有効化 |
| `inputButtonTitle` | 入力送信ボタン用の表示テキスト |
| `inputPlaceholder` | 入力フィールド用の表示テキスト |
#### アクションへの応答検知
「通知 notification」アクションでのユーザーの対話型操作の状態を監視検知します
```javascript
import { onAction } from '@tauri-apps/plugin-notification';
await onAction((notification) => {
console.log('Action performed:', notification);
});
```
### Attachments添付ファイル
添付ファイルは「通知 notification」にメディア・コンテンツを追加します。サポート状況はプラットフォームによって異なります。
```javascript
import { sendNotification } from '@tauri-apps/plugin-notification';
sendNotification({
title: 'New Image',
body: 'Check out this picture',
attachments: [
{
id: 'image-1',
url: 'asset:///notification-image.jpg',
},
],
});
```
#### 添付ファイルのプロパティ(属性)
| プロパティ | 説明 |
| ---------- | ------------------------------------------------------------ |
| `id` | 一意の識別子 |
| `url` | asset:// または file:// プロトコルを使用したコンテンツの URL |
注: 添付ファイルがターゲット・プラットフォームで利用できるかどうかの確認を行なってください。
### Channelsチャンネル
「チャンネル」は、notification通知を異なる動作ごとに分類するものです。主に Android で使用されますが、どのプラットフォームにも一貫した API を提供します。
#### チャンネルの作成
```javascript
import {
createChannel,
Importance,
Visibility,
} from '@tauri-apps/plugin-notification';
await createChannel({
id: 'messages',
name: 'Messages',
description: 'Notifications for new messages',
importance: Importance.High,
visibility: Visibility.Private,
lights: true,
lightColor: '#ff0000',
vibration: true,
sound: 'notification_sound',
});
```
#### チャンネルのプロパティ(属性)
| プロパティ | 説明 |
| ------------- | ------------------------------------------------- |
| `id` | 一意の識別子 |
| `name` | 表示名 |
| `description` | 目的の説明 |
| `importance` | 優先度レベル(なし、最小、低、デフォルト、高) |
| `visibility` | プライバシー設定(秘密、非公開、公開) |
| `lights` | notification通知LED の有効化Android    |
| `lightColor` | LED の色Android |
| `vibration` | バイブレーション機能の有効化 |
| `sound` | カスタム・サウンド・ファイル名 |
#### チャンネルの管理
既存のチャネルを一覧表示します:
```javascript
import { channels } from '@tauri-apps/plugin-notification';
const existingChannels = await channels();
```
チャンネルを削除します:
```javascript
import { removeChannel } from '@tauri-apps/plugin-notification';
await removeChannel('messages');
```
#### チャンネルの使用
チャンネルを使用して notification通知を送信します
```javascript
import { sendNotification } from '@tauri-apps/plugin-notification';
sendNotification({
title: 'New Message',
body: 'You have a new message',
channelId: 'messages',
});
```
注: notification通知を送信する前に、その通知が参照するチャンネルを作成してください。無効なチャンネル ID の場合、通知は表示されません。
## セキュリティに関する配慮
ユーザー入力の通常の安全化手順(機密情報の削除)以外には、現在のところセキュリティに関して考慮すべき事柄はありません。
<PluginPermissions plugin={frontmatter.plugin} />
<div style="text-align: right;">
【※ この日本語版は、「Nov 10, 2024 英語版」に基づいています】
</div>

View File

@@ -0,0 +1,185 @@
---
title: Openerファイル・オープン
description: ファイルと URL を外部アプリケーションで開きます。
plugin: opener
i18nReady: true
---
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} />
このプラグインを使用すると、ファイルや URL を、指定したアプリケーションまたはデフォルトのアプリケーションで開くことができます。また、システムのファイル・エクスプローラーでファイルを「表示」することもできます。
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「opener」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定" >
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
{ ' ' }
<CommandTabs
npm="npm run tauri add opener"
yarn="yarn run tauri add opener"
pnpm="pnpm tauri add opener"
deno="deno task tauri add opener"
bun="bun tauri add opener"
cargo="cargo tauri add opener"
/>
</TabItem>
<TabItem label = "手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-opener
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={4}
#[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");
}
```
3. お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします
<CommandTabs
npm = "npm install @tauri-apps/plugin-opener"
yarn = "yarn add @tauri-apps/plugin-opener"
pnpm = "pnpm add @tauri-apps/plugin-opener"
deno = "deno add npm:@tauri-apps/plugin-opener"
bun = "bun add @tauri-apps/plugin-opener"
/>
</Steps>
</TabItem>
</Tabs>
## 使用法
「opener」プラグインは、JavaScript と Rust の両方で利用できます。
<Tabs syncKey="lang">
<TabItem label="JavaScript" >
```javascript
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');
```
</TabItem>
<TabItem label = "Rust" >
`app` は `App` または [`AppHandle`](https://docs.rs/tauri/2.0.0/tauri/struct.AppHandle.html) のインスタンスであることに注意してください。
```rust
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"));
```
</TabItem>
</Tabs>
## アクセス権限 Permissions
デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、`capabilities` 設定でアクセス権限を変更する必要があります。
詳細については「[セキュリティ・レベル Capabilities](/ja/security/capabilities/)」の章を参照してください。また、プラグインのアクセス権限を設定するには「[プライグン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」の章のステップ・バイ・ステップ・ガイドを参照してください。
以下にスコープ設定例を二つ示します。`path` と `url` はどちらも [glob pattern syntax](https://docs.rs/glob/latest/glob/struct.Pattern.html)(グロブ・パターン構文)を使用して、許可されるファイルパスと URL を定義します。
<TranslationNote lang="ja">
**グロブ・パターン** glob pattern ワイルドカードでファイル名のセットを検索・照合するために指定する文字パターンのこと《[wikipedia](https://ja.wikipedia.org/wiki/グロブ)》
</TranslationNote>
最初の例は、`openPath()` 関数の特定のパスにアクセス権限を追加する方法を示します:
```json title="src-tauri/capabilities/default.json" ins={6-15}
{
"$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 そのものと、カスタム指定されているすべての URLOS に認識されている必要があります)にアクセス権限を追加する方法を示します:
```json title="src-tauri/capabilities/default.json" ins={6-15}
{
"$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:*"
}
]
}
]
}
```
<PluginPermissions plugin={frontmatter.plugin} />
<div style="text-align: right;">
【※ この日本語版は、「Aug 9, 2025 英語版」に基づいています】
</div>

View File

@@ -0,0 +1,144 @@
---
title: OS InformationOS 情報)
description: オペレーティング・システムに関する情報を読み取ります。
plugin: os
i18nReady: true
---
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import PluginPermissions from '@components/PluginPermissions.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} />
「OS InformationOS 情報)」プラグインを使用して、オペレーティング・システムに関する情報を読み取ります。
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「OS Information」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定">
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
<CommandTabs npm="npm run tauri add os"
yarn="yarn run tauri add os"
pnpm="pnpm tauri add os"
deno="deno task tauri add os"
bun="bun tauri add os"
cargo="cargo tauri add os" />
</TabItem>
<TabItem label="手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-os
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={4}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
3. JavaScript で使用する場合は、npm パッケージもインストールしてください:
<CommandTabs
npm="npm install @tauri-apps/plugin-os"
yarn="yarn add @tauri-apps/plugin-os"
pnpm="pnpm add @tauri-apps/plugin-os"
deno="deno add npm:@tauri-apps/plugin-os"
bun="bun add @tauri-apps/plugin-os"
/>
</Steps>
</TabItem>
</Tabs>
## 使用法
このプラグインを使用すると、現在のオペレーティング・システム<sup>\*</sup>から複数の情報を照会できます。利用可能なすべての関数については、[JavaScript API](/reference/javascript/os/) または [Rust API](https://docs.rs/tauri-plugin-os/) の各リファレンスをご覧ください。
{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */}
<TranslationNote lang="ja">
<sup>\*</sup> **オペレーション・システム**: 原文は operational system
で、直訳では「運用システム」の意味になりますが、ここでは「オペレーション・システム」の意味に解釈しています。
</TranslationNote>
#### 例: OS プラットフォーム
`platform` は、使用中のオペレーティング・システムを表す文字列を返します。この値がコンパイル時に設定されます。取り得る値は `linux`、`macos`、`ios`、`freebsd`、`dragonfly`、`netbsd`、`openbsd`、`solaris`、`android`、`windows` です。
<Tabs syncKey="lang">
<TabItem label="JavaScript">
```javascript
import { platform } from '@tauri-apps/plugin-os';
// `"withGlobalTauri": true` を使用する場合は、
// const { platform } = window.__TAURI__.os; を使用できます
const currentPlatform = platform();
console.log(currentPlatform);
// コンソールに「windows」と表示します
```
</TabItem>
<TabItem label="Rust">
```rust
let platform = tauri_plugin_os::platform();
println!("Platform: {}", platform);
// ターミナルに「windows」と表示します
```
</TabItem>
</Tabs>
## アクセス権限 Permissions
デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、`capabilities` 設定でアクセス権限を変更する必要があります。
詳細については「[セキュリティ・レベル Capabilities](/ja/security/capabilities/)」の章を参照してください。また、プラグインのアクセス権限を設定するには「[プライグン・アクセス権の使用](/ja/learn/security/using-plugin-permissions/)」の章のステップ・バイ・ステップ・ガイドを参照してください。
```json title="src-tauri/capabilities/default.json" ins={4}
{
"permissions": [
...,
"os:default"
]
}
```
<PluginPermissions plugin={frontmatter.plugin} />
<div style="text-align: right;">
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
</div>

View File

@@ -0,0 +1,88 @@
---
title: Persisted Scope永続スコープ
description: ファイル・システム上の実行時のスコープ変更を持続させます。
plugin: persisted-scope
i18nReady: true
---
import PluginLinks from '@components/PluginLinks.astro';
import Compatibility from '@components/plugins/Compatibility.astro';
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components';
import CommandTabs from '@components/CommandTabs.astro';
import TranslationNote from '@components/i18n/TranslationNote.astro';
<TranslationNote lang="ja">
**Plugin 説明内容の英語表記部分について** Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
</TranslationNote>
<PluginLinks plugin={frontmatter.plugin} showJsLinks={false} />
ファイル・システムとアセットのスコープ(有効範囲)を保存し、アプリが再開されたときにその状態を復元します。
<TranslationNote lang="ja">
**デジタル・アセット** digital asset 「デジタル資産」。デジタル形式でのみ存在し、明確な使用権または使用許可が付与されているもの。《[wikipedia](https://ja.wikipedia.org/wiki/デジタル・アセット)》
</TranslationNote>
## 対応プラットフォーム
<Compatibility plugin={frontmatter.plugin} />
## セットアップ
はじめに、「persistd-scope」プラグインをインストールしてください。
<Tabs>
<TabItem label="自動で設定" >
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
{ ' ' }
<CommandTabs
npm="npm run tauri add persisted-scope"
yarn="yarn run tauri add persisted-scope"
pnpm="pnpm tauri add persisted-scope"
deno="deno task tauri add persisted-scope"
bun="bun tauri add persisted-scope"
cargo="cargo tauri add persisted-scope"
/>
</TabItem>
<TabItem label = "手動で設定">
<Steps>
1. `src-tauri` フォルダで次のコマンドを実行して、このプラグインを `Cargo.toml` 内のプロジェクトの依存関係に追加します:
```sh frame=none
cargo add tauri-plugin-persisted-scope
```
2. 追加したプラグインを初期化するために `lib.rs` を修正します:
```rust title="src-tauri/src/lib.rs" ins={4}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_persisted_scope::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
</Steps>
</TabItem>
</Tabs>
## 使用法
セットアップ後、このプラグインは自動的にファイル・システムとアセット・スコープを保存および復元します。
<div style="text-align: right;">
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
</div>