123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // KMMemberPromptWC.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/11/4.
- // 会员提示通用WindowController
- //
- import Cocoa
- @objc enum KMMemberTipType : Int {
- case logout = 0 // 验证码
- case unsubscribe // 注销账户 存在会员中
- case signout // 注销账户
- case cancelSignout // 撤销用户注销成功
- case signouting // 注销账户中
- }
- @objcMembers
- class KMMemberPromptWC: NSWindowController {
-
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var subTitleLabel: NSTextField!
- @IBOutlet weak var cancelButton: NSButton!
- @IBOutlet weak var yesButton: NSButton!
- private var viewModel = KMUserInfoVCModel()
-
- var tipType: KMMemberTipType = .logout {
- didSet {
- languageLocalized()
- }
- }
-
- static let shared: KMMemberPromptWC = {
- let windowC = KMMemberPromptWC(windowNibName: "KMMemberPromptWC")
- return windowC
- }()
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
-
- languageLocalized()
- initializeUI()
-
- NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
- }
-
- @objc func changeEffectiveAppearance() {
- self.initializeUI()
- }
-
- // MARK: Private Method
-
- private func languageLocalized() -> Void {
- var title = ""
- var subTitle = ""
- var cance = ""
- var yes = ""
- if tipType == .logout {
- title = NSLocalizedString("Sign out", tableName: "MemberCenterLocalizable", comment: "")
- subTitle = NSLocalizedString("Are you sure to sign out of your account?", tableName: "MemberCenterLocalizable", comment: "")
- cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
- yes = NSLocalizedString("OK", tableName: "MemberCenterLocalizable", comment: "")
- } else if tipType == .unsubscribe {
- title = NSLocalizedString("Hint", tableName: "MemberCenterLocalizable", comment: "")
- 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: "")
- yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
- } else if tipType == .signout {
- title = NSLocalizedString("Warning", tableName: "MemberCenterLocalizable", comment: "")
- 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: "")
- cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
- yes = NSLocalizedString("Continue", tableName: "MemberCenterLocalizable", comment: "")
- } else if tipType == .cancelSignout {
- title = NSLocalizedString("Undo Remove Account", tableName: "MemberCenterLocalizable", comment: "")
- subTitle = NSLocalizedString("Restore your account successfully! Enjoy PDF Reader Pro now.", tableName: "MemberCenterLocalizable", comment: "")
- yes = NSLocalizedString("Got it", tableName: "MemberCenterLocalizable", comment: "")
- } else if tipType == .signouting {
- title = NSLocalizedString("Hint", tableName: "MemberCenterLocalizable", comment: "")
- subTitle = NSLocalizedString("You have already submitted an account removal request. Please Undo Remove Account before making a purchase.", tableName: "MemberCenterLocalizable", comment: "")
- cance = NSLocalizedString("Cancel", tableName: "MemberCenterLocalizable", comment: "")
- yes = NSLocalizedString("Undo Remove Account", tableName: "MemberCenterLocalizable", comment: "")
- }
- titleLabel.stringValue = NSLocalizedString(title, tableName: "MemberCenterLocalizable", comment: "")
- subTitleLabel.stringValue = NSLocalizedString(subTitle, tableName: "MemberCenterLocalizable", comment: "")
- if cance.isEmpty != true {
- cancelButton.title = NSLocalizedString(cance, tableName: "MemberCenterLocalizable", comment: "")
- cancelButton.isHidden = false
- } else {
- cancelButton.isHidden = true
- }
- yesButton.title = NSLocalizedString(yes, tableName: "MemberCenterLocalizable", comment: "")
- }
-
- private func initializeUI() -> Void {
- self.window?.contentView?.wantsLayer = true
- let isDarkModel = KMAdvertisementConfig.isDarkModel()
- if isDarkModel {
- self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "0E1114").cgColor;
- } else {
- self.window?.contentView?.layer?.backgroundColor = NSColor(hex: "FFFFFF").cgColor;
- }
- if tipType == .logout {
- titleLabel.textColor = NSColor(named: "000000_0.85")
- titleLabel.font = NSFont.SFProTextSemiboldFont(13)
- subTitleLabel.textColor = NSColor(named: "000000_0.85")
- subTitleLabel.font = NSFont.SFProTextRegularFont(12)
- cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
- yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
- } else if tipType == .unsubscribe {
- titleLabel.textColor = NSColor(named: "000000_0.85")
- titleLabel.font = NSFont.SFProTextSemiboldFont(13)
- subTitleLabel.textColor = NSColor(named: "000000_0.85")
- subTitleLabel.font = NSFont.SFProTextRegularFont(12)
- cancelButton.isHidden = true
- yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
- } else if tipType == .signout {
- titleLabel.textColor = NSColor(named: "000000_0.85")
- titleLabel.font = NSFont.SFProTextSemiboldFont(13)
- subTitleLabel.textColor = NSColor(named: "000000_0.85")
- subTitleLabel.font = NSFont.SFProTextRegularFont(12)
- cancelButton.setTitleColor(color: NSColor(named: "000000") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
- yesButton.setTitleColor(color: NSColor(named: "FFFFFF") ?? NSColor.white, font: NSFont.SFProTextRegularFont(13))
- }
- }
-
- // MARK: Button Action
-
- @IBAction func cancelButtonAction(_ sender: NSButton) {
- if tipType == .logout {
- self.window?.close()
- viewModel.expandPersonalCenter()
- } else if tipType == .unsubscribe {
- } else if tipType == .signout {
- self.window?.close()
- } else if tipType == .signouting {
- self.window?.close()
- }
- }
-
- @IBAction func yesButtonAction(_ sender: NSButton) {
- if tipType == .logout {
- self.window?.close()
- viewModel.confirmExitAction()
- } else if tipType == .unsubscribe {
- self.window?.close()
- } else if tipType == .signout {
- self.window?.close()
- viewModel.closeAccountWarningWC()
- } else if tipType == .cancelSignout {
- self.window?.close()
- } else if tipType == .signouting {
- let viewModel = KMUserInfoVCModel()
- viewModel.closeAccountAction()
- self.window?.close()
- }
- }
- }
|