// // AIHeaderView.swift // PDF Reader Pro Edition // // Created by Niehaoyu on 2024/4/17. // import Cocoa class AIHeaderView: NSView, NibLoadable { @IBOutlet weak var contendView: NSView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var seplineView: NSView! @IBOutlet weak var myCreditLabel: NSTextField! var guideWindowVC: KMFunctionGuideWindowController! override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func awakeFromNib() { super.awakeFromNib() self.titleLabel.font = NSFont.SFProTextSemiboldFont(14) self.myCreditLabel.font = NSFont.SFProTextSemiboldFont(11) self.titleLabel.stringValue = NSLocalizedString("AI Tools", comment: "") self.myCreditLabel.stringValue = NSLocalizedString("My AI Credit", comment: "") self.seplineView.wantsLayer = true self.refreshViewColor() } func refreshViewColor() { if KMAppearance.isDarkMode() { self.titleLabel.textColor = KMAppearance.KMColor_Layout_W0() self.myCreditLabel.textColor = NSColor.white self.seplineView.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.1).cgColor } else { self.titleLabel.textColor = KMAppearance.KMColor_Layout_M() self.myCreditLabel.textColor = NSColor.white self.seplineView.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.05).cgColor } } //MARK: IBAction @IBAction func creditInfoAction(_ sender: NSButton) { AIInfoManager.default().fetchAIInfo { dict, error in } let controller = AIUserInfoController.init() controller.purchaseHandle = { vc in #if VERSION_DMG let url = URL(string: kAIStoreServerLink) NSWorkspace.shared.open(url!) #else AIPurchaseWindowController.currentWC().showWindow(nil) #endif } controller.enterLicenseHandle = { vc in let verifyVC = KMVerificationWindowController.verification(with: .activateAIInfo) verifyVC?.callback = { KMPurchaseCompareWindowController.sharedInstance().showWindow(nil) } verifyVC?.showWindow(nil) } controller.guideHandle = {[weak self] vc in if self?.guideWindowVC == nil { let guideWindowVC = KMFunctionGuideWindowController.init(windowNibName: "KMFunctionGuideWindowController") self?.guideWindowVC = guideWindowVC } self?.guideWindowVC.type = .functionMulti self?.guideWindowVC.showWindow(nil) KMFunctionGuideWindowController.setDidShowFor(.functionMultiAIGuide) self?.guideWindowVC.window?.orderFront(nil) } let popover = NSPopover.init() popover.contentViewController = controller popover.behavior = .transient popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: .minY) } }