|
|
@ -1,59 +1,59 @@
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import * as clipboard from "@tauri-apps/plugin-clipboard-manager";
|
|
|
|
import * as clipboard from '@tauri-apps/plugin-clipboard-manager'
|
|
|
|
import { open } from "@tauri-apps/plugin-dialog";
|
|
|
|
import { open } from '@tauri-apps/plugin-dialog'
|
|
|
|
import { arrayBufferToBase64 } from "../lib/utils";
|
|
|
|
import { arrayBufferToBase64 } from '../lib/utils'
|
|
|
|
import { readFile } from "@tauri-apps/plugin-fs";
|
|
|
|
import { readFile } from '@tauri-apps/plugin-fs'
|
|
|
|
|
|
|
|
|
|
|
|
export let onMessage;
|
|
|
|
export let onMessage
|
|
|
|
export let insecureRenderHtml;
|
|
|
|
export let insecureRenderHtml
|
|
|
|
let text = "clipboard message";
|
|
|
|
let text = 'clipboard message'
|
|
|
|
|
|
|
|
|
|
|
|
function writeText() {
|
|
|
|
function writeText() {
|
|
|
|
clipboard
|
|
|
|
clipboard
|
|
|
|
.writeText(text)
|
|
|
|
.writeText(text)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
onMessage("Wrote to the clipboard");
|
|
|
|
onMessage('Wrote to the clipboard')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(onMessage);
|
|
|
|
.catch(onMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function writeImage() {
|
|
|
|
async function writeImage() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const res = await open({
|
|
|
|
const path = await open({
|
|
|
|
title: "Image to write to clipboard",
|
|
|
|
title: 'Image to write to clipboard',
|
|
|
|
filters: [
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
{
|
|
|
|
name: "Clipboard IMG",
|
|
|
|
name: 'Clipboard IMG',
|
|
|
|
extensions: ["png", "jpg", "jpeg"],
|
|
|
|
extensions: ['png', 'jpg', 'jpeg']
|
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
]
|
|
|
|
});
|
|
|
|
})
|
|
|
|
const bytes = await readFile(res.path);
|
|
|
|
const bytes = await readFile(path)
|
|
|
|
await clipboard.writeImage(bytes);
|
|
|
|
await clipboard.writeImage(bytes)
|
|
|
|
onMessage("wrote image");
|
|
|
|
onMessage('wrote image')
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
onMessage(e);
|
|
|
|
onMessage(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function read() {
|
|
|
|
async function read() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const image = await clipboard.readImage();
|
|
|
|
const image = await clipboard.readImage()
|
|
|
|
arrayBufferToBase64(await image.rgba(), function (base64) {
|
|
|
|
arrayBufferToBase64(await image.rgba(), function (base64) {
|
|
|
|
const src = "data:image/png;base64," + base64;
|
|
|
|
const src = 'data:image/png;base64,' + base64
|
|
|
|
insecureRenderHtml('<img src="' + src + '"></img>');
|
|
|
|
insecureRenderHtml('<img src="' + src + '"></img>')
|
|
|
|
});
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
return
|
|
|
|
} catch (_) {}
|
|
|
|
} catch (_) {}
|
|
|
|
|
|
|
|
|
|
|
|
clipboard
|
|
|
|
clipboard
|
|
|
|
.readText()
|
|
|
|
.readText()
|
|
|
|
.then((contents) => {
|
|
|
|
.then((contents) => {
|
|
|
|
onMessage(`Clipboard contents: ${contents}`);
|
|
|
|
onMessage(`Clipboard contents: ${contents}`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
.catch((e) => {
|
|
|
|
onMessage(e);
|
|
|
|
onMessage(e)
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
@ -65,6 +65,5 @@
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<button class="btn" type="button" on:click={writeText}>Write</button>
|
|
|
|
<button class="btn" type="button" on:click={writeText}>Write</button>
|
|
|
|
<button class="btn" type="button" on:click={writeImage}>Pick Image</button>
|
|
|
|
<button class="btn" type="button" on:click={writeImage}>Pick Image</button>
|
|
|
|
|
|
|
|
|
|
|
|
<button class="btn" type="button" on:click={read}>Read</button>
|
|
|
|
<button class="btn" type="button" on:click={read}>Read</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|