123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- // 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 Title", 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
-
- }
- if(KMMemberInfo.shared.isLogin == true) {
- KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
- if(success == true) {
- self?.enterAIInfo(sender)
- }
- }
- } else {
- enterAIInfo(sender)
- }
- }
-
- func enterAIInfo(_ sender: NSButton) {
-
- KMUserInfoVCModel().refreshUserInfo { success, msg ,res in
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: kDeviceAIStatusChangeNotification), object: nil)
- }
-
- let controller = AIUserInfoController.init()
- controller.purchaseHandle = { vc in
- #if VERSION_DMG
- // let url = URL(string: AIProduct_Link)
- // NSWorkspace.shared.open(url!)
- let embeddedWC = KMPurchaseEmbeddedWindowController.currentFirstTrialWC("com.brother.pdfreaderpro.ai.product_1")
- embeddedWC.showWindow(self)
- embeddedWC.window?.center()
- #else
- if KMMemberInfo.shared.aiPoint > 0 {
-
- } else {
- AIPurchaseWindowController.currentWC().showWindow(nil)
- }
- #endif
- }
-
- controller.enterLicenseHandle = { vc in
- let verifyVC = KMVerificationWindowController.verification(with: .activateAIInfo)
- verifyVC?.callback = {
- KMProductCompareWC.shared.orientation = false
- KMProductCompareWC.shared.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)
-
- }
- }
|