KMPurchaseLimitWindowController.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // KMPurchaseLimitWindowController.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/11/20.
  6. //
  7. import Cocoa
  8. class KMPurchaseLimitWindowController: NSWindowController {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var infoContendView: NSView!
  11. @IBOutlet weak var titleLbl: NSTextField!
  12. @IBOutlet weak var subTitleLabel: NSTextField!
  13. @IBOutlet weak var infoTitleLabel: NSTextField!
  14. @IBOutlet weak var desLabel1: NSTextField!
  15. @IBOutlet weak var desLabel2: NSTextField!
  16. @IBOutlet weak var desLabel3: NSTextField!
  17. @IBOutlet weak var purchaseBox: NSBox!
  18. @IBOutlet weak var purchaseBtn: KMButton!
  19. @IBOutlet weak var convertButton: HyperLinkButton!
  20. @objc var continueBlock: ((_ limitWC: KMPurchaseLimitWindowController)->Void)?
  21. //MARK: 打开文件
  22. @objc static func currentLimitWC() -> KMPurchaseLimitWindowController {
  23. if let controller: KMPurchaseLimitWindowController = KMPurchaseLimitWindowController.fetchSampleController() {
  24. return controller
  25. } else {
  26. let purchaseLimitWC: KMPurchaseLimitWindowController = KMPurchaseLimitWindowController.init(windowNibName: "KMPurchaseLimitWindowController")
  27. return purchaseLimitWC
  28. }
  29. }
  30. static func fetchSampleController() -> KMPurchaseLimitWindowController? {
  31. for window in NSApp.windows {
  32. let controller = window.windowController
  33. if controller is KMPurchaseLimitWindowController {
  34. return controller as? KMPurchaseLimitWindowController
  35. }
  36. }
  37. return nil
  38. }
  39. override func windowDidLoad() {
  40. super.windowDidLoad()
  41. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  42. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  43. self.refreshUI()
  44. }
  45. func refreshUI() {
  46. self.contendView.wantsLayer = true
  47. self.titleLbl.stringValue = NSLocalizedString("Purchase PDF to Office Pack", comment: "")
  48. self.subTitleLabel.stringValue = NSLocalizedString("Convert first 10 pages only. Purchase PDF to Office Pack to convert all pages.", comment: "")
  49. self.infoTitleLabel.stringValue = NSLocalizedString("PDF to Office Pack Benefits", comment: "")
  50. self.desLabel1.stringValue = NSLocalizedString("Unlimited PDF file conversion", comment: "")
  51. self.desLabel2.stringValue = NSLocalizedString("Get converted files in high quality", comment: "")
  52. self.desLabel3.stringValue = NSLocalizedString("Batch Convert PDFs", comment: "")
  53. self.subTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  54. self.infoTitleLabel.textColor = KMAppearance.KMColor_Layout_H0()
  55. self.desLabel1.textColor = KMAppearance.KMColor_Layout_H0()
  56. self.desLabel2.textColor = KMAppearance.KMColor_Layout_H0()
  57. self.desLabel3.textColor = KMAppearance.KMColor_Layout_H0()
  58. self.titleLbl.font = NSFont.UbuntuBoldFontWithSize(21)
  59. self.subTitleLabel.font = NSFont.SFProTextRegularFont(14)
  60. self.infoTitleLabel.font = NSFont.SFMediumFontWithSize(16)
  61. self.desLabel1.font = NSFont.SFProTextRegularFont(14)
  62. self.desLabel2.font = NSFont.SFProTextRegularFont(14)
  63. self.desLabel3.font = NSFont.SFProTextRegularFont(14)
  64. self.purchaseBox.wantsLayer = true
  65. self.purchaseBox.cornerRadius = CGRectGetHeight(self.purchaseBox.frame)/2
  66. self.purchaseBox.layer?.masksToBounds = true
  67. self.purchaseBtn.wantsLayer = true
  68. self.purchaseBtn.layer?.cornerRadius = CGRectGetHeight(self.purchaseBtn.frame)/2.0
  69. self.purchaseBtn.layer?.masksToBounds = true
  70. self.purchaseBtn.title = NSLocalizedString("Upgrade", comment: "")
  71. self.purchaseBtn.setTitleColor(NSColor.white)
  72. self.purchaseBtn.mouseMoveCallback = { mouseEntered in
  73. if mouseEntered {
  74. self.purchaseBtn.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.15).cgColor
  75. } else {
  76. self.purchaseBtn.layer?.backgroundColor = NSColor.clear.cgColor
  77. }
  78. }
  79. // self.purchaseBtn.setTitleFont(NSFont.UbuntuBoldFontWithSize(16)
  80. self.convertButton.title = NSLocalizedString("Refresh Purchase Status", comment: "")
  81. self.convertButton.mouseMoveCallback = { mouseEntered in
  82. if mouseEntered {
  83. if KMAppearance.isDarkMode() {
  84. self.convertButton.setTitleColor(NSColor.white)
  85. } else {
  86. self.convertButton.setTitleColor(NSColor(red: 8/255.0, green: 124/255.0, blue: 255/255.0, alpha: 1))
  87. }
  88. } else {
  89. if KMAppearance.isDarkMode() {
  90. self.convertButton.setTitleColor(NSColor(red: 181/255.0, green: 179/255.0, blue: 231/255.0, alpha: 1))
  91. } else {
  92. self.convertButton.setTitleColor(NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1))
  93. }
  94. }
  95. }
  96. self.updateViewColor()
  97. }
  98. func updateViewColor() {
  99. if KMAppearance.isDarkMode() {
  100. self.contendView.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1).cgColor
  101. self.titleLbl.textColor = NSColor(red: 1, green: 1, blue: 1, alpha: 1)
  102. self.convertButton.setTitleColor(NSColor(red: 181/255.0, green: 179/255.0, blue: 231/255.0, alpha: 1))
  103. } else {
  104. self.contendView.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1, alpha: 1).cgColor
  105. self.titleLbl.textColor = NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1)
  106. self.convertButton.setTitleColor(NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1))
  107. }
  108. }
  109. func addWaingView(_ view: NSView) {
  110. self.removeWaitingView(view)
  111. let wView = WaitingView.init(frame: view.bounds)
  112. wView.autoresizingMask = [.width, .height]
  113. view.addSubview(wView)
  114. wView.startAnimation()
  115. }
  116. func removeWaitingView(_ view: NSView) {
  117. let views = NSArray.init(array: view.subviews)
  118. for subView in views {
  119. if (subView as AnyObject).isKind(of: WaitingView.self) {
  120. (subView as AnyObject).removeFromSuperview()
  121. }
  122. }
  123. }
  124. //MARK: IBAction
  125. @IBAction func unlimitConvertAction(_ sender: Any) {
  126. var url = URL(string:"https://www.pdfreaderpro.com/store?product_code=product_2&utm_source=MacAppDmg&utm_campaign=OfficeStoreLink&utm_medium=PdfOfficeStore")!
  127. if SKInspectPublicTool.currentisLanguageHans() == true {
  128. url = URL(string: "https://www.pdfreaderpro.com/zh-cn/store?product_code=product_2&utm_source=MacAppDmg&utm_campaign=OfficeStoreLink&utm_medium=PdfOfficeStore")!
  129. }
  130. NSWorkspace.shared.open(url)
  131. // FMTrackEventManager.default().trackOnceEvent("PUW", withProperties: ["PUW_Btn":"Btn_PUW_PDFtoOffice_Buy"])
  132. }
  133. @IBAction func continueConvertAction(_ sender: Any) {
  134. VerificationManager.default().verification { status, info, error in
  135. if (error != nil) {
  136. let alert = NSAlert.init()
  137. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  138. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  139. alert.runModal()
  140. }
  141. self.removeWaitingView(self.contendView)
  142. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  143. self.close()
  144. }
  145. }
  146. self.addWaingView(self.contendView)
  147. }
  148. @objc func themeChange() {
  149. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  150. self.updateViewColor()
  151. }
  152. }
  153. }