clipboard
Read and write clipboard text. Support is probed, a refusal is denied.
What it does
clipboard reads and writes text, and text only. There is no image or file support.
How it works
The web provider probes navigator.clipboard. Without it, for example in an insecure context, every
method answers unsupported. A NotAllowedError from the browser becomes denied. The Tauri
provider uses @tauri-apps/plugin-clipboard-manager.
Config
None.
API
Mounted at app.clipboard.
| Method | Signature | Description |
|---|---|---|
readText | () => Promise<SystemResult<string>> | The clipboard text. |
writeText | (text: string) => Promise<SystemResult<void>> | Writes the text. |
Events
None.
Depends on
- The core
runtimeplugin. - In the shell:
@tauri-apps/plugin-clipboard-manager, and{ name: "clipboard-manager" }inconfig.systemof native.
Example
import { createApp } from "@moku-labs/system";
import { clipboardPlugin } from "@moku-labs/system/clipboard";
const system = createApp({ plugins: [clipboardPlugin] });
await system.start();
const copied = await system.clipboard.writeText("https://moku-labs.com");
if (!copied.ok && copied.reason === "unsupported") {
console.log("hide the copy button");
}- Native grants two permissions on purpose.
clipboard-manager:defaultgrants nothing, so the list isallow-read-textandallow-write-text.
Related
- How it works: the result contract.