KMUserFeekbackHanddler.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // KMUserFeekbackHanddler.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/7/17.
  6. //
  7. import Cocoa
  8. class KMUserFeekbackHanddler: NSObject {
  9. private weak var popover_: NSPopover?
  10. func showUserFbPopView(sender: NSView) {
  11. if let _ = self.popover_ {
  12. return
  13. }
  14. let datas = [NSLocalizedString("Report a Bug", comment: ""), NSLocalizedString("Propose a New Feature", comment: ""), "KMHorizontalLine", NSLocalizedString("Quick Start Guide", comment: "")]
  15. let vc = KMHomePopViewController(nibName: "KMHomePopViewController", bundle: nil)
  16. _ = vc.initWithPopViewDataArr(datas)
  17. vc.background = KMAppearance.Layout.bgColor()
  18. vc.textColor = KMAppearance.Layout.h0Color()
  19. vc.enterFillColor = KMAppearance.Interactive.s0Color()
  20. vc.downCallback = { [weak self] result, data in
  21. self?.popover_?.close()
  22. if data == NSLocalizedString("Report a Bug", comment: "") {
  23. self?.showFeekbackWindow(with: data)
  24. } else if data == NSLocalizedString("Propose a New Feature", comment: "") {
  25. self?.showFeekbackWindow(with: data)
  26. } else if data == NSLocalizedString("Quick Start Guide", comment: "") {
  27. KMTools.openQuickStartStudy()
  28. }
  29. }
  30. let popover = NSPopover()
  31. popover.contentViewController = vc
  32. popover.animates = true
  33. popover.behavior = .semitransient
  34. popover.setValue(true, forKey: "shouldHideAnchor")
  35. popover.delegate = self
  36. //
  37. // CGRect sourcesRect = sender.bounds;
  38. // sourcesRect = [sender convertRect:sourcesRect toView:nil];
  39. // sourcesRect.origin.y-= 20;
  40. // sourcesRect.size.height+=20;
  41. // self.mainWindowC.window.popover = popover;
  42. // self.mainWindowC.window.sourcesRect = sourcesRect;
  43. popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: .maxX)
  44. self.popover_ = popover
  45. }
  46. func showFeekbackWindow(with type: String) {
  47. let winC = KMUserFeekbackWindowController.shared
  48. winC.typeString = type
  49. winC.showWindow(nil)
  50. }
  51. }
  52. extension KMUserFeekbackHanddler: NSPopoverDelegate {
  53. func popoverWillClose(_ notification: Notification) {
  54. if let data = self.popover_?.isEqual(to: notification.object), data {
  55. self.popover_ = nil
  56. }
  57. }
  58. }