KMFunctionGuideMultiController.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. // KMFunctionGuideMultiController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/6.
  6. //
  7. import Cocoa
  8. class KMFunctionGuideMultiController: NSViewController {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var titleInfoView: NSView!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var typeNameView: NSView!
  13. @IBOutlet weak var getStartBox: KMBox!
  14. @IBOutlet weak var getStartLabel: NSTextField!
  15. @IBOutlet weak var getStartButton: KMButton!
  16. @IBOutlet weak var learnButton: HyperLinkButton!
  17. @IBOutlet weak var nameHeightConst: NSLayoutConstraint!
  18. @IBOutlet weak var descriptionBGView: NSView!
  19. @IBOutlet weak var iconImage: NSImageView!
  20. @IBOutlet weak var previousButton: KMButton!
  21. @IBOutlet weak var nextButton: KMButton!
  22. @IBOutlet weak var desLabel: NSTextField!
  23. @IBOutlet weak var desSubLabel: NSTextField!
  24. let DigitalSignatureKey = "DigitalSignatureKey"
  25. let ComparePDFsKey = "ComparePDFsKey"
  26. var namesArr = Array<Any>()
  27. var currentNameKEY = String()
  28. var clickHandle: ((_ controller: KMFunctionGuideMultiController)->Void)?
  29. deinit {
  30. DistributedNotificationCenter.default.removeObserver(self)
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. // Do view setup here.
  35. self.namesArr = [["name":"Digital Signature","key":DigitalSignatureKey,"imageName":"whatNew_Digital","description":"Digital signature verify the authenticity and integrity of documents, agreements, or contract, ensuring that the signature cannot be tampered with and provides a higher level of security."]]
  36. let dict = self.namesArr.first as! NSDictionary
  37. self.currentNameKEY = dict["key"] as! String
  38. self.loadTypeNameView()
  39. self.reloadNameViewInfo()
  40. self.reloadDescriptionInfo()
  41. self.descriptionBGView.wantsLayer = true
  42. self.titleInfoView.wantsLayer = true
  43. self.getStartBox.wantsLayer = true
  44. self.getStartBox.layer?.cornerRadius = 4
  45. self.getStartBox.layer?.masksToBounds = true
  46. self.titleLabel.stringValue = NSLocalizedString("What‘s New", comment: "")
  47. self.getStartLabel.stringValue = NSLocalizedString("Got it", comment: "")
  48. self.learnButton.title = NSLocalizedString("Learn More", comment: "")
  49. self.learnButton.toolTip = NSLocalizedString("Learn More", comment: "")
  50. self.titleLabel.font = NSFont.SFProTextHeavyFont(20)
  51. self.getStartLabel.font = NSFont.SFProTextSemiboldFont(14)
  52. self.learnButton.font = NSFont.SFProTextSemiboldFont(14)
  53. self.desLabel.font = NSFont.SFProTextSemiboldFont(14)
  54. self.desSubLabel.font = NSFont.SFProTextRegularFont(14)
  55. self.getStartButton.mouseMoveCallback = { [weak self] mouseEntered in
  56. if KMAppearance.isDarkMode() {
  57. if mouseEntered {
  58. self?.getStartBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1)
  59. } else {
  60. self?.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  61. }
  62. } else {
  63. if mouseEntered {
  64. self?.getStartBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1)
  65. } else {
  66. self?.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  67. }
  68. }
  69. }
  70. self.learnButton.mouseMoveCallback = { [weak self] mouseEntered in
  71. if mouseEntered {
  72. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M1())
  73. } else {
  74. self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  75. }
  76. }
  77. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  78. self.updateViewColor()
  79. }
  80. func loadTypeNameView() {
  81. // self.typeNameView.wantsLayer = true
  82. // self.typeNameView.layer?.backgroundColor = NSColor.red.cgColor
  83. var offsetY: CGFloat = 0
  84. let itemHeight: CGFloat = 32
  85. let viewHeight: CGFloat = itemHeight * CGFloat(self.namesArr.count)
  86. self.nameHeightConst.constant = viewHeight
  87. for i in 0...self.namesArr.count - 1 {
  88. let dict = self.namesArr[i]
  89. let nameItem: KMFunctionGuideNameItemView = KMFunctionGuideNameItemView.createFromNib()!
  90. nameItem.frame = CGRectMake(0, viewHeight - offsetY - itemHeight, CGRectGetWidth(self.typeNameView.frame), itemHeight)
  91. nameItem.infoDict = dict as! NSDictionary
  92. nameItem.clickHandle = { view in
  93. self.currentNameKEY = view.infoDict["key"] as! String
  94. self.reloadNameViewInfo()
  95. self.reloadDescriptionInfo()
  96. }
  97. nameItem.autoresizingMask = [.width, .maxYMargin]
  98. self.typeNameView.addSubview(nameItem)
  99. offsetY += itemHeight
  100. }
  101. if self.namesArr.count > 1 {
  102. self.previousButton.isHidden = false
  103. self.nextButton.isHidden = false
  104. } else {
  105. self.previousButton.isHidden = true
  106. self.nextButton.isHidden = true
  107. }
  108. }
  109. func reloadNameViewInfo() {
  110. for view in self.typeNameView.subviews {
  111. if view is KMFunctionGuideNameItemView {
  112. let itemView = view as! KMFunctionGuideNameItemView
  113. if itemView.infoDict["key"] as! String == self.currentNameKEY {
  114. itemView.isSelected = true
  115. } else {
  116. itemView.isSelected = false
  117. }
  118. }
  119. }
  120. }
  121. func reloadDescriptionInfo() {
  122. self.previousButton.isEnabled = true
  123. self.nextButton.isEnabled = true
  124. for i in 0...self.namesArr.count - 1 {
  125. let dict = self.namesArr[i] as! NSDictionary
  126. if dict["key"] as! String == self.currentNameKEY {
  127. self.desLabel.stringValue = NSLocalizedString(dict["name"] as! String, comment: "")
  128. self.desSubLabel.stringValue = NSLocalizedString(dict["description"] as! String, comment: "")
  129. self.iconImage.image = NSImage(named: dict["imageName"] as! String)
  130. }
  131. let keyValue = dict["key"] as! String
  132. if i == 0 && keyValue == self.currentNameKEY {
  133. self.previousButton.isEnabled = false
  134. } else if i == self.namesArr.count - 1 && keyValue == self.currentNameKEY {
  135. self.nextButton.isEnabled = false
  136. }
  137. }
  138. }
  139. func updateViewColor() {
  140. self.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0()
  141. self.getStartLabel.textColor = KMAppearance.KMColor_Layout_W0()
  142. self.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0())
  143. if KMAppearance.isDarkMode() {
  144. self.titleInfoView.layer?.backgroundColor = NSColor(red: 40/255.0, green: 40/255, blue: 40/255, alpha: 1).cgColor
  145. self.descriptionBGView.layer?.backgroundColor = NSColor(red: 14/255.0, green: 17/255, blue: 20/255, alpha: 1).cgColor
  146. self.titleLabel.textColor = NSColor.white
  147. self.desLabel.textColor = NSColor.white
  148. self.desSubLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1)
  149. self.getStartBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1)
  150. } else {
  151. self.titleInfoView.layer?.backgroundColor = NSColor.white.cgColor
  152. self.descriptionBGView.layer?.backgroundColor = NSColor(red: 235/255.0, green: 236/255, blue: 240/255, alpha: 1).cgColor
  153. self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  154. self.desLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  155. self.desSubLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1)
  156. self.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1)
  157. }
  158. for view in self.typeNameView.subviews {
  159. if view is KMFunctionGuideNameItemView {
  160. let itemView = view as! KMFunctionGuideNameItemView
  161. itemView.updateViewColor()
  162. }
  163. }
  164. }
  165. //MARK: IBAction
  166. @IBAction func getStartAction(_ sender: Any) {
  167. guard let callBack = self.clickHandle else {
  168. return
  169. }
  170. callBack(self)
  171. }
  172. @IBAction func learnMoreAction(_ sender: Any) {
  173. #if VERSION_DMG
  174. var url = URL(string:"https://www.pdfreaderpro.com/blog/digital-signature-update-mac-and-windows?utm_source=app_dmg&utm_medium=whatsnew_digitalsign_blog")!
  175. NSWorkspace.shared.open(url)
  176. #else
  177. var url = URL(string:"https://www.pdfreaderpro.com/blog/digital-signature-update-mac-and-windows?utm_source=app_mac&utm_medium=whatsnew_digitalsign_blog")!
  178. NSWorkspace.shared.open(url)
  179. #endif
  180. }
  181. @IBAction func previousAction(_ sender: Any) {
  182. for i in 0...self.namesArr.count - 1 {
  183. let dict = self.namesArr[i] as! NSDictionary
  184. if dict["key"] as! String == self.currentNameKEY {
  185. if i > 0 {
  186. let preDic = self.namesArr[i-1] as! NSDictionary
  187. self.currentNameKEY = preDic["key"] as! String
  188. break
  189. }
  190. }
  191. }
  192. self.reloadNameViewInfo()
  193. self.reloadDescriptionInfo()
  194. }
  195. @IBAction func nextAction(_ sender: Any) {
  196. for i in 0...self.namesArr.count - 1 {
  197. let dict = self.namesArr[i] as! NSDictionary
  198. if dict["key"] as! String == self.currentNameKEY {
  199. if i < self.namesArr.count {
  200. let nextDic = self.namesArr[i+1] as! NSDictionary
  201. self.currentNameKEY = nextDic["key"] as! String
  202. break
  203. }
  204. }
  205. }
  206. self.reloadNameViewInfo()
  207. self.reloadDescriptionInfo()
  208. }
  209. @objc func themeChange() {
  210. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  211. self.updateViewColor()
  212. }
  213. }
  214. }