KMFunctionGuideWindowController.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. //
  2. // KMFunctionGuideWindowController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/6.
  6. //
  7. import Cocoa
  8. class KMFunctionGuideWindowController: NSWindowController {
  9. @IBOutlet weak var contendBox: NSBox!
  10. var singleController: KMFunctionGuideSingleController!
  11. var multiController: KMFunctionGuideMultiController!
  12. @objc var _type: KMGuideInfoType = .none
  13. //MARK: Static
  14. @objc static func availableShow(_ type: KMGuideInfoType) -> Bool {
  15. if type == .functionMulitDidital {
  16. if (UserDefaults.standard.object(forKey: kKMGuideInfoMultiDigitalKey) == nil) {
  17. return true
  18. }
  19. } else if type == .functionMultiAIGuide {
  20. if (UserDefaults.standard.object(forKey: kKMGuideInfoMultiAIGuideKey) == nil) {
  21. return true
  22. }
  23. } else if type == .aiInfoResultSave {
  24. if (UserDefaults.standard.object(forKey: kKMGuideInfoAIResultSaveKey) == nil) {
  25. return true
  26. }
  27. }
  28. return false
  29. }
  30. @objc static func setDidShowFor(_ type: KMGuideInfoType) -> Void {
  31. if type == .functionMulitDidital {
  32. //V3.2.0添加数字签名引导
  33. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoMultiDigitalKey)
  34. UserDefaults.standard.synchronize()
  35. } else if type == .functionMultiAIGuide {
  36. //V3.3.0添加AI引导
  37. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoMultiAIGuideKey)
  38. UserDefaults.standard.synchronize()
  39. } else if type == .aiInfoResultSave {
  40. //V3.3.0添加AI引导
  41. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoAIResultSaveKey)
  42. UserDefaults.standard.synchronize()
  43. }
  44. }
  45. //MARK: SystemAction
  46. override func windowDidLoad() {
  47. super.windowDidLoad()
  48. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  49. }
  50. func setContendView(_ view: NSView) {
  51. var frame: CGRect = self.window!.frame
  52. frame.origin.y -= view.frame.size.height-frame.size.height
  53. frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0
  54. frame.size.width = view.frame.size.width
  55. frame.size.height = view.frame.size.height
  56. self.window?.setFrame(frame, display: true, animate: true)
  57. self.contendBox.contentView = view
  58. }
  59. override func showWindow(_ sender: Any?) {
  60. super.showWindow(sender)
  61. self.window?.center()
  62. DispatchQueue.main.async {
  63. if self.type == .functionSingle {
  64. self.setContendView(self.singleController.view)
  65. } else if self.type == .functionMulti {
  66. self.setContendView(self.multiController.view)
  67. }
  68. }
  69. }
  70. //MARK: Setter
  71. @objc var type: KMGuideInfoType {
  72. set {
  73. _type = newValue;
  74. if _type == .functionSingle {
  75. self.singleController = KMFunctionGuideSingleController.init()
  76. } else if _type == .functionMulti {
  77. self.multiController = KMFunctionGuideMultiController.init()
  78. self.multiController.clickHandle = {[weak self] controller in
  79. #if VERSION_DMG
  80. if controller.currentNameKEY == controller.AIInfoKey {
  81. // var url = URL(string: AIProduct_Link)!
  82. // NSWorkspace.shared.open(url)
  83. if AIInfoManager.default().aiInfoValid {
  84. self?.closeAction()
  85. } else {
  86. let singleTon = KMPurchaseCompareDMGWindowController.init()
  87. singleTon.showWindow(nil)
  88. singleTon.window?.center()
  89. }
  90. } else if controller.currentNameKEY == controller.MeasureInfoKey {
  91. // var url = URL(string: Store_Link)!
  92. // NSWorkspace.shared.open(url)
  93. if VerificationManager.default().status == ActivityStatusVerification {
  94. self?.closeAction()
  95. } else {
  96. let singleTon = KMPurchaseCompareDMGWindowController.init()
  97. singleTon.showWindow(nil)
  98. singleTon.window?.center()
  99. }
  100. } else {
  101. KMPrint("请配置Key...")
  102. }
  103. #else
  104. if controller.currentNameKEY == controller.AIInfoKey {
  105. if AIInfoManager.default().aiInfoValid {
  106. self?.closeAction()
  107. } else {
  108. AIPurchaseWindowController.currentWC().showWindow(nil)
  109. }
  110. } else if controller.currentNameKEY == controller.MeasureInfoKey {
  111. if IAPProductsManager.default().isAvailableAllFunction() {
  112. self?.closeAction()
  113. } else {
  114. let singleTon = KMPurchaseCompareWindowController.init()
  115. singleTon.showWindow(nil)
  116. singleTon.window?.center()
  117. }
  118. }
  119. #endif
  120. self?.closeAction()
  121. }
  122. }
  123. }
  124. get {
  125. return _type;
  126. }
  127. }
  128. func closeAction() {
  129. self.close()
  130. }
  131. }