KMPurchaseSuccessWindowController.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. class KMPurchaseSuccessWindowController: KMBaseWindowController {
  11. @IBOutlet weak var iconIv: NSImageView!
  12. @IBOutlet weak var titleLabel: NSTextField!
  13. @IBOutlet weak var imageView: NSImageView!
  14. @IBOutlet var textView: NSTextView!
  15. @IBOutlet weak var imageView2: NSImageView!
  16. @IBOutlet var textView2: NSTextView!
  17. convenience init() {
  18. self.init(windowNibName: "KMPurchaseSuccessWindowController")
  19. }
  20. static let shared = KMPurchaseSuccessWindowController()
  21. override func windowDidLoad() {
  22. super.windowDidLoad()
  23. iconIv.image = NSImage(named: "KMImageNamePurchaseSuccessIcon")
  24. titleLabel.stringValue = NSLocalizedString("Purchase Succeesfully", tableName: "MemberCenterLocalizable", comment: "")
  25. titleLabel.font = .SFProTextRegularFont(20)
  26. imageView.image = NSImage(named: "KMImageNamePurchaseImage")
  27. imageView2.image = NSImage(named: "KMImageNamePurchaseImage2")
  28. window?.titleVisibility = .hidden
  29. if KMAppearance.isDarkMode() {
  30. window?.backgroundColor = NSColor(hex: "#0E1114")
  31. titleLabel.textColor = NSColor(hex: "#4E7FDB")
  32. } else {
  33. window?.backgroundColor = .white
  34. titleLabel.textColor = NSColor(hex: "#002143")
  35. }
  36. textView.drawsBackground = false
  37. textView.backgroundColor = .clear
  38. textView.isEditable = false
  39. textView.isSelectable = true
  40. textView.textColor = NSColor.black
  41. textView.font = NSFont.SFProTextRegularFont(14)
  42. let tipsString = NSLocalizedString("Check your order information and benefit in Account Center.%@", tableName: "MemberCenterLocalizable", comment: "")
  43. let specialOffer = NSLocalizedString("Check Now", tableName: "MemberCenterLocalizable", comment: "")
  44. let fullString = String(format: tipsString, specialOffer)
  45. let paragraphStyle = NSMutableParagraphStyle()
  46. // paragraphStyle.alignment = .center
  47. let attributedString = NSMutableAttributedString(string: fullString)
  48. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  49. let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  50. let font = NSFont.SFProTextRegularFont(14)
  51. attributedString.addAttributes([
  52. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  53. .font: font,
  54. .paragraphStyle: paragraphStyle
  55. ], range: (fullString as NSString).range(of: fullString))
  56. attributedString.addAttributes([
  57. .foregroundColor: linkColor,
  58. .link: "action://checkNow",
  59. .font: font
  60. ], range: specialOfferRange)
  61. textView.textStorage?.setAttributedString(attributedString)
  62. textView.delegate = self
  63. textView2.drawsBackground = false
  64. textView2.backgroundColor = .clear
  65. textView2.isEditable = false
  66. textView2.isSelectable = true
  67. textView2.textColor = NSColor.black
  68. textView2.font = NSFont.SFProTextRegularFont(14)
  69. let tipsString2 = NSLocalizedString("If you have purchased multiple PDF Reader Pro Permanent in volume, check them in Account Center -> Transfer Benefits. %@", tableName: "MemberCenterLocalizable", comment: "")
  70. let specialOffer2 = NSLocalizedString("Check Benefit", tableName: "MemberCenterLocalizable", comment: "")
  71. let fullString2 = String(format: tipsString2, specialOffer2)
  72. let paragraphStyle2 = NSMutableParagraphStyle()
  73. // paragraphStyle.alignment = .center
  74. let attributedString2 = NSMutableAttributedString(string: fullString2)
  75. let specialOfferRange2 = (fullString2 as NSString).range(of: specialOffer2)
  76. // let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  77. // let font = NSFont.SFProTextRegularFont(12)
  78. attributedString2.addAttributes([
  79. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  80. .font: font,
  81. .paragraphStyle: paragraphStyle2
  82. ], range: (fullString2 as NSString).range(of: fullString2))
  83. attributedString2.addAttributes([
  84. .foregroundColor: linkColor,
  85. .link: "action://checkBenefit",
  86. .font: font
  87. ], range: specialOfferRange2)
  88. textView2.textStorage?.setAttributedString(attributedString2)
  89. textView2.delegate = self
  90. }
  91. }
  92. extension KMPurchaseSuccessWindowController: NSTextViewDelegate {
  93. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  94. if let urlString = link as? String, urlString == "action://checkNow" {
  95. KMTools.openURL(urlString: kUserCenterURL)
  96. return true
  97. } else if let urlString = link as? String, urlString == "action://checkBenefit" {
  98. KMTools.openURL(urlString: kUserCenterGiftURL)
  99. return true
  100. }
  101. return false
  102. }
  103. }