feat(core): add clipboard writeText and readText APIs (#2035)

This commit is contained in:
Lucas Fernandes Nogueira
2021-06-21 13:32:22 -03:00
committed by GitHub
parent 3280c4aa91
commit 285bf64bf9
13 changed files with 265 additions and 35 deletions

View File

@@ -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];

View 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>