mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-30 17:48:50 +02:00
feat(clipboard-manager): implement clear on iOS and Android (#1462)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"clipboard-manager": "minor"
|
||||||
|
---
|
||||||
|
|
||||||
|
Add support for clearing clipboard text on iOS and Android.
|
||||||
@@ -92,7 +92,11 @@ class ClipboardPlugin(private val activity: Activity) : Plugin(activity) {
|
|||||||
val clipData = when (args) {
|
val clipData = when (args) {
|
||||||
is WriteOptions.PlainText -> {
|
is WriteOptions.PlainText -> {
|
||||||
ClipData.newPlainText(args.label, args.text)
|
ClipData.newPlainText(args.label, args.text)
|
||||||
|
} else -> {
|
||||||
|
invoke.reject("Invalid write options provided")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.setPrimaryClip(clipData)
|
manager.setPrimaryClip(clipData)
|
||||||
@@ -120,4 +124,12 @@ class ClipboardPlugin(private val activity: Activity) : Plugin(activity) {
|
|||||||
|
|
||||||
invoke.resolveObject(data)
|
invoke.resolveObject(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
fun clear(invoke: Invoke) {
|
||||||
|
if (manager.hasPrimaryClip()) {
|
||||||
|
manager.clearPrimaryClip()
|
||||||
|
}
|
||||||
|
invoke.resolve()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ class ClipboardPlugin: Plugin {
|
|||||||
invoke.reject("Clipboard is empty")
|
invoke.reject("Clipboard is empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc public func clear(_ invoke: Invoke) throws {
|
||||||
|
let clipboard = UIPasteboard.general
|
||||||
|
clipboard.items = []
|
||||||
|
invoke.resolve()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@_cdecl("init_plugin_clipboard")
|
@_cdecl("init_plugin_clipboard")
|
||||||
|
|||||||
@@ -92,9 +92,7 @@ impl<R: Runtime> Clipboard<R> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(&self) -> crate::Result<()> {
|
pub fn clear(&self) -> crate::Result<()> {
|
||||||
Err(crate::Error::Clipboard(
|
self.0.run_mobile_plugin("clear", ()).map_err(Into::into)
|
||||||
"Unsupported on this platform".to_string(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user