ExamplePlugin.swift 594 B

1234567891011121314151617181920212223242526
  1. // Copyright 2019-2024 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import SwiftRs
  5. import Tauri
  6. import UIKit
  7. import WebKit
  8. class PingArgs: Decodable {
  9. let value: String?
  10. let onEvent: Channel?
  11. }
  12. class ExamplePlugin: Plugin {
  13. @objc public func ping(_ invoke: Invoke) throws {
  14. let args = try invoke.parseArgs(PingArgs.self)
  15. try args.onEvent?.send(["kind": "ping"])
  16. invoke.resolve(["value": args.value ?? ""])
  17. }
  18. }
  19. @_cdecl("init_plugin_sample")
  20. func initPlugin() -> Plugin {
  21. return ExamplePlugin()
  22. }