mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): add clipboard writeText and readText APIs (#2035)
This commit is contained in:
committed by
GitHub
parent
3280c4aa91
commit
285bf64bf9
@@ -16,6 +16,7 @@
|
||||
import Shortcuts from "./components/Shortcuts.svelte";
|
||||
import Shell from "./components/Shell.svelte";
|
||||
import Updater from "./components/Updater.svelte";
|
||||
import Clipboard from "./components/Clipboard.svelte";
|
||||
|
||||
const MENU_TOGGLE_HOTKEY = 'ctrl+b';
|
||||
|
||||
@@ -69,7 +70,11 @@
|
||||
{
|
||||
label: "Updater",
|
||||
component: Updater,
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Clipboard",
|
||||
component: Clipboard,
|
||||
}
|
||||
];
|
||||
|
||||
let selected = views[0];
|
||||
|
||||
36
examples/api/src/components/Clipboard.svelte
Normal file
36
examples/api/src/components/Clipboard.svelte
Normal file
@@ -0,0 +1,36 @@
|
||||
<script>
|
||||
import {
|
||||
writeText,
|
||||
readText
|
||||
} from "@tauri-apps/api/clipboard";
|
||||
|
||||
export let onMessage;
|
||||
let text = "clipboard message";
|
||||
|
||||
function write() {
|
||||
writeText(text)
|
||||
.then(() => {
|
||||
onMessage('Wrote to the clipboard');
|
||||
})
|
||||
.catch(onMessage);
|
||||
}
|
||||
|
||||
function read() {
|
||||
readText()
|
||||
.then((contents) => {
|
||||
onMessage(`Clipboard contents: ${contents}`);
|
||||
})
|
||||
.catch(onMessage);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<div>
|
||||
<input
|
||||
placeholder="Text to write to the clipboard"
|
||||
bind:value={text}
|
||||
/>
|
||||
<button type="button" on:click={write}>Write</button>
|
||||
</div>
|
||||
<button type="button" on:click={read}>Read</button>
|
||||
</div>
|
||||
Reference in New Issue
Block a user