Clipboard(クリップボード)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
「clipboard(クリップボード)」プラグインを使用してシステム・クリップボードの読み取りと書き込みを行ないます。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | Only plain-text content support |
| ios | | Only plain-text content support |
はじめに、「clipboard(クリップボード)」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add clipboard-manageryarn run tauri add clipboard-managerpnpm tauri add clipboard-managerdeno task tauri add clipboard-managerbun tauri add clipboard-managercargo tauri add clipboard-manager-
src-tauriフォルダで次のコマンドを実行して、Cargo.toml内のプロジェクトの依存関係にこのプラグインを追加します:cargo add tauri-plugin-clipboard-manager -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_clipboard_manager::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
JavaScript でクリップボードを管理する場合には、npm パッケージもインストールします:
npm install @tauri-apps/plugin-clipboard-manageryarn add @tauri-apps/plugin-clipboard-managerpnpm add @tauri-apps/plugin-clipboard-managerdeno add npm:@tauri-apps/plugin-clipboard-managerbun add @tauri-apps/plugin-clipboard-manager
「clipboard」プラグインは、JavaScript と Rust の両方で利用できます。
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';// `"withGlobalTauri": true` を使用する場合は、// const { writeText, readText } = window.__TAURI__.clipboardManager; を使用できます;
// コンテンツをクリップボードに書き込みますawait writeText('Tauri is awesome!');
// クリップボードからコンテンツを読み取りますconst content = await readText();console.log(content);// コンソールにコンテンツの内容「Tauri is awesome!」を表示しますuse tauri_plugin_clipboard_manager::ClipboardExt;
app.clipboard().write_text("Tauri is awesome!".to_string()).unwrap();
// クリップボードからコンテンツを読み取りますlet content = app.clipboard().read_text();println!("{:?}", content.unwrap());// ターミナルにコンテンツの内容「Tauri is awesome!」を表示しますDefault Permission
No features are enabled by default, as we believe the clipboard can be inherently dangerous and it is application specific if read and/or write access is needed.
Clipboard interaction needs to be explicitly enabled.
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the clear command without any pre-configured scope. |
|
|
Denies the clear command without any pre-configured scope. |
|
|
Enables the read_image command without any pre-configured scope. |
|
|
Denies the read_image command without any pre-configured scope. |
|
|
Enables the read_text command without any pre-configured scope. |
|
|
Denies the read_text command without any pre-configured scope. |
|
|
Enables the write_html command without any pre-configured scope. |
|
|
Denies the write_html command without any pre-configured scope. |
|
|
Enables the write_image command without any pre-configured scope. |
|
|
Denies the write_image command without any pre-configured scope. |
|
|
Enables the write_text command without any pre-configured scope. |
|
|
Denies the write_text command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT