KMMemberPromptWC.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. }
  15. class KMMemberPromptWC: NSWindowController {
  16. @IBOutlet weak var titleLabel: NSTextField!
  17. @IBOutlet weak var subTitleLabel: NSTextField!
  18. @IBOutlet weak var cancelButton: NSButton!
  19. @IBOutlet weak var yesButton: NSButton!
  20. private var viewModel = KMUserInfoVCModel()
  21. var tipType: KMMemberTipType = .logout
  22. static let shared: KMMemberPromptWC = {
  23. let windowC = KMMemberPromptWC(windowNibName: "KMMemberPromptWC")
  24. return windowC
  25. }()
  26. override func windowDidLoad() {
  27. super.windowDidLoad()
  28. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  29. languageLocalized()
  30. initializeUI()
  31. }
  32. // MARK: Private Method
  33. private func languageLocalized() -> Void {
  34. var title = ""
  35. var subTitle = ""
  36. var cance = ""
  37. var yes = ""
  38. if tipType == .logout {
  39. title = NSLocalizedString("Sign out", tableName: "MemberCenterLocalizable", comment: "")
  40. subTitle = NSLocalizedString("Are you sure to sign out of your account?", tableName: "MemberCenterLocalizable", comment: "")
  41. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  42. yes = NSLocalizedString("OK", tableName: "MemberCenterLocalizable", comment: "")
  43. } else if tipType == .unsubscribe {
  44. title = NSLocalizedString("Hint", tableName: "MemberCenterLocalizable", comment: "")
  45. 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: "")
  46. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  47. yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
  48. } else if tipType == .signout {
  49. title = NSLocalizedString("Warning", tableName: "MemberCenterLocalizable", comment: "")
  50. 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: "")
  51. cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
  52. yes = NSLocalizedString("Continue", tableName: "MemberCenterLocalizable", comment: "")
  53. } else if tipType == .cancelSignout {
  54. title = NSLocalizedString("Undo Remove Account", tableName: "MemberCenterLocalizable", comment: "")
  55. subTitle = NSLocalizedString("Restore your account successfully! Enjoy PDF Reader Pro now.", tableName: "MemberCenterLocalizable", comment: "")
  56. yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
  57. }
  58. titleLabel.stringValue = NSLocalizedString(title, tableName: "MemberCenterLocalizable", comment: "")
  59. subTitleLabel.stringValue = NSLocalizedString(subTitle, tableName: "MemberCenterLocalizable", comment: "")
  60. cancelButton.title = NSLocalizedString(cance, tableName: "MemberCenterLocalizable", comment: "")
  61. yesButton.title = NSLocalizedString(yes, tableName: "MemberCenterLocalizable", comment: "")
  62. }
  63. private func initializeUI() -> Void {
  64. if tipType == .logout {
  65. titleLabel.textColor = NSColor(named: "000000_0.85")
  66. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  67. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  68. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  69. cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  70. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  71. } else if tipType == .unsubscribe {
  72. titleLabel.textColor = NSColor(named: "000000_0.85")
  73. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  74. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  75. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  76. cancelButton.isHidden = true
  77. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  78. } else if tipType == .signout {
  79. titleLabel.textColor = NSColor(named: "000000_0.85")
  80. titleLabel.font = NSFont.SFProTextSemiboldFont(13)
  81. subTitleLabel.textColor = NSColor(named: "000000_0.85")
  82. subTitleLabel.font = NSFont.SFProTextRegularFont(12)
  83. cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  84. yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
  85. }
  86. }
  87. // MARK: Button Action
  88. @IBAction func cancelButtonAction(_ sender: NSButton) {
  89. if tipType == .logout {
  90. self.window?.close()
  91. viewModel.expandPersonalCenter()
  92. } else if tipType == .unsubscribe {
  93. } else if tipType == .signout {
  94. self.window?.close()
  95. }
  96. }
  97. @IBAction func yesButtonAction(_ sender: NSButton) {
  98. if tipType == .logout {
  99. self.window?.close()
  100. viewModel.confirmExitAction()
  101. } else if tipType == .unsubscribe {
  102. self.window?.close()
  103. } else if tipType == .signout {
  104. self.window?.close()
  105. viewModel.closeAccountWarningWC()
  106. }
  107. }
  108. }