KMTrialSuccessController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // KMTrialSuccessController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/12/7.
  6. //
  7. import Cocoa
  8. class KMTrialSuccessController: NSViewController {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var infoContendView: NSView!
  11. @IBOutlet weak var iconImg: NSImageView!
  12. @IBOutlet weak var titleLabel: NSTextField!
  13. @IBOutlet weak var subTitleLabel: NSTextField!
  14. @IBOutlet weak var getStartBox: KMBox!
  15. @IBOutlet weak var getStartLabel: NSTextField!
  16. @IBOutlet weak var getStartButton: KMButton!
  17. @objc var clickHandle: ((_ controller: KMTrialSuccessController)->Void)?
  18. convenience init() {
  19. self.init(nibName: "KMTrialSuccessController", bundle: nil)
  20. }
  21. deinit {
  22. DistributedNotificationCenter.default.removeObserver(self)
  23. }
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. // Do view setup here.
  27. self.contendView.wantsLayer = true
  28. self.infoContendView.wantsLayer = true
  29. self.infoContendView.layer?.cornerRadius = 10
  30. self.infoContendView.layer?.masksToBounds = true
  31. self.getStartBox.wantsLayer = true
  32. self.getStartBox.layer?.masksToBounds = true
  33. self.getStartBox.layer?.cornerRadius = CGRectGetHeight(self.getStartBox.frame)/2
  34. self.titleLabel.stringValue = NSLocalizedString("Free Trial PDF Reader Pro for 7 Days!", comment: "")
  35. self.subTitleLabel.stringValue = NSLocalizedString("Congrats! You are eligible to enjoy all advanced features in PDF Reader Pro.", comment: "")
  36. self.getStartLabel.stringValue = NSLocalizedString("Start Now", comment: "")
  37. self.titleLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  38. self.subTitleLabel.font = NSFont.SFProTextRegularFont(14)
  39. self.getStartLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  40. self.getStartButton.wantsLayer = true
  41. self.getStartButton!.mouseMoveCallback = { [weak self] mouseEntered in
  42. if mouseEntered {
  43. self?.getStartButton?.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.15).cgColor
  44. } else {
  45. self?.getStartButton?.layer?.backgroundColor = NSColor.clear.cgColor
  46. }
  47. }
  48. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  49. self.updateViewColor()
  50. }
  51. @objc func updateViewColor() {
  52. if KMAppearance.isDarkMode() {
  53. self.contendView.layer?.backgroundColor = NSColor(red: 57/255.0, green: 58/255.0, blue: 70/255.0, alpha: 1).cgColor
  54. self.infoContendView.layer?.backgroundColor = NSColor(red: 46/255, green: 44/255, blue: 54/255, alpha: 1).cgColor
  55. self.titleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  56. self.subTitleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  57. self.getStartBox.fillColor = NSColor(red: 181/255, green: 177/255, blue: 239/255, alpha: 1)
  58. self.getStartLabel.textColor = NSColor(red: 7/255, green: 1/255, blue: 34/255, alpha: 1)
  59. } else {
  60. self.contendView.layer?.backgroundColor = NSColor(red: 232/255.0, green: 233/255.0, blue: 1, alpha: 1).cgColor
  61. self.infoContendView.layer?.backgroundColor = NSColor(red: 248/255, green: 249/255, blue: 1, alpha: 1).cgColor
  62. self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  63. self.subTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  64. self.getStartBox.fillColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  65. self.getStartLabel.textColor = NSColor.white
  66. }
  67. }
  68. //MARK: IBAction
  69. @IBAction func getStartAction(_ sender: Any) {
  70. guard let callBack = self.clickHandle else {
  71. return
  72. }
  73. callBack(self)
  74. }
  75. @objc func themeChange() {
  76. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  77. self.updateViewColor()
  78. }
  79. }
  80. }