KMToolCompareWindowController.swift 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // KMToolCompareWindowController.swift
  3. // PDF Master
  4. //
  5. // Created by liujiajie on 2023/11/9.
  6. //
  7. import Cocoa
  8. var currentWindowController: KMToolCompareWindowController? = nil
  9. class KMToolCompareWindowController: NSWindowController{
  10. var type: KMCompareWithToolType?
  11. var selectIndex: Int = 0
  12. @IBOutlet var box: NSBox!
  13. var modalSession: NSApplication.ModalSession?
  14. deinit {
  15. NotificationCenter.default.removeObserver(self)
  16. }
  17. convenience init(toolType: KMCompareWithToolType, selectNum: Int) {
  18. self.init(windowNibName: "KMToolCompareWindowController")
  19. self.type = toolType
  20. self.selectIndex = selectNum
  21. }
  22. func toolCompareWith(toolType:KMCompareWithToolType, selectNum:Int) -> KMToolCompareWindowController {
  23. if (currentWindowController != nil) {
  24. return currentWindowController!
  25. }
  26. let vc = KMToolCompareWindowController(toolType: toolType, selectNum: selectNum)
  27. currentWindowController = vc
  28. return vc
  29. }
  30. override func windowDidLoad() {
  31. super.windowDidLoad()
  32. #if VERSION_DMG
  33. // IAPProductsManager.defaultManager().loadProducts()
  34. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductLoadedNotification(notification:)), name: NSNotification.Name("KMIAPProductLoadedNotification"), object: nil)
  35. NotificationCenter.default.addObserver(self, selector: #selector(IAPSubscriptionLoadedNotification(notification:)), name: NSNotification.Name("KMIAPSubscriptionLoadedNotification"), object: nil)
  36. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
  37. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductFailedNotification(notification:)), name: NSNotification.Name("KMIAPProductFailedNotification"), object: nil)
  38. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
  39. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFailedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFailedNotification"), object: nil)
  40. #endif
  41. }
  42. func removeWaitingView(view: NSView) {
  43. for subview in view.subviews {
  44. if subview is WaitingView {
  45. subview.removeFromSuperview()
  46. break
  47. }
  48. }
  49. }
  50. func reloadData() {
  51. // if IAPProductsManager.defaultManager().isAvailableAllFunction {
  52. // self.payConvertCompareViewController.reloadData()
  53. // } else {
  54. // self.convertCompareViewController.reloadData()
  55. // }
  56. }
  57. @objc func IAPProductFailedNotification(notification: NSNotification) {
  58. self.removeWaitingView(view: (self.window?.contentView)!)
  59. }
  60. @objc func IAPProductPurchasedNotification(notification: NSNotification) {
  61. self.removeWaitingView(view: (self.window?.contentView)!)
  62. self.reloadData()
  63. }
  64. @objc func IAPProductLoadedNotification(notification: NSNotification) {
  65. self.reloadData()
  66. }
  67. @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
  68. self.removeWaitingView(view: (self.window?.contentView)!)
  69. self.reloadData()
  70. }
  71. @objc func IAPProductRestoreFailedNotification(notification: NSNotification) {
  72. self.removeWaitingView(view: (self.window?.contentView)!)
  73. }
  74. @objc func IAPSubscriptionLoadedNotification(notification: NSNotification) {
  75. self.removeWaitingView(view: (self.window?.contentView)!)
  76. self.reloadData()
  77. }
  78. }