KMFunctionGuideWindowController.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. DispatchQueue.main.async {
  62. if self.type == .functionSingle {
  63. self.setContendView(self.singleController.view)
  64. } else if self.type == .functionMulti {
  65. self.setContendView(self.multiController.view)
  66. }
  67. }
  68. }
  69. //MARK: Setter
  70. @objc var type: KMGuideInfoType {
  71. set {
  72. _type = newValue;
  73. if _type == .functionSingle {
  74. self.singleController = KMFunctionGuideSingleController.init()
  75. } else if _type == .functionMulti {
  76. self.multiController = KMFunctionGuideMultiController.init()
  77. self.multiController.clickHandle = {[weak self] controller in
  78. #if VERSION_DMG
  79. if controller.currentNameKEY == controller.AIInfoKey {
  80. // var url = URL(string: AIProduct_Link)!
  81. // NSWorkspace.shared.open(url)
  82. if AIInfoManager.default().aiInfoValid {
  83. self?.closeAction()
  84. } else {
  85. let singleTon = KMPurchaseCompareDMGWindowController.init()
  86. singleTon.showWindow(nil)
  87. singleTon.window?.center()
  88. }
  89. } else if controller.currentNameKEY == controller.MeasureInfoKey {
  90. // var url = URL(string: Store_Link)!
  91. // NSWorkspace.shared.open(url)
  92. if VerificationManager.default().status == ActivityStatusVerification {
  93. self?.closeAction()
  94. } else {
  95. let singleTon = KMPurchaseCompareDMGWindowController.init()
  96. singleTon.showWindow(nil)
  97. singleTon.window?.center()
  98. }
  99. } else {
  100. KMPrint("请配置Key...")
  101. }
  102. #else
  103. if controller.currentNameKEY == controller.AIInfoKey {
  104. if AIInfoManager.default().aiInfoValid {
  105. self?.closeAction()
  106. } else {
  107. AIPurchaseWindowController.currentWC().showWindow(nil)
  108. }
  109. } else if controller.currentNameKEY == controller.MeasureInfoKey {
  110. if IAPProductsManager.default().isAvailableAllFunction() {
  111. self?.closeAction()
  112. } else {
  113. let singleTon = KMPurchaseCompareWindowController.init()
  114. singleTon.showWindow(nil)
  115. singleTon.window?.center()
  116. }
  117. AccountTools.canUseAdvance_success { can in
  118. }
  119. }
  120. #endif
  121. self?.closeAction()
  122. }
  123. }
  124. }
  125. get {
  126. return _type;
  127. }
  128. }
  129. func closeAction() {
  130. self.close()
  131. }
  132. }