KMPurchaseLimitWindowController.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. 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. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
  46. self.refreshUI()
  47. }
  48. func refreshUI() {
  49. self.contendView.wantsLayer = true
  50. self.titleLbl.stringValue = NSLocalizedString("Purchase PDF to Office Pack", comment: "")
  51. self.subTitleLabel.stringValue = NSLocalizedString("Convert first 10 pages only. Purchase PDF to Office Pack to convert all pages.", comment: "")
  52. self.infoTitleLabel.stringValue = NSLocalizedString("PDF to Office Pack Benefits", comment: "")
  53. self.desLabel1.stringValue = NSLocalizedString("Unlimited PDF file conversion", comment: "")
  54. self.desLabel2.stringValue = NSLocalizedString("Get converted files in high quality", comment: "")
  55. self.desLabel3.stringValue = NSLocalizedString("Batch Convert PDFs", comment: "")
  56. self.subTitleLabel.textColor = KMAppearance.Layout.h0Color()
  57. self.infoTitleLabel.textColor = KMAppearance.Layout.h0Color()
  58. self.desLabel1.textColor = KMAppearance.Layout.h0Color()
  59. self.desLabel2.textColor = KMAppearance.Layout.h0Color()
  60. self.desLabel3.textColor = KMAppearance.Layout.h0Color()
  61. self.titleLbl.font = NSFont.UbuntuBoldFontWithSize(21)
  62. self.subTitleLabel.font = NSFont.SFProTextRegularFont(14)
  63. self.infoTitleLabel.font = NSFont.SFMediumFontWithSize(16)
  64. self.desLabel1.font = NSFont.SFProTextRegularFont(14)
  65. self.desLabel2.font = NSFont.SFProTextRegularFont(14)
  66. self.desLabel3.font = NSFont.SFProTextRegularFont(14)
  67. self.purchaseBox.wantsLayer = true
  68. self.purchaseBox.cornerRadius = CGRectGetHeight(self.purchaseBox.frame)/2
  69. self.purchaseBox.layer?.masksToBounds = true
  70. self.purchaseBtn.wantsLayer = true
  71. self.purchaseBtn.layer?.cornerRadius = CGRectGetHeight(self.purchaseBtn.frame)/2.0
  72. self.purchaseBtn.layer?.masksToBounds = true
  73. self.purchaseBtn.title = NSLocalizedString("Upgrade", comment: "")
  74. self.purchaseBtn.setTitleColor(NSColor.white)
  75. self.purchaseBtn.mouseMoveCallback = { mouseEntered in
  76. if mouseEntered {
  77. self.purchaseBtn.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.15).cgColor
  78. } else {
  79. self.purchaseBtn.layer?.backgroundColor = NSColor.clear.cgColor
  80. }
  81. }
  82. // self.purchaseBtn.setTitleFont(NSFont.UbuntuBoldFontWithSize(16)
  83. self.convertButton.title = NSLocalizedString("Refresh Purchase Status", comment: "")
  84. self.convertButton.mouseMoveCallback = { mouseEntered in
  85. if mouseEntered {
  86. if KMAppearance.isDarkMode() {
  87. self.convertButton.setTitleColor(NSColor.white)
  88. } else {
  89. self.convertButton.setTitleColor(NSColor(red: 8/255.0, green: 124/255.0, blue: 255/255.0, alpha: 1))
  90. }
  91. } else {
  92. if KMAppearance.isDarkMode() {
  93. self.convertButton.setTitleColor(NSColor(red: 181/255.0, green: 179/255.0, blue: 231/255.0, alpha: 1))
  94. } else {
  95. self.convertButton.setTitleColor(NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1))
  96. }
  97. }
  98. }
  99. self.updateViewColor()
  100. }
  101. func updateViewColor() {
  102. if KMAppearance.isDarkMode() {
  103. self.contendView.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1).cgColor
  104. self.titleLbl.textColor = NSColor(red: 1, green: 1, blue: 1, alpha: 1)
  105. self.convertButton.setTitleColor(NSColor(red: 181/255.0, green: 179/255.0, blue: 231/255.0, alpha: 1))
  106. } else {
  107. self.contendView.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1, alpha: 1).cgColor
  108. self.titleLbl.textColor = NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1)
  109. self.convertButton.setTitleColor(NSColor(red: 0, green: 33/255.0, blue: 67/255.0, alpha: 1))
  110. }
  111. }
  112. func addWaingView(_ view: NSView) {
  113. self.removeWaitingView(view)
  114. let wView = WaitingView.init(frame: view.bounds)
  115. wView.autoresizingMask = [.width, .height]
  116. view.addSubview(wView)
  117. wView.startAnimation()
  118. }
  119. func removeWaitingView(_ view: NSView) {
  120. let views = NSArray.init(array: view.subviews)
  121. for subView in views {
  122. if (subView as AnyObject).isKind(of: WaitingView.self) {
  123. (subView as AnyObject).removeFromSuperview()
  124. }
  125. }
  126. }
  127. //MARK: IBAction
  128. @IBAction func unlimitConvertAction(_ sender: Any) {
  129. var url = URL(string:"https://www.pdfreaderpro.com/store?product_code=product_2&utm_source=MacAppDmg&utm_campaign=OfficeStoreLink&utm_medium=PdfOfficeStore")!
  130. if SKInspectPublicTool.currentisLanguageHans() == true {
  131. url = URL(string: "https://www.pdfreaderpro.com/zh-cn/store?product_code=product_2&utm_source=MacAppDmg&utm_campaign=OfficeStoreLink&utm_medium=PdfOfficeStore")!
  132. }
  133. NSWorkspace.shared.open(url)
  134. FMTrackEventManager.defaultManager.trackOnceEvent(event: "PUW", withProperties: ["PUW_Btn":"Btn_PUW_PDFtoOffice_Buy"])
  135. }
  136. @IBAction func continueConvertAction(_ sender: Any) {
  137. VerificationManager.default().verification { status, info, error in
  138. if (error != nil) {
  139. let alert = NSAlert.init()
  140. alert.messageText = NSLocalizedString("Failed to Refresh", comment: "")
  141. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  142. alert.runModal()
  143. }
  144. self.removeWaitingView(self.contendView)
  145. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
  146. self.close()
  147. }
  148. }
  149. self.addWaingView(self.contendView)
  150. }
  151. @objc func themeChange() {
  152. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  153. self.updateViewColor()
  154. }
  155. }
  156. }