AIHeaderView.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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", 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. let controller = AIUserInfoController.init()
  43. controller.purchaseHandle = { vc in
  44. #if VERSION_DMG
  45. let url = URL(string: kAIStoreServerLink)
  46. NSWorkspace.shared.open(url!)
  47. #else
  48. AIPurchaseWindowController.currentWC().showWindow(nil)
  49. #endif
  50. }
  51. controller.enterLicenseHandle = { vc in
  52. let verifyVC = KMVerificationWindowController.verification(with: .activateExpired)
  53. verifyVC?.callback = {
  54. KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
  55. }
  56. verifyVC?.showWindow(nil)
  57. }
  58. controller.guideHandle = {[unowned self] vc in
  59. if self.guideWindowVC == nil {
  60. let guideWindowVC = KMFunctionGuideWindowController.init(windowNibName: "KMFunctionGuideWindowController")
  61. self.guideWindowVC = guideWindowVC
  62. }
  63. self.guideWindowVC.type = .functionMulti
  64. self.guideWindowVC.showWindow(nil)
  65. KMFunctionGuideWindowController.setDidShowFor(.functionMultiAIGuide)
  66. self.guideWindowVC.window?.orderFront(nil)
  67. }
  68. let popover = NSPopover.init()
  69. popover.contentViewController = controller
  70. popover.behavior = .transient
  71. popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: .minY)
  72. }
  73. }