KMUpgradeWindowController.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //
  2. // KMUpgradeWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/7/23.
  6. //
  7. import Cocoa
  8. class KMUpgradeWindowController: NSWindowController {
  9. @IBOutlet var contendBox: NSBox!
  10. @IBOutlet var titleLabel: NSTextField!
  11. @IBOutlet var enterlicenseBtn: HyperLinkButton!
  12. @IBOutlet var infoContendBox: NSBox!
  13. @IBOutlet var infoDescriptionBox: NSBox!
  14. @IBOutlet var infoSepLineView: NSView!
  15. @IBOutlet var advancedLabel: NSTextField!
  16. @IBOutlet var advancedSubLabel1: NSTextField!
  17. @IBOutlet var advancedSubLabel2: NSTextField!
  18. @IBOutlet var advancedSubLabel3: NSTextField!
  19. @IBOutlet var advancedSubLabel4: NSTextField!
  20. @IBOutlet var advancedSubLabel5: NSTextField!
  21. @IBOutlet var advancedSubLabel6: NSTextField!
  22. @IBOutlet var advancedSubLabel7: NSTextField!
  23. @IBOutlet var businessLabel: NSTextField!
  24. @IBOutlet var businessSubLabel1: NSTextField!
  25. @IBOutlet var businessSubLabel2: NSTextField!
  26. @IBOutlet var businessSubLabel3: NSTextField!
  27. @IBOutlet var businessSubLabel4: NSTextField!
  28. @IBOutlet var businessSubLabel5: NSTextField!
  29. @IBOutlet var businessSubLabel6: NSTextField!
  30. @IBOutlet var totalPriceLabel: NSTextField!
  31. @IBOutlet var licenseAmoutLabel: NSTextField!
  32. @IBOutlet var discountLabel: NSTextField!
  33. @IBOutlet var buynowBox: NSBox!
  34. @IBOutlet var buynowBtn: KMButton!
  35. var gradientView: UpgradeGradientView?
  36. convenience init() {
  37. self.init(windowNibName: "KMUpgradeWindowController")
  38. }
  39. deinit {
  40. DistributedNotificationCenter.default().removeObserver(self)
  41. }
  42. override func windowDidLoad() {
  43. super.windowDidLoad()
  44. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  45. self.initViewInfo()
  46. self.refreshViewColor()
  47. self.reloadData()
  48. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  49. }
  50. func initViewInfo() {
  51. self.contendBox.borderWidth = 0
  52. self.titleLabel.font = NSFont.UbuntuBoldFontWithSize(36)
  53. self.enterlicenseBtn.font = NSFont.SFProTextRegularFont(14)
  54. self.advancedLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  55. self.advancedSubLabel1.font = NSFont.UbuntuRegularFontWithSize(14)
  56. self.advancedSubLabel2.font = NSFont.UbuntuRegularFontWithSize(14)
  57. self.advancedSubLabel3.font = NSFont.UbuntuRegularFontWithSize(14)
  58. self.advancedSubLabel4.font = NSFont.UbuntuRegularFontWithSize(14)
  59. self.advancedSubLabel5.font = NSFont.UbuntuRegularFontWithSize(14)
  60. self.advancedSubLabel6.font = NSFont.UbuntuRegularFontWithSize(14)
  61. self.advancedSubLabel7.font = NSFont.UbuntuRegularFontWithSize(14)
  62. self.businessLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  63. self.businessSubLabel1.font = NSFont.UbuntuMediumFontWithSize(14)
  64. self.businessSubLabel2.font = NSFont.UbuntuMediumFontWithSize(14)
  65. self.businessSubLabel3.font = NSFont.UbuntuMediumFontWithSize(14)
  66. self.businessSubLabel4.font = NSFont.UbuntuMediumFontWithSize(14)
  67. self.businessSubLabel5.font = NSFont.UbuntuMediumFontWithSize(14)
  68. self.businessSubLabel6.font = NSFont.UbuntuMediumFontWithSize(14)
  69. self.totalPriceLabel.font = NSFont.UbuntuBoldFontWithSize(28)
  70. self.buynowBtn.font = NSFont.UbuntuMediumFontWithSize(16)
  71. self.licenseAmoutLabel.font = NSFont.UbuntuRegularFontWithSize(12)
  72. self.discountLabel.font = NSFont.UbuntuMediumFontWithSize(12)
  73. self.infoContendBox.borderWidth = 0
  74. self.infoContendBox.cornerRadius = 4
  75. self.infoContendBox.wantsLayer = true
  76. self.infoContendBox.layer?.cornerRadius = 4
  77. // self.infoContendBox.clipsToBounds = true
  78. self.infoContendBox.layer?.masksToBounds = true
  79. self.infoDescriptionBox.borderWidth = 0
  80. self.titleLabel.stringValue = NSLocalizedString("Upgrade to Permanent Version", comment: "")
  81. self.enterlicenseBtn.title = NSLocalizedString("Enter License", comment: "")
  82. self.advancedLabel.stringValue = NSLocalizedString("Advanced Features", comment: "")
  83. self.advancedSubLabel1.stringValue = NSLocalizedString("Create, sign, and manage document", comment: "")
  84. self.advancedSubLabel2.stringValue = NSLocalizedString("Edit PDF text, image and pages", comment: "")
  85. self.advancedSubLabel3.stringValue = NSLocalizedString("Collaborative review and annotate PDFs", comment: "")
  86. self.advancedSubLabel4.stringValue = NSLocalizedString("Secure and redact to protect privacy data", comment: "")
  87. self.advancedSubLabel5.stringValue = NSLocalizedString("Digital & electronic signatures", comment: "")
  88. self.advancedSubLabel6.stringValue = NSLocalizedString("Create Custom Stamp", comment: "")
  89. self.advancedSubLabel7.stringValue = NSLocalizedString("Create & fill forms", comment: "")
  90. self.businessLabel.stringValue = NSLocalizedString("Business Service Rights", comment: "")
  91. self.businessSubLabel1.stringValue = NSLocalizedString("Manage licenses with Admin Console", comment: "")
  92. self.businessSubLabel2.stringValue = NSLocalizedString("Optional deployment method", comment: "")
  93. self.businessSubLabel3.stringValue = NSLocalizedString("Support on-premise deployment", comment: "")
  94. self.businessSubLabel4.stringValue = NSLocalizedString("Free update", comment: "")
  95. self.businessSubLabel5.stringValue = NSLocalizedString("Support SSO (Single Sign-on)", comment: "")
  96. self.businessSubLabel6.stringValue = NSLocalizedString("High-Standard data encryption", comment: "")
  97. self.buynowBtn.title = NSLocalizedString("Buy Now", comment: "")
  98. self.infoSepLineView.wantsLayer = true
  99. self.gradientView = UpgradeGradientView.init(frame: self.contendBox.bounds)
  100. self.gradientView?.autoresizingMask = [.width, .height]
  101. self.gradientView?.wantsLayer = true
  102. self.contendBox.contentView?.addSubview(self.gradientView!, positioned: .below, relativeTo: self.titleLabel)
  103. }
  104. func refreshViewColor() {
  105. self.infoContendBox.fillColor = NSColor(red: 36/255, green: 43/255, blue: 90/255, alpha: 1)
  106. self.infoDescriptionBox.fillColor = NSColor.white
  107. self.titleLabel.textColor = NSColor.white
  108. self.advancedLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1)
  109. self.advancedSubLabel1.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  110. self.advancedSubLabel2.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  111. self.advancedSubLabel3.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  112. self.advancedSubLabel4.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  113. self.advancedSubLabel5.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  114. self.advancedSubLabel6.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  115. self.advancedSubLabel7.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1)
  116. self.enterlicenseBtn.setTitleColor(NSColor.white)
  117. self.businessLabel.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  118. self.businessSubLabel1.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  119. self.businessSubLabel2.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  120. self.businessSubLabel3.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  121. self.businessSubLabel4.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  122. self.businessSubLabel5.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  123. self.businessSubLabel6.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1)
  124. self.totalPriceLabel.textColor = NSColor(red: 1, green: 214/255, blue: 102/255, alpha: 1)
  125. self.licenseAmoutLabel.textColor = NSColor(red: 160/255, green: 162/255, blue: 174/255, alpha: 1)
  126. self.discountLabel.textColor = NSColor.white
  127. self.infoSepLineView.layer?.backgroundColor = NSColor(red: 231/255, green: 231/255, blue: 231/255, alpha: 1).cgColor
  128. }
  129. func reloadData() {
  130. self.totalPriceLabel.isHidden = true
  131. self.licenseAmoutLabel.isHidden = true
  132. self.discountLabel.isHidden = true
  133. guard let licenseCount = KMAdsInfoManager.shareInstance.licenseCount else {
  134. return
  135. }
  136. self.totalPriceLabel.isHidden = false
  137. self.licenseAmoutLabel.isHidden = false
  138. self.discountLabel.isHidden = false
  139. self.totalPriceLabel.stringValue = licenseCount.totalPrice
  140. self.licenseAmoutLabel.stringValue = "(" + NSLocalizedString("Amount", comment: "") + licenseCount.amount + ")"
  141. self.discountLabel.stringValue = NSLocalizedString("Discounted", comment: "") + licenseCount.discount
  142. }
  143. //MARK: IBAction
  144. @IBAction func enterlicenseAction(_ sender: Any) {
  145. self.close()
  146. if (IAPProductsManager.default().isAvailableAllFunction()) {
  147. let vc = KMVerificationWindowController.verification(with:.info)
  148. vc?.callback = { [weak self] in
  149. }
  150. vc?.showWindow(nil)
  151. } else {
  152. let vc = KMVerificationWindowController.verification(with:.activate)
  153. vc?.callback = { [weak self] in
  154. }
  155. vc?.showWindow(nil)
  156. }
  157. }
  158. @IBAction func buyAction(_ sender: Any) {
  159. FMTrackEventManager.defaultManager.lynxTrackEvent(event: "OnbrdTop", withProperties: ["OnbrdTop_Tbr" : "OnbrdTop_Tbr_BuyNowExpire"])
  160. #if VERSION_DMG
  161. let string = "https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=app_dmg&utm_medium=dmg_puw_comparison"
  162. let url: URL = URL(string: string)!
  163. NSWorkspace.shared.open(url)
  164. #endif
  165. }
  166. @objc func themeChange() {
  167. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  168. self.refreshViewColor()
  169. }
  170. }
  171. override func showWindow(_ sender: Any?) {
  172. super.showWindow(sender)
  173. self.window?.center()
  174. }
  175. }
  176. class UpgradeGradientView: NSView {
  177. override func draw(_ dirtyRect: NSRect) {
  178. super.draw(dirtyRect)
  179. setupGradient()
  180. }
  181. private func setupGradient() {
  182. let gradientLayer = CAGradientLayer()
  183. gradientLayer.frame = self.bounds
  184. gradientLayer.colors = [NSColor(red: 55/255, green: 102/255, blue: 255/255, alpha: 1).cgColor,
  185. NSColor(red: 84/255, green: 62/255, blue: 213/255, alpha: 1).cgColor] // 设置渐变颜色
  186. gradientLayer.startPoint = CGPoint(x: 0.0, y: 1.0)
  187. gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0)
  188. // 移除之前的渐变层(如果存在)
  189. if let existingLayer = self.layer?.sublayers?.first(where: { $0 is CAGradientLayer }) {
  190. existingLayer.removeFromSuperlayer()
  191. }
  192. self.wantsLayer = true
  193. self.layer?.addSublayer(gradientLayer)
  194. gradientLayer.frame = self.bounds // 确保渐变层的大小与视图一致
  195. }
  196. override func viewDidMoveToSuperview() {
  197. super.viewDidMoveToSuperview()
  198. setupGradient()
  199. }
  200. override func layout() {
  201. super.layout()
  202. if let gradientLayer = self.layer?.sublayers?.first as? CAGradientLayer {
  203. gradientLayer.frame = self.bounds // 重新设置渐变层的大小
  204. }
  205. }
  206. }