KMMemberPromptWC.swift 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // KMMemberPromptWC.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/4.
  6. // 会员提示通用WindowController
  7. //
  8. import Cocoa
  9. @objc enum KMMemberTipType : Int {
  10. case logout = 0 // 验证码
  11. case unsubscribe // 注销账户 存在会员中
  12. case signout // 注销账户
  13. case cancelSignout // 撤销用户注销成功
  14. case signouting // 注销账户中
  15. }
  16. class KMMemberPromptWC: NSWindowController {
  17. @IBOutlet weak var titleLabel: NSTextField!
  18. @IBOutlet weak var subTitleLabel: NSTextField!
  19. @IBOutlet weak var cancelButton: NSButton!
  20. @IBOutlet weak var yesButton: NSButton!
  21. private var viewModel = KMUserInfoVCModel()
  22. var tipType: KMMemberTipType = .logout {
  23. didSet {
  24. languageLocalized()
  25. }
  26. }
  27. static let shared: KMMemberPromptWC = {
  28. let windowC = KMMemberPromptWC(windowNibName: "KMMemberPromptWC")
  29. return windowC
  30. }()
  31. override func windowDidLoad() {
  32. super.windowDidLoad()
  33. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  34. languageLocalized()
  35. initializeUI()
  36. NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  37. }
  38. @objc func changeEffectiveAppearance() {
  39. self.initializeUI()
  40. }
  41. // MARK: Private Method
  42. private func languageLocalized() -> Void {
  43. var title = ""
  44. var subTitle = ""
  45. var cance = ""
  46. var yes = ""
  47. if tipType == .logout {
  48. title = NSLocalizedString("Sign out", tableName: "MemberCenterLocalizable", comment: "")
  49. subTitle = NSLocalizedString("Are you sure to sign out of your account?", tableName: "MemberCenterLocalizable", comment: "")
  50. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  51. yes = NSLocalizedString("OK", tableName: "MemberCenterLocalizable", comment: "")
  52. } else if tipType == .unsubscribe {
  53. title = NSLocalizedString("Hint", tableName: "MemberCenterLocalizable", comment: "")
  54. subTitle = NSLocalizedString("You are currently in a membership subscription. To prevent further deductions in the next cycle, please cancel your subscription on the payment platform before removing your account.", tableName: "MemberCenterLocalizable", comment: "")
  55. yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
  56. } else if tipType == .signout {
  57. title = NSLocalizedString("Warning", tableName: "MemberCenterLocalizable", comment: "")
  58. subTitle = NSLocalizedString("Removing your account will permanently delete all account data, including the membership benefits of PDF Reader Pro across all platforms you purchased under this account. Are you sure you want to continue?", tableName: "MemberCenterLocalizable", comment: "")
  59. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  60. yes = NSLocalizedString("Continue", tableName: "MemberCenterLocalizable", comment: "")
  61. } else if tipType == .cancelSignout {
  62. title = NSLocalizedString("Undo Remove Account", tableName: "MemberCenterLocalizable", comment: "")
  63. subTitle = NSLocalizedString("Restore your account successfully! Enjoy PDF Reader Pro now.", tableName: "MemberCenterLocalizable", comment: "")
  64. yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
  65. } else if tipType == .signouting {
  66. title = NSLocalizedString("Hint", tableName: "MemberCenterLocalizable", comment: "")
  67. subTitle = NSLocalizedString("You have already submitted an account removal request. Please Undo Remove Account before making a purchase.", tableName: "MemberCenterLocalizable", comment: "")
  68. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  69. yes = NSLocalizedString("Undo Remove Account", tableName: "MemberCenterLocalizable", comment: "")
  70. }
  71. titleLabel.stringValue = NSLocalizedString(title, tableName: "MemberCenterLocalizable", comment: "")
  72. subTitleLabel.stringValue = NSLocalizedString(subTitle, tableName: "MemberCenterLocalizable", comment: "")
  73. if cance.isEmpty != true {
  74. cancelButton.title = NSLocalizedString(cance, tableName: "MemberCenterLocalizable", comment: "")
  75. cancelButton.isHidden = false
  76. } else {
  77. cancelButton.isHidden = true
  78. }
  79. yesButton.title = NSLocalizedString(yes, tableName: "MemberCenterLocalizable", comment: "")
  80. }
  81. private func initializeUI() -> Void {
  82. self.window?.contentView?.wantsLayer = true
  83. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  84. if isDarkModel {
  85. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
  86. } else {
  87. self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
  88. }
  89. if tipType == .logout {
  90. titleLabel.textColor = NSColor(named: "000000_0.85")
  91. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  92. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  93. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  94. cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  95. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  96. } else if tipType == .unsubscribe {
  97. titleLabel.textColor = NSColor(named: "000000_0.85")
  98. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  99. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  100. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  101. cancelButton.isHidden = true
  102. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  103. } else if tipType == .signout {
  104. titleLabel.textColor = NSColor(named: "000000_0.85")
  105. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  106. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  107. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  108. cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  109. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  110. }
  111. }
  112. // MARK: Button Action
  113. @IBAction func cancelButtonAction(_ sender: NSButton) {
  114. if tipType == .logout {
  115. self.window?.close()
  116. viewModel.expandPersonalCenter()
  117. } else if tipType == .unsubscribe {
  118. } else if tipType == .signout {
  119. self.window?.close()
  120. }
  121. }
  122. @IBAction func yesButtonAction(_ sender: NSButton) {
  123. if tipType == .logout {
  124. self.window?.close()
  125. viewModel.confirmExitAction()
  126. } else if tipType == .unsubscribe {
  127. self.window?.close()
  128. } else if tipType == .signout {
  129. self.window?.close()
  130. viewModel.closeAccountWarningWC()
  131. } else if tipType == .cancelSignout {
  132. self.window?.close()
  133. } else if tipType == .signouting {
  134. let viewModel = KMUserInfoVCModel()
  135. viewModel.closeAccountAction()
  136. self.window?.close()
  137. }
  138. }
  139. }