KMFreeGetAIWC.swift 7.2 KB

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