KMTabbingHintWindowController.swift 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // KMTabbingHintWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2/28/24.
  6. //
  7. import Cocoa
  8. typealias homeClickedTabbingShowBlock = (_ continueOrNot: Bool) -> Void
  9. let KMTabbingHintShowFlag = "KMTabbingHintShowFlag"
  10. class KMTabbingHintWindowController: NSWindowController{
  11. @IBOutlet var hintLabel: NSTextField!
  12. @IBOutlet var newTabInWindowButton: NSButton!
  13. @IBOutlet var newWindowButton: NSButton!
  14. @IBOutlet var notShowAgainButton: NSButton!
  15. @IBOutlet var gapView: NSView!
  16. @IBOutlet var cancelButton: NSButton!
  17. @IBOutlet var doneButton: NSButton!
  18. @IBOutlet weak var lockIv: NSImageView!
  19. var selectCallBack: homeClickedTabbingShowBlock?
  20. convenience init() {
  21. self.init(windowNibName: "KMTabbingHintWindowController")
  22. }
  23. override func windowDidLoad() {
  24. super.windowDidLoad()
  25. localiedLanguage()
  26. configuViewsUI()
  27. #if VERSION_DMG
  28. NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChangeNotification), name: NSNotification.Name.deviceActivateStatusChange, object: nil)
  29. #else
  30. NotificationCenter.default.addObserver(self, selector: #selector(IAPResultReceived), name: NSNotification.Name.KMIAPSubscriptionLoaded, object: nil)
  31. NotificationCenter.default.addObserver(self, selector: #selector(IAPPurchaseSuccess), name: NSNotification.Name.KMIAPProductPurchased, object: nil)
  32. NotificationCenter.default.addObserver(self, selector: #selector(IAPRestoreFinish), name: NSNotification.Name.KMIAPProductRestoreFinished, object: nil)
  33. #endif
  34. }
  35. func localiedLanguage() {
  36. hintLabel.stringValue = String(format: "%@:", NSLocalizedString("Open a document in", comment: ""))
  37. newTabInWindowButton.title = NSLocalizedString("a new tab in the same window", comment: "")
  38. newWindowButton.title = NSLocalizedString("a new window", comment: "")
  39. notShowAgainButton.title = NSLocalizedString("No longer prompt", comment: "")
  40. cancelButton.title = NSLocalizedString("Cancel", comment: "")
  41. doneButton.title = NSLocalizedString("Done", comment: "")
  42. }
  43. func configuViewsUI() {
  44. hintLabel.font = NSFont.boldSystemFont(ofSize: 16)
  45. newTabInWindowButton.state = .off
  46. newWindowButton.state = .on
  47. notShowAgainButton.state = .off
  48. gapView.wantsLayer = true
  49. gapView.layer?.backgroundColor = NSColor(red: 218/255.0, green: 218/255.0, blue: 218/255.0, alpha: 1).cgColor
  50. window?.contentView?.wantsLayer = true
  51. var color = NSColor.white
  52. if #available(macOS 10.14, *) {
  53. if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
  54. appearanceName == .darkAqua {
  55. color = KMAppearance.viewBackgroundColor()
  56. }
  57. }
  58. color = NSColor(deviceRed: 74.0/255.0, green: 74.0/255.0, blue: 74.0/255.0, alpha: 1.0)
  59. if #available(macOS 10.14, *) {
  60. if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]),
  61. appearanceName == .darkAqua {
  62. color = NSColor(deviceRed: 1.0, green: 1.0, blue: 1.0, alpha: 0.7)
  63. }
  64. }
  65. hintLabel.textColor = color
  66. newTabInWindowButton?.setTitleColor(color)
  67. newWindowButton?.setTitleColor(color)
  68. notShowAgainButton?.setTitleColor(color)
  69. self.reloadData()
  70. }
  71. @IBAction func buttonClicked_NewTabInWindowButton(_ sender: NSButton) {
  72. if KMMemberInfo.shared.isMemberAllFunction == false {
  73. sender.state = NSControl.StateValue.off
  74. let winC = KMProductCompareWC.shared
  75. winC.kEventName = "Reading_MultiTab_BuyNow"
  76. KMMemberInfo.shared.advancedFunctionUsage()
  77. return
  78. }
  79. sender.state = NSControl.StateValue.on
  80. self.newWindowButton.state = .off
  81. }
  82. @IBAction func buttonClicked_NewWindow(_ sender: NSButton) {
  83. sender.state = NSControl.StateValue.on
  84. self.newTabInWindowButton.state = .off
  85. }
  86. @IBAction func buttonClicked_DonotHintAgain(_ sender: NSButton) {
  87. }
  88. @IBAction func buttonClicked_Cancel(_ sender: NSButton) {
  89. self.km_quick_endSheet()
  90. if let callback = self.selectCallBack {
  91. callback(false)
  92. }
  93. }
  94. @IBAction func buttonClicked_Done(_ sender: NSButton) {
  95. UserDefaults.standard.set(self.notShowAgainButton.state, forKey: KMTabbingHintShowFlag)
  96. UserDefaults.standard.synchronize()
  97. if let callback = self.selectCallBack {
  98. callback(true)
  99. }
  100. self.km_quick_endSheet()
  101. }
  102. func reloadData() {
  103. KMMainThreadExecute {
  104. self.lockIv.isHidden = KMMemberInfo.shared.isMemberAllFunction
  105. }
  106. }
  107. // MARK: - Noti Methods
  108. @objc func deviceActivateStatusChangeNotification(sender: Notification) {
  109. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  110. self.reloadData()
  111. }
  112. }
  113. @objc func IAPResultReceived(sender: Notification) {
  114. DispatchQueue.main.async {
  115. self.reloadData()
  116. }
  117. }
  118. @objc func IAPPurchaseSuccess(sender: Notification) {
  119. DispatchQueue.main.async {
  120. self.reloadData()
  121. }
  122. }
  123. @objc func IAPRestoreFinish(sender: Notification) {
  124. DispatchQueue.main.async {
  125. self.reloadData()
  126. }
  127. }
  128. }