KMFunctionGuideWindowController.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }
  20. return false
  21. }
  22. @objc static func setDidShowFor(_ type: KMGuideInfoType) -> Void {
  23. if type == .functionMulitDidital {
  24. //V3.2.0添加数字签名引导
  25. UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoMultiDigitalKey)
  26. UserDefaults.standard.synchronize()
  27. }
  28. }
  29. //MARK: SystemAction
  30. override func windowDidLoad() {
  31. super.windowDidLoad()
  32. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  33. }
  34. func setContendView(_ view: NSView) {
  35. var frame: CGRect = self.window!.frame
  36. frame.origin.y -= view.frame.size.height-frame.size.height
  37. frame.origin.x -= (view.frame.size.width-frame.size.width)/2.0
  38. frame.size.width = view.frame.size.width
  39. frame.size.height = view.frame.size.height
  40. self.window?.setFrame(frame, display: true, animate: true)
  41. self.contendBox.contentView = view
  42. }
  43. override func showWindow(_ sender: Any?) {
  44. super.showWindow(sender)
  45. DispatchQueue.main.async {
  46. if self.type == .functionSingle {
  47. self.setContendView(self.singleController.view)
  48. } else if self.type == .functionMulti {
  49. self.setContendView(self.multiController.view)
  50. }
  51. }
  52. }
  53. //MARK: Setter
  54. @objc var type: KMGuideInfoType {
  55. set {
  56. _type = newValue;
  57. if _type == .functionSingle {
  58. self.singleController = KMFunctionGuideSingleController.init()
  59. } else if _type == .functionMulti {
  60. self.multiController = KMFunctionGuideMultiController.init()
  61. self.multiController.clickHandle = { controller in
  62. self.closeAction()
  63. }
  64. }
  65. }
  66. get {
  67. return _type;
  68. }
  69. }
  70. func closeAction() {
  71. self.close()
  72. }
  73. }