// // 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 // 注销账户中 } 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() } } @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() } } }