KMOpenDMGPopupBootWC.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. signInTextView.bounds = signInTextView.enclosingScrollView?.contentView.bounds ?? .zero
  55. signInTextView.autoresizingMask = [.width, .height]
  56. let tipsString = NSLocalizedString("Already have an account? %@", tableName: "MemberCenterLocalizable", comment: "")
  57. let specialOffer = NSLocalizedString("Sign in", tableName: "MemberCenterLocalizable", comment: "")
  58. let fullString = String(format: tipsString, specialOffer)
  59. let paragraphStyle = NSMutableParagraphStyle()
  60. paragraphStyle.alignment = .center
  61. let attributedString = NSMutableAttributedString(string: fullString)
  62. let specialOfferRange = (fullString as NSString).range(of: specialOffer)
  63. let linkColor = NSColor(named: "4982E6") ?? NSColor.blue
  64. let font = NSFont.SFProTextRegularFont(12)
  65. attributedString.addAttributes([
  66. .foregroundColor: NSColor(named: "42464D") ?? NSColor.black as Any,
  67. .font: font,
  68. .paragraphStyle: paragraphStyle
  69. ], range: (fullString as NSString).range(of: fullString))
  70. attributedString.addAttributes([
  71. .foregroundColor: linkColor,
  72. .link: "action://openDetail",
  73. .font: font
  74. ], range: specialOfferRange)
  75. signInTextView.textStorage?.setAttributedString(attributedString)
  76. signInTextView.delegate = self
  77. freeBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  78. guard let self = self else { return }
  79. }
  80. freeBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  81. guard let self = self else { return }
  82. if downEntered {
  83. self.viewModel.getVipFree()
  84. self.window?.close()
  85. }
  86. }
  87. }
  88. }
  89. extension KMOpenDMGPopupBootWC: NSTextViewDelegate {
  90. func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool {
  91. if let urlString = link as? String, urlString == "action://openDetail" {
  92. viewModel.signUpAction()
  93. self.window?.close()
  94. return true
  95. }
  96. return false
  97. }
  98. }