AIHeaderView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // AIHeaderView.swift
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2024/4/17.
  6. //
  7. import Cocoa
  8. class AIHeaderView: NSView, NibLoadable {
  9. @IBOutlet weak var contendView: NSView!
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var seplineView: NSView!
  12. @IBOutlet weak var myCreditLabel: NSTextField!
  13. var guideWindowVC: KMFunctionGuideWindowController!
  14. override func draw(_ dirtyRect: NSRect) {
  15. super.draw(dirtyRect)
  16. // Drawing code here.
  17. }
  18. override func awakeFromNib() {
  19. super.awakeFromNib()
  20. self.titleLabel.font = NSFont.SFProTextSemiboldFont(14)
  21. self.myCreditLabel.font = NSFont.SFProTextSemiboldFont(11)
  22. self.titleLabel.stringValue = NSLocalizedString("AI Tools Title", comment: "")
  23. self.myCreditLabel.stringValue = NSLocalizedString("My AI Credit", comment: "")
  24. self.seplineView.wantsLayer = true
  25. self.refreshViewColor()
  26. }
  27. func refreshViewColor() {
  28. if KMAppearance.isDarkMode() {
  29. self.titleLabel.textColor = KMAppearance.KMColor_Layout_W0()
  30. self.myCreditLabel.textColor = NSColor.white
  31. self.seplineView.layer?.backgroundColor = NSColor.white.withAlphaComponent(0.1).cgColor
  32. } else {
  33. self.titleLabel.textColor = KMAppearance.KMColor_Layout_M()
  34. self.myCreditLabel.textColor = NSColor.white
  35. self.seplineView.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.05).cgColor
  36. }
  37. }
  38. //MARK: IBAction
  39. @IBAction func creditInfoAction(_ sender: NSButton) {
  40. AIInfoManager.default().fetchAIInfo { dict, error in
  41. }
  42. if(KMMemberInfo.shared.isLogin == true) {
  43. KMUserInfoViewController.refreshTokenUserInfo {[weak self] success, resDic in
  44. if(success == true) {
  45. self?.enterAIInfo(sender)
  46. }
  47. }
  48. } else {
  49. enterAIInfo(sender)
  50. }
  51. }
  52. func enterAIInfo(_ sender: NSButton) {
  53. KMUserInfoVCModel().refreshUserInfo { success, msg ,res in
  54. NotificationCenter.default.post(name: NSNotification.Name(rawValue: kDeviceAIStatusChangeNotification), object: nil)
  55. }
  56. let controller = AIUserInfoController.init()
  57. controller.purchaseHandle = { vc in
  58. #if VERSION_DMG
  59. // let url = URL(string: AIProduct_Link)
  60. // NSWorkspace.shared.open(url!)
  61. let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(KMAISubscriptionMonthCodeKey_DMG)
  62. embeddedWC.showWindow(self)
  63. embeddedWC.window?.center()
  64. #else
  65. if KMMemberInfo.shared.aiPoint > 0 {
  66. } else {
  67. AIPurchaseWindowController.currentWC().showWindow(nil)
  68. }
  69. #endif
  70. }
  71. controller.enterLicenseHandle = { vc in
  72. let verifyVC = KMVerificationWindowController.verification(with: .activateAIInfo)
  73. verifyVC?.callback = {
  74. KMProductCompareWC.shared.orientation = false
  75. KMProductCompareWC.shared.showWindow(nil)
  76. }
  77. verifyVC?.showWindow(nil)
  78. }
  79. controller.guideHandle = {[weak self] vc in
  80. if self?.guideWindowVC == nil {
  81. let guideWindowVC = KMFunctionGuideWindowController.init(windowNibName: "KMFunctionGuideWindowController")
  82. self?.guideWindowVC = guideWindowVC
  83. }
  84. self?.guideWindowVC.type = .functionMulti
  85. self?.guideWindowVC.showWindow(nil)
  86. KMFunctionGuideWindowController.setDidShowFor(.functionMultiAIGuide)
  87. self?.guideWindowVC.window?.orderFront(nil)
  88. }
  89. let popover = NSPopover.init()
  90. popover.contentViewController = controller
  91. popover.behavior = .transient
  92. popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: .minY)
  93. }
  94. }