KMOpenDMGPopupBootWC.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // KMOpenDMGPopupBootWC.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/6.
  6. // 打开DMG时的弹窗引导
  7. //
  8. import Cocoa
  9. class KMOpenDMGPopupBootWC: NSWindowController {
  10. @IBOutlet weak var titleLabel: NSTextField!
  11. @IBOutlet weak var subTitleLabel: NSTextField!
  12. @IBOutlet weak var freeBox: KMBox!
  13. @IBOutlet weak var freeLabel: NSTextField!
  14. @IBOutlet weak var signInTextView: NSTextView!
  15. private var viewModel = KMOpenDMGPopBootModel()
  16. static let shared: KMOpenDMGPopupBootWC = {
  17. let windowC = KMOpenDMGPopupBootWC(windowNibName: "KMOpenDMGPopupBootWC")
  18. return windowC
  19. }()
  20. override func windowDidLoad() {
  21. super.windowDidLoad()
  22. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  23. languageLocalized()
  24. initializeUI()
  25. NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  26. }
  27. @objc func changeEffectiveAppearance() {
  28. self.initializeUI()
  29. }
  30. // MARK: Private Method
  31. private func languageLocalized() -> Void {
  32. titleLabel.stringValue = NSLocalizedString("Free to Get 7-Day VIP Now", tableName: "MemberCenterLocalizable", comment: "")
  33. subTitleLabel.stringValue = String(format: " · %@", NSLocalizedString("Use all functions without restrictions", tableName: "MemberCenterLocalizable", comment: ""))
  34. freeLabel.stringValue = NSLocalizedString("Get 7-Day VIP Free", tableName: "MemberCenterLocalizable", comment: "")
  35. }
  36. private func initializeUI() -> Void {
  37. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  38. if isDarkModel {
  39. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
  40. } else {
  41. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
  42. }
  43. titleLabel.textColor = NSColor(named: "4982E6")
  44. titleLabel.font = NSFont.SFProTextSemiboldFont(24)
  45. subTitleLabel.textColor = NSColor(named: "101828")
  46. subTitleLabel.font = NSFont.SFProTextRegularFont(14)
  47. freeBox.fillColor = NSColor(named: "273C62") ?? .blue
  48. freeLabel.textColor = NSColor(named: "FFFFFF")
  49. freeLabel.font = NSFont.SFProTextRegularFont(13)
  50. signInTextView.isEditable = false
  51. signInTextView.isSelectable = true
  52. signInTextView.textColor = NSColor.black
  53. signInTextView.font = NSFont.SFProTextRegularFont(12)
  54. let tipsString = NSLocalizedString("Already have an account? %@", tableName: "MemberCenterLocalizable", comment: "")
  55. let specialOffer = NSLocalizedString("Sign in", tableName: "MemberCenterLocalizable", comment: "")
  56. let fullString = String(format: tipsString, specialOffer)
  57. let paragraphStyle = NSMutableParagraphStyle()
  58. paragraphStyle.alignment = .center
  59. let attributedString = NSMutableAttributedString(string: fullString)
  60. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  61. let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  62. let font = NSFont.SFProTextRegularFont(12)
  63. attributedString.addAttributes([
  64. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  65. .font: font,
  66. .paragraphStyle: paragraphStyle
  67. ], range: (fullString as NSString).range(of: fullString))
  68. attributedString.addAttributes([
  69. .foregroundColor: linkColor,
  70. .link: "action://openDetail",
  71. .font: font
  72. ], range: specialOfferRange)
  73. signInTextView.textStorage?.setAttributedString(attributedString)
  74. signInTextView.delegate = self
  75. freeBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  76. guard let self = self else { return }
  77. }
  78. freeBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  79. guard let self = self else { return }
  80. if downEntered {
  81. viewModel.getVipFree()
  82. self.window?.close()
  83. }
  84. }
  85. }
  86. }
  87. extension KMOpenDMGPopupBootWC: NSTextViewDelegate {
  88. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  89. if let urlString = link as? String, urlString == "action://openDetail" {
  90. viewModel.signUpAction()
  91. self.window?.close()
  92. return true
  93. }
  94. return false
  95. }
  96. }