You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-5Lines changed: 42 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@
19
19
## Installation
20
20
21
21
> If you are installing from npm and crate.io package registry, make sure the versions for both packages are the same, otherwise, the API may not match.
22
-
>
22
+
>
23
23
> I will make sure the latest version is published to both npm and crates.io.
24
24
25
25
### Short Instructions
@@ -38,7 +38,7 @@ You need to make sure the package versions is compatible with the correct versio
38
38
- Tauri 1.x: package and crate version should start with 1.x
39
39
- Tauri 2.x: package and crate version should start with 2.x
@@ -48,7 +48,6 @@ You need to make sure the package versions is compatible with the correct versio
48
48
- Check crate versions at https://crates.io/crates/tauri-plugin-clipboard/versions
49
49
- Check npm package verison at https://www.npmjs.com/package/tauri-plugin-clipboard-api?activeTab=versions
50
50
51
-
52
51
<details>
53
52
<summary>More Installation Options</summary>
54
53
@@ -271,7 +270,7 @@ Difference between URI and no-URI is that URI starts with `files://` on Linux an
271
270
272
271
## Notes
273
272
274
-
> You don't really need to read this section if you are just using the plugin.
273
+
### Monitor
275
274
276
275
The logic of tauri's listen API is encapsulated in `onTextUpdate`, `onFilesUpdate`, `startListening`.
277
276
@@ -308,7 +307,45 @@ The returned unlisten function from `startListening` also does two things:
308
307
309
308
For more details read the source code from [./webview-src/api.ts](./webview-src/api.ts).
310
309
311
-
## Note
310
+
#### Break On Type
311
+
312
+
`listenToClipboard` and `startListening` function takes an optional parameter `breakOnType` with type
313
+
314
+
```ts
315
+
typeBreakOnTypeInput= {
316
+
text?:boolean;
317
+
html?:boolean;
318
+
rtf?:boolean;
319
+
image?:boolean;
320
+
files?:boolean;
321
+
};
322
+
```
323
+
324
+
This parameter is used to break the monitor event emission when the clipboard content type matches the type. For example, when HTML content is copied, text update event will also be emitted.
325
+
326
+
The order of type checking is `file -> image -> html -> rtf -> text`.
327
+
328
+
The default `breakOnType` is
329
+
330
+
```ts
331
+
{
332
+
text: false,
333
+
html: false,
334
+
rtf: false,
335
+
image: false,
336
+
files: true
337
+
}
338
+
```
339
+
340
+
When files are copied, text is also updated. By default, text update event will not be emitted when files are copied.
341
+
342
+
If you don't want to listen to text update when HTML content is copied, you can set `breakOnType` to `{ html: true }`.
The base64 image string can be converted to `Uint8Array` and written to file system using tauri's fs API. (We also provide a `readImageBinary` function to read image as binary data (`Uint8Array` is one of the available return type).
* Listen to "plugin:clipboard://clipboard-monitor/update" from Tauri core.
251
-
* But this event doesn't tell us whether text or image is updated,
252
-
* so this function will detect which is changed and emit the corresponding event
253
-
* Event constant variables: TEXT_CHANGED or IMAGE_CHANGED
251
+
* The corresponding clipboard type event will be emitted when there is clipboard update.
252
+
* Multiple types of clipboard data can be copied at the same time. e.g. When HTML is copied, text is also updated. files copy also update text.
253
+
* There is an optional `breakOn` argument to control whether to break event emitting for other types.
254
+
* Type checking order: files -> image -> html -> rtf -> text
255
+
* If you don't want text update triggered when html is copied, pass breakOn argument `{html: true}`
256
+
* By default, files is set to true. When files are copied, text event won't be triggered. If you want text event to be triggered, pass `{files: false}`
257
+
*
258
+
* Due to the order of checking, the text field doesn't matter as no other types are checked after text.
254
259
* @returns unlisten function
255
260
*/
256
261
exportfunctionlistenToClipboard(
257
262
breakOn: BreakOnTypeInput=DefaultBreakOn
258
263
): Promise<UnlistenFn>{
259
264
constparseBreakOn=BreakOnType.parse(breakOn);
260
-
console.log(parseBreakOn);
261
-
262
265
returnlisten(MONITOR_UPDATE_EVENT,async(e)=>{
263
266
if(e.payload==="clipboard update"){
264
267
if(awaithasFiles()){
@@ -394,6 +397,20 @@ export async function listenToMonitorStatusUpdate(
394
397
});
395
398
}
396
399
400
+
/**
401
+
* Start monitor service thread with `startMonitor()` and then run `listenToClipboard()`
402
+
* The corresponding clipboard type event will be emitted when there is clipboard update.
403
+
* Use `onImageUpdate()`, `onTextUpdate()`, `onHTMLUpdate()`, `onFilesUpdate()`, `onRTFUpdate()` to listen to the event after calling this function.
404
+
*
405
+
* Multiple types of clipboard data can be copied at the same time. e.g. When HTML is copied, text is also updated. files copy also update text.
406
+
* There is an optional `breakOn` argument to control whether to break event emitting for other types.
407
+
* Type checking order: files -> image -> html -> rtf -> text
408
+
* If you don't want text update triggered when html is copied, pass breakOn argument `{html: true}`
409
+
* By default, files is set to true. When files are copied, text event won't be triggered. If you want text event to be triggered, pass `{files: false}`
410
+
*
411
+
* Due to the order of checking, the text field doesn't matter as no other types are checked after text.
0 commit comments