KMFunctionGuideWindowController.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. var url = URL(string:kAIStoreServerLink)!
  80. NSWorkspace.shared.open(url)
  81. #else
  82. AIPurchaseWindowController.currentWC().showWindow(nil)
  83. #endif
  84. self?.closeAction()
  85. }
  86. }
  87. }
  88. get {
  89. return _type;
  90. }
  91. }
  92. func closeAction() {
  93. self.close()
  94. }
  95. }