// // KMPurchaseSuccessWindowController.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/11/18. // import Cocoa let kUserCenterURL = "https://www.pdfreaderpro.com/user-center/account-benefits"; let kUserCenterGiftURL = "https://www.pdfreaderpro.com/gift-management"; class KMPurchaseSuccessWindowController: KMBaseWindowController { @IBOutlet weak var iconIv: NSImageView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var imageView: NSImageView! @IBOutlet var textView: NSTextView! @IBOutlet weak var imageView2: NSImageView! @IBOutlet var textView2: NSTextView! convenience init() { self.init(windowNibName: "KMPurchaseSuccessWindowController") } static let shared = KMPurchaseSuccessWindowController() override func windowDidLoad() { super.windowDidLoad() iconIv.image = NSImage(named: "KMImageNamePurchaseSuccessIcon") titleLabel.stringValue = NSLocalizedString("Purchase Succeesfully", tableName: "MemberCenterLocalizable", comment: "") titleLabel.font = .SFProTextRegularFont(20) imageView.image = NSImage(named: "KMImageNamePurchaseImage") imageView2.image = NSImage(named: "KMImageNamePurchaseImage2") window?.titleVisibility = .hidden if KMAppearance.isDarkMode() { window?.backgroundColor = NSColor(hex: "#0E1114") titleLabel.textColor = NSColor(hex: "#4E7FDB") } else { window?.backgroundColor = .white titleLabel.textColor = NSColor(hex: "#002143") } textView.drawsBackground = false textView.backgroundColor = .clear textView.isEditable = false textView.isSelectable = true textView.textColor = NSColor.black textView.font = NSFont.SFProTextRegularFont(14) let tipsString = NSLocalizedString("Check your order information and benefit in Account Center.%@", tableName: "MemberCenterLocalizable", comment: "") let specialOffer = NSLocalizedString("Check Now", tableName: "MemberCenterLocalizable", comment: "") let fullString = String(format: tipsString, specialOffer) let paragraphStyle = NSMutableParagraphStyle() // paragraphStyle.alignment = .center let attributedString = NSMutableAttributedString(string: fullString) let specialOfferRange = (fullString as NSString).range(of: specialOffer) let linkColor = NSColor(named: "4982E6") ?? NSColor.blue let font = NSFont.SFProTextRegularFont(14) attributedString.addAttributes([ .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any, .font: font, .paragraphStyle: paragraphStyle ], range: (fullString as NSString).range(of: fullString)) attributedString.addAttributes([ .foregroundColor: linkColor, .link: "action://checkNow", .font: font ], range: specialOfferRange) textView.textStorage?.setAttributedString(attributedString) textView.delegate = self textView2.drawsBackground = false textView2.backgroundColor = .clear textView2.isEditable = false textView2.isSelectable = true textView2.textColor = NSColor.black textView2.font = NSFont.SFProTextRegularFont(14) let tipsString2 = NSLocalizedString("If you have purchased multiple PDF Reader Pro Permanent in volume, check them in Account Center -> Transfer Benefits. %@", tableName: "MemberCenterLocalizable", comment: "") let specialOffer2 = NSLocalizedString("Check Benefit", tableName: "MemberCenterLocalizable", comment: "") let fullString2 = String(format: tipsString2, specialOffer2) let paragraphStyle2 = NSMutableParagraphStyle() // paragraphStyle.alignment = .center let attributedString2 = NSMutableAttributedString(string: fullString2) let specialOfferRange2 = (fullString2 as NSString).range(of: specialOffer2) // let linkColor = NSColor(named: "4982E6") ?? NSColor.blue // let font = NSFont.SFProTextRegularFont(12) attributedString2.addAttributes([ .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any, .font: font, .paragraphStyle: paragraphStyle2 ], range: (fullString2 as NSString).range(of: fullString2)) attributedString2.addAttributes([ .foregroundColor: linkColor, .link: "action://checkBenefit", .font: font ], range: specialOfferRange2) textView2.textStorage?.setAttributedString(attributedString2) textView2.delegate = self } } extension KMPurchaseSuccessWindowController: NSTextViewDelegate { func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool { if let urlString = link as? String, urlString == "action://checkNow" { KMTools.openURL(urlString: kUserCenterURL) return true } else if let urlString = link as? String, urlString == "action://checkBenefit" { KMTools.openURL(urlString: kUserCenterGiftURL) return true } return false } }