Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde = "1.0"
thiserror = "1.0"
base64 = "0.22.1"
image = "0.25.1"
clipboard-rs = "0.2.0"
clipboard-rs = "0.2.1"

[build-dependencies]
tauri-plugin = { version = "2.0.0-beta.15", features = ["build"] }
tauri-plugin = { version = "2.0.0-beta", features = ["build"] }
2 changes: 1 addition & 1 deletion examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"type": "module",
"dependencies": {
"@floating-ui/dom": "1.5.3",
"@tauri-apps/api": "2.0.0-beta.11",
"@tauri-apps/api": "^2.0.0-beta",
"tauri-plugin-clipboard-api": "link:../../"
}
}
12 changes: 3 additions & 9 deletions examples/demo/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
"main"
],
"permissions": [
"path:default",
"event:default",
"window:default",
"webview:default",
"app:default",
"resources:default",
"image:default",
"menu:default",
"tray:default",
"core:event:default",
"core:path:default",
"core:window:default",
"clipboard:read-all",
"clipboard:write-all",
"clipboard:monitor-all"
Expand Down
16 changes: 9 additions & 7 deletions examples/demo/src/lib/components/listener.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
let unlistenImageUpdate: UnlistenFn;
let unlistenHtmlUpdate: UnlistenFn;
let unlistenRTF: UnlistenFn;
let unlistenAvail: UnlistenFn;
let unlistenClipboard: () => Promise<void>;
let unlistenFiles: UnlistenFn;
const has = {
Expand Down Expand Up @@ -65,14 +66,14 @@
});
unlistenClipboard = await startListening();

onClipboardUpdate(async () => {
unlistenAvail = await onClipboardUpdate(async (values) => {
clear();
has.hasHTML = await hasHTML();
has.hasImage = await hasImage();
has.hasText = await hasText();
has.hasRTF = await hasRTF();
has.hasFiles = await hasFiles();
console.log('plugin:clipboard://clipboard-monitor/update event received');
console.log('plugin:clipboard://clipboard-monitor/update event received', values);
has.hasHTML = values.html;
has.hasImage = values.image;
has.hasText = values.text;
has.hasRTF = values.rtf
has.hasFiles = values.files;
});
});

Expand All @@ -86,6 +87,7 @@
if (unlistenHtmlUpdate) unlistenHtmlUpdate();
if (unlistenFiles) unlistenFiles();
if (unlistenClipboard) unlistenClipboard();
if (unlistenAvail) unlistenAvail();
});
</script>

Expand Down
16 changes: 12 additions & 4 deletions guest-js/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export const ClipboardChangedFilesPayloadSchema = v.object({
})
export type ClipboardChangedPayload = v.InferOutput<typeof ClipboardChangedPayloadSchema>

export interface ClipboardState {
text: boolean,
html: boolean,
rtf: boolean,
image: boolean,
files: boolean,
}

export function hasText() {
return invoke<boolean>(HAS_TEXT_COMMAND)
}
Expand Down Expand Up @@ -333,13 +341,13 @@ export function listenToClipboard(

/**
* This listen to clipboard monitor update event, and trigger the callback function.
* However from this event we don't know whether it's text or image, no real data is returned.
* Use with listenToClipboard function.
* @param cb callback
* @returns unlisten function
*/
export function onClipboardUpdate(cb: () => void) {
return listen(MONITOR_UPDATE_EVENT, cb)
export async function onClipboardUpdate(cb: (state: ClipboardState) => void) {
return await listen<ClipboardState>(MONITOR_UPDATE_EVENT, (event) => {
cb(event.payload)
})
}

export async function onTextUpdate(cb: (text: string) => void): Promise<UnlistenFn> {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"peerDependencies": {},
"dependencies": {
"valibot": "^0.40.0",
"@tauri-apps/api": "2.0.0-beta.11"
"@tauri-apps/api": "^2.0.0-beta"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

### Permission Table
## Permission Table

<table>
<tr>
Expand Down
Loading