123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // 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(.pdfReaderProAIAnnual_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
- if KMMemberInfo.shared.isLogin && KMMemberInfo.shared.validFlag == "5" {
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .signouting
- } else {
- self.window?.showWaitingView()
- // AppStore 免费版本
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().aiAllAccessPack12month_lite, discount: IAPProductsManager.default().isCancelAutoRenew())
- }
- #endif
- #else
- // AppStore 付费版
- if KMMemberInfo.shared.isLogin && KMMemberInfo.shared.validFlag == "5" {
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .signouting
- } else {
- 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()
- window?.close()
- }
- }
|