Skip to content

Commit bc35524

Browse files
Create clipboard guide #1475 (#1604)
* clipboard #1475 * clarify use of readText() Co-authored-by: Lorenzo Lewis <[email protected]> * rename 'plugin add' to 'add' --------- Co-authored-by: Lorenzo Lewis <[email protected]>
1 parent 16d3d88 commit bc35524

File tree

1 file changed

+94
-4
lines changed

1 file changed

+94
-4
lines changed

src/content/docs/features/clipboard.mdx

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,100 @@ description: Read and write to the system clipboard.
55

66
import Stub from '@components/Stub.astro';
77
import PluginLinks from '@components/PluginLinks.astro';
8+
import { Tabs, TabItem } from '@astrojs/starlight/components';
9+
import CommandTabs from '@components/CommandTabs.astro';
810

911
<PluginLinks plugin="clipboard-manager" />
1012

11-
<Stub>
12-
Based on
13-
https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/clipboard-manager
14-
</Stub>
13+
Read and write to the system clipboard using the clipboard plugin.
14+
15+
## Setup
16+
17+
Install the clipboard plugin to get started.
18+
19+
<Tabs>
20+
<TabItem label="Automatic">
21+
22+
1. Use your project's package manager to add the dependency:
23+
24+
<CommandTabs npm="npm run tauri add clipboard-manager"
25+
yarn="yarn run tauri add clipboard-manager"
26+
pnpm="pnpm tauri add clipboard-manager"
27+
cargo="cargo tauri add clipboard-manager" />
28+
29+
2. Modify `lib.rs` to initialize the plugin:
30+
31+
{/* TODO: Revise once https://github.com/tauri-apps/tauri/issues/7696 is in */}
32+
33+
```rust
34+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
35+
pub fn run() {
36+
tauri::Builder::default()
37+
// Initialize the plugin
38+
.plugin(tauri_plugin_clipboard_manager::init())
39+
.run(tauri::generate_context!())
40+
.expect("error while running tauri application");
41+
}
42+
```
43+
44+
</TabItem>
45+
<TabItem label="Manual">
46+
47+
1. Run `cargo add tauri-plugin-clipboard-manager` to add the plugin to the project's dependencies in `Cargo.toml`.
48+
49+
2. Modify `lib.rs` to initialize the plugin:
50+
51+
```rust
52+
// lib.rs
53+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
54+
pub fn run() {
55+
tauri::Builder::default()
56+
// Initialize the plugin
57+
.plugin(tauri_plugin_clipboard_manager::init())
58+
.run(tauri::generate_context!())
59+
.expect("error while running tauri application");
60+
}
61+
```
62+
63+
3. If you'd like to manage the clipboard in JavaScript then install the npm package as well:
64+
65+
<CommandTabs
66+
npm="npm install @tauri-apps/plugin-clipboard-manager"
67+
yarn="yarn add @tauri-apps/plugin-clipboard-manager"
68+
pnpm="pnpm add @tauri-apps/plugin-clipboard-manager"
69+
/>
70+
71+
</TabItem>
72+
73+
</Tabs>
74+
75+
## Usage
76+
77+
{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */}
78+
79+
The clipboard plugin is available in both JavaScript and Rust.
80+
81+
<Tabs>
82+
<TabItem label="JavaScript">
83+
84+
```js
85+
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';
86+
87+
// Write text to the clipboard
88+
await writeText('Tauri is awesome!');
89+
90+
// Read text from the clipboard
91+
const content = await readText()
92+
console.log(content)
93+
// Prints "Tauri is awesome!" to the console
94+
```
95+
96+
</TabItem>
97+
<TabItem label="Rust">
98+
99+
{/* TODO: */}
100+
101+
<Stub />
102+
103+
</TabItem>
104+
</Tabs>

0 commit comments

Comments
 (0)