KMFreeGetAIWC.swift 6.9 KB

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