KMPurchaseSuccessWindowController.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // KMPurchaseSuccessWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by User-Tangchao on 2024/11/18.
  6. //
  7. import Cocoa
  8. let kUserCenterURL = "https://www.pdfreaderpro.com/user-center/account-benefits";
  9. let kUserCenterGiftURL = "https://www.pdfreaderpro.com/gift-management";
  10. typealias successCloseBlock = (_ close: Bool) -> Void
  11. class KMPurchaseSuccessWindowController: KMBaseWindowController, NSWindowDelegate {
  12. @IBOutlet weak var iconIv: NSImageView!
  13. @IBOutlet weak var titleLabel: NSTextField!
  14. @IBOutlet weak var imageView: NSImageView!
  15. @IBOutlet var textView: NSTextView!
  16. @IBOutlet weak var imageView2: NSImageView!
  17. @IBOutlet var textView2: NSTextView!
  18. var closeCallback: ((_ isClose: Bool)->Void)?
  19. convenience init() {
  20. self.init(windowNibName: "KMPurchaseSuccessWindowController")
  21. }
  22. static let shared = KMPurchaseSuccessWindowController()
  23. override func windowDidLoad() {
  24. super.windowDidLoad()
  25. self.window?.delegate = self
  26. iconIv.image = NSImage(named: "KMImageNamePurchaseSuccessIcon")
  27. titleLabel.stringValue = NSLocalizedString("Purchase Succeesfully", tableName: "MemberCenterLocalizable", comment: "")
  28. titleLabel.font = .SFProTextRegularFont(20)
  29. imageView.image = NSImage(named: "KMImageNamePurchaseImage")
  30. imageView2.image = NSImage(named: "KMImageNamePurchaseImage2")
  31. window?.titleVisibility = .hidden
  32. if KMAppearance.isDarkMode() {
  33. window?.backgroundColor = NSColor(hex: "#0E1114")
  34. titleLabel.textColor = NSColor(hex: "#4E7FDB")
  35. } else {
  36. window?.backgroundColor = .white
  37. titleLabel.textColor = NSColor(hex: "#002143")
  38. }
  39. textView.drawsBackground = false
  40. textView.backgroundColor = .clear
  41. textView.enclosingScrollView?.backgroundColor = .clear
  42. textView.enclosingScrollView?.hasVerticalScroller = false
  43. textView.enclosingScrollView?.hasHorizontalScroller = false
  44. textView.isEditable = false
  45. textView.isSelectable = true
  46. textView.textColor = NSColor.black
  47. textView.font = NSFont.SFProTextRegularFont(14)
  48. let tipsString = NSLocalizedString("Check your order information and benefit in Account Center. %@", tableName: "MemberCenterLocalizable", comment: "")
  49. let specialOffer = NSLocalizedString("Check Now", tableName: "MemberCenterLocalizable", comment: "")
  50. let fullString = String(format: tipsString, specialOffer)
  51. let paragraphStyle = NSMutableParagraphStyle()
  52. // paragraphStyle.alignment = .center
  53. let attributedString = NSMutableAttributedString(string: fullString)
  54. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  55. let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  56. let font = NSFont.SFProTextRegularFont(14)
  57. attributedString.addAttributes([
  58. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  59. .font: font,
  60. .paragraphStyle: paragraphStyle
  61. ], range: (fullString as NSString).range(of: fullString))
  62. attributedString.addAttributes([
  63. .foregroundColor: linkColor,
  64. .link: "action://checkNow",
  65. .font: font
  66. ], range: specialOfferRange)
  67. textView.textStorage?.setAttributedString(attributedString)
  68. textView.delegate = self
  69. textView2.drawsBackground = false
  70. textView2.backgroundColor = .clear
  71. textView2.enclosingScrollView?.backgroundColor = .clear
  72. textView2.enclosingScrollView?.hasVerticalScroller = false
  73. textView2.enclosingScrollView?.hasHorizontalScroller = false
  74. textView2.isEditable = false
  75. textView2.isSelectable = true
  76. textView2.textColor = NSColor.black
  77. textView2.font = NSFont.SFProTextRegularFont(14)
  78. let tipsString2 = NSLocalizedString("If you have purchased multiple PDF Reader Pro Permanent in volume, check them in Account Center -> Transfer Benefits. %@", tableName: "MemberCenterLocalizable", comment: "")
  79. let specialOffer2 = NSLocalizedString("Check Benefit", tableName: "MemberCenterLocalizable", comment: "")
  80. let fullString2 = String(format: tipsString2, specialOffer2)
  81. let paragraphStyle2 = NSMutableParagraphStyle()
  82. // paragraphStyle.alignment = .center
  83. let attributedString2 = NSMutableAttributedString(string: fullString2)
  84. let specialOfferRange2 = (fullString2 as NSString).range(of: specialOffer2)
  85. // let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  86. // let font = NSFont.SFProTextRegularFont(12)
  87. attributedString2.addAttributes([
  88. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  89. .font: font,
  90. .paragraphStyle: paragraphStyle2
  91. ], range: (fullString2 as NSString).range(of: fullString2))
  92. attributedString2.addAttributes([
  93. .foregroundColor: linkColor,
  94. .link: "action://checkBenefit",
  95. .font: font
  96. ], range: specialOfferRange2)
  97. textView2.textStorage?.setAttributedString(attributedString2)
  98. textView2.delegate = self
  99. }
  100. func windowWillClose(_ notification: Notification) {
  101. if let data = self.window?.isEqual(to: notification.object), data {
  102. self.closeCallback?(true)
  103. }
  104. }
  105. }
  106. extension KMPurchaseSuccessWindowController: NSTextViewDelegate {
  107. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  108. if let urlString = link as? String, urlString == "action://checkNow" {
  109. KMTools.openURL(urlString: kUserCenterURL)
  110. return true
  111. } else if let urlString = link as? String, urlString == "action://checkBenefit" {
  112. KMTools.openURL(urlString: kUserCenterGiftURL)
  113. return true
  114. }
  115. return false
  116. }
  117. }