KMFreeGetAIWC.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // KMFreeGetAIWC.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/11.
  6. //
  7. import Cocoa
  8. @objcMembers
  9. class KMFreeGetAIWC: NSWindowController {
  10. @IBOutlet weak var titleLabel1: NSTextField!
  11. @IBOutlet weak var subTitle1: NSTextField!
  12. @IBOutlet weak var subTitle2: NSTextField!
  13. @IBOutlet weak var subTitle3: NSTextField!
  14. @IBOutlet weak var aitoolsBox: KMBox!
  15. @IBOutlet weak var aitoolsLabel: NSTextField!
  16. @IBOutlet weak var laterButton: NSButton!
  17. @IBOutlet weak var privacyPolicyLabel: NSTextField!
  18. @IBOutlet weak var termsServiceLabel: NSTextField!
  19. private var viewModel = KMProductModel()
  20. static let shared: KMFreeGetAIWC = {
  21. let windowC = KMFreeGetAIWC(windowNibName: "KMFreeGetAIWC")
  22. return windowC
  23. }()
  24. override func windowDidLoad() {
  25. super.windowDidLoad()
  26. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  27. languageLocalized()
  28. initializeUI()
  29. subTitle2.isHidden = true
  30. subTitle3.isHidden = true
  31. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  32. }
  33. @objc func themeChanged(_ notification: Notification) {
  34. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  35. self.initializeUI()
  36. }
  37. }
  38. // MARK: Private Method
  39. private func languageLocalized() -> Void {
  40. var productPrice = ""
  41. #if VERSION_FREE
  42. #if VERSION_DMG
  43. productPrice = KMProductModel.shared.getProductPrice(.pdfReaderProStandard_dmg)
  44. #else
  45. productPrice = IAPProductsManager.default().aiAllAccessPack12month_lite.price()
  46. #endif
  47. #else
  48. productPrice = IAPProductsManager.default().aiAllAccessPack12month_pro.price()
  49. #endif
  50. let firmString = NSLocalizedString("Free for the first year, then automatically renew at %@ annually. You can cancel your subscription anytime.", tableName: "MemberCenterLocalizable", comment: "")
  51. let fireFullString = String(format: firmString, productPrice)
  52. titleLabel1.stringValue = NSLocalizedString("1-Year AI Tools Giveaway", tableName: "MemberCenterLocalizable", comment: "")
  53. subTitle1.stringValue = String(format: " · %@", fireFullString)
  54. subTitle2.stringValue = String(format: " · %@", NSLocalizedString("Free for the first year, then auto-renewal at $125.99 per year. You can cancel your subscription anytime.", tableName: "MemberCenterLocalizable", comment: ""))
  55. subTitle3.stringValue = String(format: " · %@", NSLocalizedString("Pick up free AI Tools before 23:59:00, or it will be invalid", tableName: "MemberCenterLocalizable", comment: ""))
  56. aitoolsLabel.stringValue = NSLocalizedString("Get 1-Year AI Tools with $0", tableName: "MemberCenterLocalizable", comment: "")
  57. laterButton.title = NSLocalizedString("Later", tableName: "MemberCenterLocalizable", comment: "")
  58. privacyPolicyLabel.isEditable = false
  59. privacyPolicyLabel.isSelectable = true
  60. privacyPolicyLabel.allowsEditingTextAttributes = true
  61. termsServiceLabel.isEditable = false
  62. termsServiceLabel.isSelectable = true
  63. termsServiceLabel.allowsEditingTextAttributes = true
  64. NotificationCenter.default.addObserver(
  65. self,
  66. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  67. name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
  68. object: nil
  69. )
  70. NotificationCenter.default.addObserver(
  71. self,
  72. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  73. name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
  74. object: nil
  75. )
  76. let privacyPolicy = NSLocalizedString("Privacy Policy", tableName: "MemberCenterLocalizable", comment: "")
  77. let termsService = NSLocalizedString("Service Agreement", tableName: "MemberCenterLocalizable", comment: "")
  78. let attributedString1 = NSMutableAttributedString(string: privacyPolicy)
  79. let attributedString2 = NSMutableAttributedString(string: termsService)
  80. let privacyPolicyRange = (privacyPolicy as NSString).range(of: privacyPolicy)
  81. let termsServiceRange = (termsService as NSString).range(of: termsService)
  82. attributedString1.addAttributes([
  83. .font: NSFont.systemFont(ofSize: 12),
  84. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  85. .underlineStyle: NSUnderlineStyle.single.rawValue,
  86. .link: NSURL(string: "https://www.pdfreaderpro.com/privacy-policy")!
  87. ], range: privacyPolicyRange)
  88. attributedString2.addAttributes([
  89. .font: NSFont.systemFont(ofSize: 12),
  90. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  91. .underlineStyle: NSUnderlineStyle.single.rawValue,
  92. .link: NSURL(string:"https://www.pdfreaderpro.com/terms_of_service")!
  93. ], range: termsServiceRange)
  94. privacyPolicyLabel.attributedStringValue = attributedString1
  95. termsServiceLabel.attributedStringValue = attributedString2
  96. aitoolsBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  97. guard let self = self else { return }
  98. }
  99. aitoolsBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  100. guard let self = self else { return }
  101. #if VERSION_FREE
  102. #if VERSION_DMG
  103. // DMG
  104. #if VERSION_DMG
  105. self.close()
  106. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(KMAISubscriptionYearTrailCodeKey_DMG)
  107. embeddedWC.showWindow(nil)
  108. embeddedWC.window?.center()
  109. #endif
  110. #else
  111. self.window?.showWaitingView()
  112. // AppStore 免费版本
  113. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
  114. #endif
  115. #else
  116. // AppStore 付费版
  117. self.window?.showWaitingView()
  118. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: IAPProductsManager.default().isCancelAutoRenew())
  119. #endif
  120. }
  121. }
  122. private func initializeUI() -> Void {
  123. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  124. if isDarkModel {
  125. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
  126. } else {
  127. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
  128. }
  129. titleLabel1.textColor = NSColor(named: "1D2023")
  130. titleLabel1.font = NSFont.SFProTextSemiboldFont(24)
  131. subTitle1.textColor = NSColor(named: "101828")
  132. subTitle1.font = NSFont.SFProTextRegularFont(14)
  133. subTitle2.textColor = NSColor(named: "101828")
  134. subTitle2.font = NSFont.SFProTextRegularFont(14)
  135. subTitle3.textColor = NSColor(named: "F04438")
  136. subTitle3.font = NSFont.SFProTextRegularFont(14)
  137. aitoolsBox.fillColor = NSColor(named: "273C62") ?? .blue
  138. aitoolsLabel.textColor = NSColor(named: "FFFFFF")
  139. aitoolsLabel.font = NSFont.SFProTextRegularFont(13)
  140. laterButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.white, font: NSFont.SFProTextRegularFont(12))
  141. }
  142. // MARK: Action
  143. @IBAction func laterButtonAction(_ sender: NSButton) {
  144. window?.close()
  145. }
  146. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  147. self.window?.hideWaitingView()
  148. }
  149. }