KMEmbeddedPaymentPopWC.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // KMEmbeddedPaymentPopWC.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/9/4.
  6. //
  7. import Cocoa
  8. import WebKit
  9. class KMEmbeddedPaymentPopWC: NSWindowController {
  10. @IBOutlet weak var webView: WKWebView!
  11. var urlPath: String?
  12. var callback: ((_ isClose: Bool) -> Void)?
  13. static var currentWindowController: KMEmbeddedPaymentPopWC!
  14. @objc static func currentFirstTrialWC(_ urlPath: String) -> KMEmbeddedPaymentPopWC {
  15. if currentWindowController != nil {
  16. currentWindowController.urlPath = urlPath
  17. return currentWindowController
  18. } else {
  19. let configWC: KMEmbeddedPaymentPopWC = KMEmbeddedPaymentPopWC.init(windowNibName: "KMEmbeddedPaymentPopWC")
  20. currentWindowController = configWC;
  21. currentWindowController.urlPath = urlPath
  22. return currentWindowController
  23. }
  24. }
  25. override func windowDidLoad() {
  26. super.windowDidLoad()
  27. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  28. if urlPath != nil {
  29. if let url = URL(string: urlPath!) {
  30. let request = URLRequest(url: url)
  31. webView.load(request)
  32. }
  33. }
  34. self.window?.delegate = self;
  35. }
  36. }
  37. extension KMEmbeddedPaymentPopWC: NSWindowDelegate {
  38. func windowWillClose(_ notification: Notification) {
  39. if let callback = self.callback {
  40. callback(true)
  41. }
  42. KMEmbeddedPaymentPopWC.currentWindowController = nil
  43. }
  44. }