feat(clipboard): add plugin (#323)

This commit is contained in:
Lucas Fernandes Nogueira
2023-04-18 10:19:45 -03:00
committed by GitHub
parent 4539c03f95
commit 8cd7d3501b
37 changed files with 4679 additions and 22 deletions
+10
View File
@@ -0,0 +1,10 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Package.resolved
+31
View File
@@ -0,0 +1,31 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "tauri-plugin-clipboard",
platforms: [
.iOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "tauri-plugin-clipboard",
type: .static,
targets: ["tauri-plugin-clipboard"]),
],
dependencies: [
.package(name: "Tauri", path: "../.tauri/tauri-api")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "tauri-plugin-clipboard",
dependencies: [
.byName(name: "Tauri")
],
path: "Sources")
]
)
+3
View File
@@ -0,0 +1,3 @@
# Tauri Plugin {{ plugin_name_original }}
A description of this package.
@@ -0,0 +1,42 @@
import UIKit
import WebKit
import Tauri
import SwiftRs
class ClipboardPlugin: Plugin {
@objc public func write(_ invoke: Invoke) throws {
let options = invoke.getObject("options")
if let options = options {
let clipboard = UIPasteboard.general
let kind = invoke.getString("kind", "")
switch kind {
case "PlainText":
let text = options["text"] as? String
clipboard.string = text
default:
invoke.reject("Unknown kind \(kind)")
return
}
invoke.resolve()
} else {
invoke.reject("Missing `options` input")
}
}
@objc public func read(_ invoke: Invoke) throws {
let clipboard = UIPasteboard.general
if let text = clipboard.string {
invoke.resolve([
"kind": "PlainText",
"options": text
])
} else {
invoke.reject("Clipboard is empty")
}
}
}
@_cdecl("init_plugin_clipboard")
func initPlugin(name: SRString, webview: WKWebView?) {
Tauri.registerPlugin(webview: webview, name: name.toString(), plugin: ClipboardPlugin())
}
@@ -0,0 +1,8 @@
import XCTest
@testable import ClipboardPlugin
final class ClipboardPluginTests: XCTestCase {
func testClipboard() throws {
let plugin = ClipboardPlugin()
}
}