parent
3c6db3265e
commit
acbadc110c
@ -0,0 +1,10 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
||||||
|
xcuserdata/
|
||||||
|
DerivedData/
|
||||||
|
.swiftpm/config/registries.json
|
||||||
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||||
|
.netrc
|
||||||
|
Package.resolved
|
@ -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")
|
||||||
|
]
|
||||||
|
)
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue