mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-01-31 00:45:24 +01:00
feat(clipboard-manager): implement clear on iOS and Android (#1462)
This commit is contained in:
5
.changes/clear-clipboard.md
Normal file
5
.changes/clear-clipboard.md
Normal file
@@ -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) {
|
||||
is WriteOptions.PlainText -> {
|
||||
ClipData.newPlainText(args.label, args.text)
|
||||
} else -> {
|
||||
invoke.reject("Invalid write options provided")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
manager.setPrimaryClip(clipData)
|
||||
@@ -120,4 +124,12 @@ class ClipboardPlugin(private val activity: Activity) : Plugin(activity) {
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@objc public func clear(_ invoke: Invoke) throws {
|
||||
let clipboard = UIPasteboard.general
|
||||
clipboard.items = []
|
||||
invoke.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_clipboard")
|
||||
|
||||
@@ -92,9 +92,7 @@ impl<R: Runtime> Clipboard<R> {
|
||||
}
|
||||
|
||||
pub fn clear(&self) -> crate::Result<()> {
|
||||
Err(crate::Error::Clipboard(
|
||||
"Unsupported on this platform".to_string(),
|
||||
))
|
||||
self.0.run_mobile_plugin("clear", ()).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user