KMFreeGetAIWC.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. let privacyPolicy = NSLocalizedString("Privacy Policy", tableName: "MemberCenterLocalizable", comment: "")
  48. let termsService = NSLocalizedString("Terms of Service", tableName: "MemberCenterLocalizable", comment: "")
  49. let attributedString1 = NSMutableAttributedString(string: privacyPolicy)
  50. let attributedString2 = NSMutableAttributedString(string: termsService)
  51. let privacyPolicyRange = (privacyPolicy as NSString).range(of: privacyPolicy)
  52. let termsServiceRange = (termsService as NSString).range(of: termsService)
  53. attributedString1.addAttributes([
  54. .font: NSFont.systemFont(ofSize: 12),
  55. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  56. .underlineStyle: NSUnderlineStyle.single.rawValue,
  57. .link: NSURL(string: NSLocalizedString("https://www.pdfreaderpro.com/privacy-policy", comment: ""))!
  58. ], range: privacyPolicyRange)
  59. attributedString2.addAttributes([
  60. .font: NSFont.systemFont(ofSize: 12),
  61. .foregroundColor: NSColor(named: "273C62") ?? .blue,
  62. .underlineStyle: NSUnderlineStyle.single.rawValue,
  63. .link: NSURL(string: NSLocalizedString("https://www.pdfreaderpro.com/terms_of_service", comment: ""))!
  64. ], range: termsServiceRange)
  65. privacyPolicyLabel.attributedStringValue = attributedString1
  66. termsServiceLabel.attributedStringValue = attributedString2
  67. aitoolsBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  68. guard let self = self else { return }
  69. }
  70. aitoolsBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  71. guard let self = self else { return }
  72. #if VERSION_FREE
  73. #if VERSION_DMG
  74. // DMG
  75. #else
  76. // AppStore 免费版本
  77. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
  78. #endif
  79. #else
  80. // AppStore 付费版
  81. #endif
  82. }
  83. }
  84. private func initializeUI() -> Void {
  85. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  86. if isDarkModel {
  87. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
  88. } else {
  89. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
  90. }
  91. titleLabel1.textColor = NSColor(named: "1D2023")
  92. titleLabel1.font = NSFont.SFProTextSemiboldFont(24)
  93. subTitle1.textColor = NSColor(named: "101828")
  94. subTitle1.font = NSFont.SFProTextRegularFont(14)
  95. subTitle2.textColor = NSColor(named: "101828")
  96. subTitle2.font = NSFont.SFProTextRegularFont(14)
  97. subTitle3.textColor = NSColor(named: "F04438")
  98. subTitle3.font = NSFont.SFProTextRegularFont(14)
  99. aitoolsBox.fillColor = NSColor(named: "273C62") ?? .blue
  100. aitoolsLabel.textColor = NSColor(named: "FFFFFF")
  101. aitoolsLabel.font = NSFont.SFProTextRegularFont(13)
  102. laterButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.white, font: NSFont.SFProTextRegularFont(12))
  103. }
  104. // MARK: Action
  105. @IBAction func laterButtonAction(_ sender: NSButton) {
  106. window?.close()
  107. }
  108. }