KMOpenDMGPopupBootWC.swift 5.1 KB

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