KMAccountExceptionView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // KMAccountExceptionView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2023/9/4.
  6. //
  7. import Cocoa
  8. typealias KMAccountExceptionViewCancelAction = (_ view: KMAccountExceptionView) -> Void
  9. class KMAccountExceptionView: KMBaseXibView {
  10. @IBOutlet var textView: NSTextView!
  11. @IBOutlet weak var titleLabel: NSTextField!
  12. @IBOutlet weak var doneButton: NSButton!
  13. @IBOutlet weak var closeButton: NSButton!
  14. @IBOutlet weak var closeBox: KMBox!
  15. var cancelAction: KMAccountExceptionViewCancelAction?
  16. override func draw(_ dirtyRect: NSRect) {
  17. super.draw(dirtyRect)
  18. // Drawing code here.
  19. }
  20. override func setup() {
  21. self.closeBox.moveCallback = { [weak self] (mouseEntered, mouseBox) in
  22. if mouseEntered {
  23. self?.closeButton?.image = NSImage(named: "control_btn_icon_close_hov")
  24. } else {
  25. self?.closeButton?.image = NSImage(named: "control_btn_icon_close")
  26. }
  27. }
  28. self.textView.delegate = self
  29. self.textView.frame = (self.textView.enclosingScrollView?.contentView.bounds)!
  30. self.textView.autoresizingMask = [.width, .height]
  31. self.textView.font = NSFont.SFProTextRegularFont(14)
  32. self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
  33. self.titleLabel.font = NSFont.SFProTextSemiboldFont(20)
  34. self.doneButton.backgroundColor(NSColor.km_init(hex: "#1770F4"))
  35. self.doneButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
  36. self.doneButton.font = NSFont.SFProTextRegularFont(14)
  37. self.doneButton.border(NSColor.clear, 0, 4)
  38. }
  39. override func updateLanguage() {
  40. self.titleLabel.stringValue = NSLocalizedString("Account Blocked", comment: "")
  41. //singin
  42. let string = NSLocalizedString("Your account is currently blocked due to frequent switching, during which you can still use the free basics function normally.To unblock the account, please contact us and provide complaint instructions.", comment: "")
  43. let attributedString = NSMutableAttributedString.init(string: string)
  44. let paragraphStyle = NSMutableParagraphStyle()
  45. paragraphStyle.alignment = .center;
  46. paragraphStyle.lineHeightMultiple = 1.32
  47. paragraphStyle.lineBreakMode = .byWordWrapping
  48. attributedString.addAttributes([NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0),
  49. NSAttributedString.Key.foregroundColor : NSColor.km_init(hex: "#616469"),
  50. NSAttributedString.Key.paragraphStyle : paragraphStyle],
  51. range: NSRange(location: 0, length: string.count))
  52. let range = string.range(of: NSLocalizedString("contact us", comment: ""))
  53. attributedString.setAttributes([NSAttributedString.Key.font : NSFont.SFProTextRegularFont(14.0),
  54. NSAttributedString.Key.foregroundColor : NSColor.km_init(hex: "#1770F4"),
  55. NSAttributedString.Key.underlineColor : NSColor.clear,
  56. NSAttributedString.Key.link : "timer://"],
  57. range: string.nsRange(from: range!)!)
  58. self.textView.textStorage?.setAttributedString(attributedString)
  59. }
  60. @IBAction func doneAction(_ sender: Any) {
  61. guard let callBack = cancelAction else { return }
  62. callBack(self)
  63. }
  64. @IBAction func closeButtonAction(_ sender: Any) {
  65. guard let callBack = cancelAction else { return }
  66. callBack(self)
  67. }
  68. }
  69. extension KMAccountExceptionView: NSTextViewDelegate {
  70. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  71. if link as! String == "timer://" {
  72. // guard let callBack = reSendAction else { return true }
  73. // textView.isSelectable = false
  74. // callBack(self, textView)
  75. NSWorkspace.shared.open(URL(string: "https://www.pdfreaderpro.com/contact")!)
  76. }
  77. return true
  78. }
  79. }