// // KMUpgradeWindowController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/7/23. // import Cocoa class KMUpgradeWindowController: NSWindowController { @IBOutlet var contendBox: NSBox! @IBOutlet var titleLabel: NSTextField! @IBOutlet var enterlicenseBtn: HyperLinkButton! @IBOutlet var infoContendBox: NSBox! @IBOutlet var infoDescriptionBox: NSBox! @IBOutlet var infoSepLineView: NSView! @IBOutlet var advancedLabel: NSTextField! @IBOutlet var advancedSubLabel1: NSTextField! @IBOutlet var advancedSubLabel2: NSTextField! @IBOutlet var advancedSubLabel3: NSTextField! @IBOutlet var advancedSubLabel4: NSTextField! @IBOutlet var advancedSubLabel5: NSTextField! @IBOutlet var advancedSubLabel6: NSTextField! @IBOutlet var advancedSubLabel7: NSTextField! @IBOutlet var businessLabel: NSTextField! @IBOutlet var businessSubLabel1: NSTextField! @IBOutlet var businessSubLabel2: NSTextField! @IBOutlet var businessSubLabel3: NSTextField! @IBOutlet var businessSubLabel4: NSTextField! @IBOutlet var businessSubLabel5: NSTextField! @IBOutlet var businessSubLabel6: NSTextField! @IBOutlet var totalPriceLabel: NSTextField! @IBOutlet var licenseAmoutLabel: NSTextField! @IBOutlet var discountLabel: NSTextField! @IBOutlet var buynowBox: NSBox! @IBOutlet var buynowBtn: KMButton! var gradientView: UpgradeGradientView? convenience init() { self.init(windowNibName: "KMUpgradeWindowController") } deinit { DistributedNotificationCenter.default().removeObserver(self) } override func windowDidLoad() { super.windowDidLoad() // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. self.initViewInfo() self.refreshViewColor() self.reloadData() DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil) } func initViewInfo() { self.contendBox.borderWidth = 0 self.titleLabel.font = NSFont.UbuntuBoldFontWithSize(36) self.enterlicenseBtn.font = NSFont.SFProTextRegularFont(14) self.advancedLabel.font = NSFont.UbuntuBoldFontWithSize(20) self.advancedSubLabel1.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel2.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel3.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel4.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel5.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel6.font = NSFont.UbuntuRegularFontWithSize(14) self.advancedSubLabel7.font = NSFont.UbuntuRegularFontWithSize(14) self.businessLabel.font = NSFont.UbuntuBoldFontWithSize(20) self.businessSubLabel1.font = NSFont.UbuntuMediumFontWithSize(14) self.businessSubLabel2.font = NSFont.UbuntuMediumFontWithSize(14) self.businessSubLabel3.font = NSFont.UbuntuMediumFontWithSize(14) self.businessSubLabel4.font = NSFont.UbuntuMediumFontWithSize(14) self.businessSubLabel5.font = NSFont.UbuntuMediumFontWithSize(14) self.businessSubLabel6.font = NSFont.UbuntuMediumFontWithSize(14) self.totalPriceLabel.font = NSFont.UbuntuBoldFontWithSize(28) self.buynowBtn.font = NSFont.UbuntuMediumFontWithSize(16) self.licenseAmoutLabel.font = NSFont.UbuntuRegularFontWithSize(12) self.discountLabel.font = NSFont.UbuntuMediumFontWithSize(12) self.infoContendBox.borderWidth = 0 self.infoContendBox.cornerRadius = 4 self.infoContendBox.wantsLayer = true self.infoContendBox.layer?.cornerRadius = 4 // self.infoContendBox.clipsToBounds = true self.infoContendBox.layer?.masksToBounds = true self.infoDescriptionBox.borderWidth = 0 self.titleLabel.stringValue = NSLocalizedString("Upgrade to Permanent Version", comment: "") self.enterlicenseBtn.title = NSLocalizedString("Enter License", comment: "") self.advancedLabel.stringValue = NSLocalizedString("Advanced Features", comment: "") self.advancedSubLabel1.stringValue = NSLocalizedString("Create, sign, and manage document", comment: "") self.advancedSubLabel2.stringValue = NSLocalizedString("Edit PDF text, image and pages", comment: "") self.advancedSubLabel3.stringValue = NSLocalizedString("Collaborative review and annotate PDFs", comment: "") self.advancedSubLabel4.stringValue = NSLocalizedString("Secure and redact to protect privacy data", comment: "") self.advancedSubLabel5.stringValue = NSLocalizedString("Digital & electronic signatures", comment: "") self.advancedSubLabel6.stringValue = NSLocalizedString("Create Custom Stamp", comment: "") self.advancedSubLabel7.stringValue = NSLocalizedString("Create & fill forms", comment: "") self.businessLabel.stringValue = NSLocalizedString("Business Service Rights", comment: "") self.businessSubLabel1.stringValue = NSLocalizedString("Manage licenses with Admin Console", comment: "") self.businessSubLabel2.stringValue = NSLocalizedString("Optional deployment method", comment: "") self.businessSubLabel3.stringValue = NSLocalizedString("Support on-premise deployment", comment: "") self.businessSubLabel4.stringValue = NSLocalizedString("Free update", comment: "") self.businessSubLabel5.stringValue = NSLocalizedString("Support SSO (Single Sign-on)", comment: "") self.businessSubLabel6.stringValue = NSLocalizedString("High-Standard data encryption", comment: "") self.buynowBtn.title = NSLocalizedString("Buy Now", comment: "") self.infoSepLineView.wantsLayer = true self.gradientView = UpgradeGradientView.init(frame: self.contendBox.bounds) self.gradientView?.autoresizingMask = [.width, .height] self.gradientView?.wantsLayer = true self.contendBox.contentView?.addSubview(self.gradientView!, positioned: .below, relativeTo: self.titleLabel) } func refreshViewColor() { self.infoContendBox.fillColor = NSColor(red: 36/255, green: 43/255, blue: 90/255, alpha: 1) self.infoDescriptionBox.fillColor = NSColor.white self.titleLabel.textColor = NSColor.white self.advancedLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.advancedSubLabel1.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel2.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel3.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel4.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel5.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel6.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.advancedSubLabel7.textColor = NSColor(red: 39/255, green: 60/255, blue: 98/255, alpha: 1) self.enterlicenseBtn.setTitleColor(NSColor.white) self.businessLabel.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel1.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel2.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel3.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel4.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel5.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.businessSubLabel6.textColor = NSColor(red: 0, green: 105/255, blue: 1, alpha: 1) self.totalPriceLabel.textColor = NSColor(red: 1, green: 214/255, blue: 102/255, alpha: 1) self.licenseAmoutLabel.textColor = NSColor(red: 160/255, green: 162/255, blue: 174/255, alpha: 1) self.discountLabel.textColor = NSColor.white self.infoSepLineView.layer?.backgroundColor = NSColor(red: 231/255, green: 231/255, blue: 231/255, alpha: 1).cgColor } func reloadData() { self.totalPriceLabel.isHidden = true self.licenseAmoutLabel.isHidden = true self.discountLabel.isHidden = true guard let licenseCount = KMAdsInfoManager.shareInstance.licenseCount else { return } self.totalPriceLabel.isHidden = false self.licenseAmoutLabel.isHidden = false self.discountLabel.isHidden = false self.totalPriceLabel.stringValue = licenseCount.totalPrice self.licenseAmoutLabel.stringValue = "(" + NSLocalizedString("Amount", comment: "") + licenseCount.amount + ")" self.discountLabel.stringValue = NSLocalizedString("Discounted", comment: "") + licenseCount.discount } //MARK: IBAction @IBAction func enterlicenseAction(_ sender: Any) { self.close() if (IAPProductsManager.default().isAvailableAllFunction()) { let vc = KMVerificationWindowController.verification(with:.info) vc?.callback = { [weak self] in } vc?.showWindow(nil) } else { let vc = KMVerificationWindowController.verification(with:.activate) vc?.callback = { [weak self] in } vc?.showWindow(nil) } } @IBAction func buyAction(_ sender: Any) { FMTrackEventManager.defaultManager.lynxTrackEvent(event: "OnbrdTop", withProperties: ["OnbrdTop_Tbr" : "OnbrdTop_Tbr_BuyNowExpire"]) #if VERSION_DMG let string = "https://www.pdfreaderpro.com/store/pdftecheditor?utm_source=app_dmg&utm_medium=dmg_puw_comparison" let url: URL = URL(string: string)! NSWorkspace.shared.open(url) #endif } @objc func themeChange() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { self.refreshViewColor() } } override func showWindow(_ sender: Any?) { super.showWindow(sender) self.window?.center() } } class UpgradeGradientView: NSView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) setupGradient() } private func setupGradient() { let gradientLayer = CAGradientLayer() gradientLayer.frame = self.bounds gradientLayer.colors = [NSColor(red: 55/255, green: 102/255, blue: 255/255, alpha: 1).cgColor, NSColor(red: 84/255, green: 62/255, blue: 213/255, alpha: 1).cgColor] // 设置渐变颜色 gradientLayer.startPoint = CGPoint(x: 0.0, y: 1.0) gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0) // 移除之前的渐变层(如果存在) if let existingLayer = self.layer?.sublayers?.first(where: { $0 is CAGradientLayer }) { existingLayer.removeFromSuperlayer() } self.wantsLayer = true self.layer?.addSublayer(gradientLayer) gradientLayer.frame = self.bounds // 确保渐变层的大小与视图一致 } override func viewDidMoveToSuperview() { super.viewDidMoveToSuperview() setupGradient() } override func layout() { super.layout() if let gradientLayer = self.layer?.sublayers?.first as? CAGradientLayer { gradientLayer.frame = self.bounds // 重新设置渐变层的大小 } } }