// // KMConvertCollectionViewHeader.swift // PDF Reader Pro // // Created by kdanmobile on 2023/11/1. // import Cocoa typealias convertCollectionViewHeaderClickedCallBack = () -> () class KMConvertCollectionViewHeader: KMBaseXibView{ @IBOutlet var layerColorView: NSView! @IBOutlet var indicateLabel: NSTextField! @IBOutlet var imageView: NSImageView! @IBOutlet var infoLabel: NSTextField! @IBOutlet var containerView: NSView! var convertHeaderClickedCallBack: convertCollectionViewHeaderClickedCallBack? deinit { NotificationCenter.default.removeObserver(self) } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) } override func awakeFromNib() { super.awakeFromNib() containerView.wantsLayer = true // 购买状态变化通知 self.layerColorView.wantsLayer = true self.layerColorView.layer?.masksToBounds = true self.layerColorView.layer?.cornerRadius = 12 self.layerColorView.layer?.backgroundColor = NSColor(red: 1.0, green: 94/255.0, blue: 44/255.0, alpha: 1.0).cgColor self.refreshData() NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"), object: nil) } override func setup() { indicateLabel.font = NSFont.boldSystemFont(ofSize: 14) indicateLabel.textColor = KMAppearance.Layout.h0Color() indicateLabel.stringValue = NSLocalizedString("Convert", comment: "") infoLabel.font = NSFont.boldSystemFont(ofSize: 11) infoLabel.textColor = NSColor.white infoLabel.stringValue = NSLocalizedString("Upgrade to Pro", comment: "") infoLabel.toolTip = NSLocalizedString("Upgrade to Pro", comment: "") } override func mouseUp(with event: NSEvent) { super.mouseUp(with: event) let point = event.locationInWindow let newPoint = convert(point, from: nil) if let data = self.containerView?.frame.contains(newPoint), data { if !KMMemberInfo.shared.isPermitConvert { self.convertHeaderClickedCallBack?() } } } func refreshData() { if KMMemberInfo.shared.isPermitConvert { containerView.isHidden = true } else { containerView.isHidden = false } } @objc func IAPProductPurchasedNotification(notification: Notification) { self.refreshData() } @objc func IAPProductRestoreFinishedNotification(notification: Notification) { self.refreshData() } }