// // KMFreeGetAIWC.swift // PDF Reader Pro // // Created by wanjun on 2024/11/11. // import Cocoa @objcMembers class KMFreeGetAIWC: NSWindowController { @IBOutlet weak var titleLabel1: NSTextField! @IBOutlet weak var subTitle1: NSTextField! @IBOutlet weak var subTitle2: NSTextField! @IBOutlet weak var subTitle3: NSTextField! @IBOutlet weak var aitoolsBox: KMBox! @IBOutlet weak var aitoolsLabel: NSTextField! @IBOutlet weak var laterButton: NSButton! @IBOutlet weak var privacyPolicyLabel: NSTextField! @IBOutlet weak var termsServiceLabel: NSTextField! private var viewModel = KMProductModel() static let shared: KMFreeGetAIWC = { let windowC = KMFreeGetAIWC(windowNibName: "KMFreeGetAIWC") 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() subTitle2.isHidden = true subTitle3.isHidden = true DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil) } @objc func themeChanged(_ notification: Notification) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { self.initializeUI() } } // MARK: Private Method private func languageLocalized() -> Void { var productPrice = "" #if VERSION_FREE #if VERSION_DMG productPrice = KMProductModel.shared.getProductPrice(.pdfReaderProStandard_dmg) #else productPrice = IAPProductsManager.default().aiAllAccessPack12month_lite.price() #endif #else productPrice = IAPProductsManager.default().aiAllAccessPack12month_pro.price() #endif let firmString = NSLocalizedString("Free for the first year, then automatically renew at %@ annually. You can cancel your subscription anytime.", tableName: "MemberCenterLocalizable", comment: "") let fireFullString = String(format: firmString, productPrice) titleLabel1.stringValue = NSLocalizedString("1-Year AI Tools Giveaway", tableName: "MemberCenterLocalizable", comment: "") subTitle1.stringValue = String(format: " · %@", fireFullString) subTitle2.stringValue = String(format: " · %@", NSLocalizedString("Free for the first year, then auto-renewal at $125.99 per year. You can cancel your subscription anytime.", tableName: "MemberCenterLocalizable", comment: "")) subTitle3.stringValue = String(format: " · %@", NSLocalizedString("Pick up free AI Tools before 23:59:00, or it will be invalid", tableName: "MemberCenterLocalizable", comment: "")) aitoolsLabel.stringValue = NSLocalizedString("Get 1-Year AI Tools with $0", tableName: "MemberCenterLocalizable", comment: "") laterButton.title = NSLocalizedString("Later", tableName: "MemberCenterLocalizable", comment: "") privacyPolicyLabel.isEditable = false privacyPolicyLabel.isSelectable = true privacyPolicyLabel.allowsEditingTextAttributes = true termsServiceLabel.isEditable = false termsServiceLabel.isSelectable = true termsServiceLabel.allowsEditingTextAttributes = true NotificationCenter.default.addObserver( self, selector: #selector(IAPSubscriptionLoadedNotification(_:)), name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"), object: nil ) NotificationCenter.default.addObserver( self, selector: #selector(IAPSubscriptionLoadedNotification(_:)), name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"), object: nil ) let privacyPolicy = NSLocalizedString("Privacy Policy", tableName: "MemberCenterLocalizable", comment: "") let termsService = NSLocalizedString("Service Agreement", tableName: "MemberCenterLocalizable", comment: "") let attributedString1 = NSMutableAttributedString(string: privacyPolicy) let attributedString2 = NSMutableAttributedString(string: termsService) let privacyPolicyRange = (privacyPolicy as NSString).range(of: privacyPolicy) let termsServiceRange = (termsService as NSString).range(of: termsService) attributedString1.addAttributes([ .font: NSFont.systemFont(ofSize: 12), .foregroundColor: NSColor(named: "273C62") ?? .blue, .underlineStyle: NSUnderlineStyle.single.rawValue, .link: NSURL(string: "https://www.pdfreaderpro.com/privacy-policy")! ], range: privacyPolicyRange) attributedString2.addAttributes([ .font: NSFont.systemFont(ofSize: 12), .foregroundColor: NSColor(named: "273C62") ?? .blue, .underlineStyle: NSUnderlineStyle.single.rawValue, .link: NSURL(string:"https://www.pdfreaderpro.com/terms_of_service")! ], range: termsServiceRange) privacyPolicyLabel.attributedStringValue = attributedString1 termsServiceLabel.attributedStringValue = attributedString2 aitoolsBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in guard let self = self else { return } } aitoolsBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox, event) -> Void in guard let self = self else { return } #if VERSION_FREE #if VERSION_DMG // DMG #if VERSION_DMG self.close() let embeddedWC = KMPurchaseEmbeddedWindowController.currentCode(KMAISubscriptionYearTrailCodeKey_DMG) embeddedWC.showWindow(nil) embeddedWC.window?.center() #endif #else self.window?.showWaitingView() // AppStore 免费版本 IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: IAPProductsManager.default().isCancelAutoRenew()) #endif #else // AppStore 付费版 self.window?.showWaitingView() IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_pro, discount: IAPProductsManager.default().isCancelAutoRenew()) #endif } } private func initializeUI() -> Void { 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; } titleLabel1.textColor = NSColor(named: "1D2023") titleLabel1.font = NSFont.SFProTextSemiboldFont(24) subTitle1.textColor = NSColor(named: "101828") subTitle1.font = NSFont.SFProTextRegularFont(14) subTitle2.textColor = NSColor(named: "101828") subTitle2.font = NSFont.SFProTextRegularFont(14) subTitle3.textColor = NSColor(named: "F04438") subTitle3.font = NSFont.SFProTextRegularFont(14) aitoolsBox.fillColor = NSColor(named: "273C62") ?? .blue aitoolsLabel.textColor = NSColor(named: "FFFFFF") aitoolsLabel.font = NSFont.SFProTextRegularFont(13) laterButton.setTitleColor(color: NSColor(named: "4982E6") ?? NSColor.white, font: NSFont.SFProTextRegularFont(12)) } // MARK: Action @IBAction func laterButtonAction(_ sender: NSButton) { window?.close() } @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) { self.window?.hideWaitingView() } }