mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-05-31 13:39:36 +02:00
9dec9605ed
* feat(clipboard): support `read_image` & `write_image` * fix plugin name * platform specific bahavior * remove unnecessary BufWriter * improvement * update example * update example * format * header, fix change file * use image from tauri * fix ci * update tauri, fix read * image crate only on desktop [skip ci] * Update plugins/authenticator/src/u2f_crate/protocol.rs [skip ci] Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> * Update plugins/authenticator/src/u2f_crate/protocol.rs [skip ci] Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> * update deps, address code review * fix mobile [skip ci] --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Nogueira <lucas@tauri.app> Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
47 lines
1.0 KiB
Swift
47 lines
1.0 KiB
Swift
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftRs
|
|
import Tauri
|
|
import UIKit
|
|
import WebKit
|
|
|
|
enum WriteOptions: Codable {
|
|
case plainText(text: String)
|
|
}
|
|
|
|
enum ReadClipData: Codable {
|
|
case plainText(text: String)
|
|
}
|
|
|
|
class ClipboardPlugin: Plugin {
|
|
@objc public func writeText(_ invoke: Invoke) throws {
|
|
let options = try invoke.parseArgs(WriteOptions.self)
|
|
let clipboard = UIPasteboard.general
|
|
switch options {
|
|
case .plainText(let text):
|
|
clipboard.string = text
|
|
default:
|
|
invoke.unimplemented()
|
|
return
|
|
}
|
|
invoke.resolve()
|
|
|
|
}
|
|
|
|
@objc public func readText(_ invoke: Invoke) throws {
|
|
let clipboard = UIPasteboard.general
|
|
if let text = clipboard.string {
|
|
invoke.resolve(ReadClipData.plainText(text: text))
|
|
} else {
|
|
invoke.reject("Clipboard is empty")
|
|
}
|
|
}
|
|
}
|
|
|
|
@_cdecl("init_plugin_clipboard")
|
|
func initPlugin() -> Plugin {
|
|
return ClipboardPlugin()
|
|
}
|