KMFreeGetAIWC.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. subTitle3.isHidden = true
  30. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  31. }
  32. @objc func themeChanged(_ notification: Notification) {
  33. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  34. self.initializeUI()
  35. }
  36. }
  37. // MARK: Private Method
  38. private func languageLocalized() -> Void {
  39. titleLabel1.stringValue = NSLocalizedString("Successfully subscribe PDF Reader Pro Advanced - Annual Plan!", tableName: "MemberCenterLocalizable", comment: "")
  40. subTitle1.stringValue = String(format: " · %@", NSLocalizedString("You get the chance to use AI Tools free for a year on the desktop version", tableName: "MemberCenterLocalizable", comment: ""))
  41. 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: ""))
  42. subTitle3.stringValue = String(format: " · %@", NSLocalizedString("Pick up free AI Tools before 23:59:00, or it will be invalid", tableName: "MemberCenterLocalizable", comment: ""))
  43. aitoolsLabel.stringValue = NSLocalizedString("Get 1-Year AI Tools with $0", tableName: "MemberCenterLocalizable", comment: "")
  44. laterButton.title = NSLocalizedString("Later", tableName: "MemberCenterLocalizable", comment: "")
  45. privacyPolicyLabel.isEditable = false
  46. privacyPolicyLabel.isSelectable = true
  47. privacyPolicyLabel.allowsEditingTextAttributes = true
  48. termsServiceLabel.isEditable = false
  49. termsServiceLabel.isSelectable = true
  50. termsServiceLabel.allowsEditingTextAttributes = true
  51. NotificationCenter.default.addObserver(
  52. self,
  53. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  54. name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
  55. object: nil
  56. )
  57. NotificationCenter.default.addObserver(
  58. self,
  59. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  60. name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
  61. object: nil
  62. )
  63. let privacyPolicy = NSLocalizedString("Privacy Policy", tableName: "MemberCenterLocalizable", comment: "")
  64. let termsService = NSLocalizedString("Terms of Service", tableName: "MemberCenterLocalizable", comment: "")
  65. let attributedString1 = NSMutableAttributedString(string: privacyPolicy)
  66. let attributedString2 = NSMutableAttributedString(string: termsService)
  67. let privacyPolicyRange = (privacyPolicy as NSString).range(of: privacyPolicy)
  68. let termsServiceRange = (termsService as NSString).range(of: termsService)
  69. attributedString1.addAttributes([
  70. .font: NSFont.systemFont(ofSize: 12),
  71. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  72. .underlineStyle: NSUnderlineStyle.single.rawValue,
  73. .link: NSURL(string: "https://www.pdfreaderpro.com/privacy-policy")!
  74. ], range: privacyPolicyRange)
  75. attributedString2.addAttributes([
  76. .font: NSFont.systemFont(ofSize: 12),
  77. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  78. .underlineStyle: NSUnderlineStyle.single.rawValue,
  79. .link: NSURL(string:"https://www.pdfreaderpro.com/terms_of_service")!
  80. ], range: termsServiceRange)
  81. privacyPolicyLabel.attributedStringValue = attributedString1
  82. termsServiceLabel.attributedStringValue = attributedString2
  83. aitoolsBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  84. guard let self = self else { return }
  85. }
  86. aitoolsBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  87. guard let self = self else { return }
  88. #if VERSION_FREE
  89. #if VERSION_DMG
  90. // DMG
  91. #else
  92. self.window?.showWaitingView()
  93. // AppStore 免费版本
  94. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
  95. #endif
  96. #else
  97. // AppStore 付费版
  98. self.window?.showWaitingView()
  99. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: IAPProductsManager.default().isCancelAutoRenew())
  100. #endif
  101. }
  102. }
  103. private func initializeUI() -> Void {
  104. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  105. if isDarkModel {
  106. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
  107. } else {
  108. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
  109. }
  110. titleLabel1.textColor = NSColor(named: "1D2023")
  111. titleLabel1.font = NSFont.SFProTextSemiboldFont(24)
  112. subTitle1.textColor = NSColor(named: "101828")
  113. subTitle1.font = NSFont.SFProTextRegularFont(14)
  114. subTitle2.textColor = NSColor(named: "101828")
  115. subTitle2.font = NSFont.SFProTextRegularFont(14)
  116. subTitle3.textColor = NSColor(named: "F04438")
  117. subTitle3.font = NSFont.SFProTextRegularFont(14)
  118. aitoolsBox.fillColor = NSColor(named: "273C62") ?? .blue
  119. aitoolsLabel.textColor = NSColor(named: "FFFFFF")
  120. aitoolsLabel.font = NSFont.SFProTextRegularFont(13)
  121. laterButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.white, font: NSFont.SFProTextRegularFont(12))
  122. }
  123. // MARK: Action
  124. @IBAction func laterButtonAction(_ sender: NSButton) {
  125. window?.close()
  126. }
  127. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  128. self.window?.hideWaitingView()
  129. }
  130. }