123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427 |
- //
- // KMProductCompareWC.swift
- // PDF Reader Pro
- //
- // Created by wanjun on 2024/11/6.
- //
- import Cocoa
- import Combine
- @objc enum KMDiscountType: UInt {
- case none = 0
- case newUserGift // 新手活动
- case advancedYearSubscribeTrialingCancel // 高级年订阅 试用退订
- case freeTrail // 免费试用
- }
- @objcMembers class KMProductCompareWC: NSWindowController {
- @IBOutlet @objc weak var tableView: NSTableView!
- @IBOutlet @objc weak var titleLabel: NSTextField!
- @IBOutlet @objc weak var topMainBox: NSBox!
- @IBOutlet @objc weak var topMainView: NSView!
- @IBOutlet @objc weak var topsubBox1: NSBox!
- @IBOutlet @objc weak var topSelectBox1: NSBox!
- @IBOutlet @objc weak var topsubBox2: NSBox!
- @IBOutlet @objc weak var topSelectBox2: NSBox!
- @IBOutlet @objc weak var topsubBox3: NSBox!
- @IBOutlet @objc weak var topSelectBox3: NSBox!
- @IBOutlet @objc weak var topsubBox4: NSBox!
- @IBOutlet @objc weak var topSelectBox4: NSBox!
- @IBOutlet weak var topsubBoxWidth1: NSLayoutConstraint!
- @IBOutlet weak var topsubBoxWidth2: NSLayoutConstraint!
- @IBOutlet weak var topsubBoxWidth3: NSLayoutConstraint!
- @IBOutlet weak var topsubBoxWidth4: NSLayoutConstraint!
- @IBOutlet @objc weak var switchLabel: NSTextField!
- // @IBOutlet @objc weak var switchButton: NSButton!
- @IBOutlet @objc weak var freeInfoView: NSView!
- @IBOutlet @objc weak var freeInfoLabel: NSTextField!
- @IBOutlet @objc weak var value1InfoView: NSView!
- // @IBOutlet @objc weak var value1InfoBox: NSBox!
- @IBOutlet @objc weak var value1InfoTypeBox: NSBox!
- @IBOutlet @objc weak var sixMouthProLabel: NSTextField!
- @IBOutlet @objc weak var oneYearProLabel: NSTextField!
- @IBOutlet weak var backgroundImage1: NSImageView!
-
- @IBOutlet @objc weak var switchBox: NSBox!
- @IBOutlet @objc weak var switchBtn: NSButton!
- @IBOutlet @objc weak var switchCircleView: NSView!
- @IBOutlet @objc weak var switchCircleLeftConst: NSLayoutConstraint!
- @IBOutlet @objc weak var saleBox: NSBox!
- @IBOutlet @objc weak var saleIv: NSImageView!
- @IBOutlet @objc weak var saleLabel: NSTextField!
- @IBOutlet @objc weak var value1InfoLabel: NSTextField!
- @IBOutlet @objc weak var value1PurchaseLabel: NSTextField!
- @IBOutlet @objc weak var value1PurchaseSubLabel: NSTextField!
- @IBOutlet @objc weak var value1PurchaseButton: KMCustomButton!
- @IBOutlet @objc weak var value1PurchaseBtnLbl: NSTextField!
- @IBOutlet @objc weak var value1PurchaseOriPriceLbl: NSTextField!
- @IBOutlet @objc weak var value1PurchaseBtnLblBtn: NSButton!
- // 标准版年订阅
- @IBOutlet @objc weak var standardPlanInfoView: NSView!
- @IBOutlet @objc weak var standardPlanInfoLabel: NSTextField!
- @IBOutlet @objc weak var standardPlanPurchaseLabel: NSTextField!
- @IBOutlet @objc weak var standardPlanPurchaseSubLabel: NSTextField!
- @IBOutlet @objc weak var standardPlanPurchaseButton: NSButton!
- @IBOutlet @objc weak var standardPlanPurchaseLbl: NSTextField!
- @IBOutlet @objc weak var standardPlanPurchaseLblBtn: NSButton!
- @IBOutlet @objc weak var standardPlanPurchaseSubLabel2: NSTextField!
- @IBOutlet @objc weak var standardPurchaseOriPriceLbl: NSTextField!
- // 高级版年订阅
- @IBOutlet @objc weak var advancedPlanInfoView: NSView!
- @IBOutlet @objc weak var advancedPlanInfoLabel: NSTextField!
- @IBOutlet @objc weak var advancedPlanPurchaseLabel: NSTextField!
- @IBOutlet @objc weak var advancedPlanPurchaseSubLabel: NSTextField!
- @IBOutlet @objc weak var advancedPlanPurchaseButton: NSButton!
- @IBOutlet @objc weak var advancedPlanPurchaseLbl: NSTextField!
- @IBOutlet @objc weak var advancedPlanPurchaseLblBtn: NSButton!
- @IBOutlet @objc weak var advancedPlanPurchaseSubLabel2: NSTextField!
- @IBOutlet weak var backgroundImage3: NSImageView!
- @IBOutlet @objc weak var discountPermanent2: NSImageView!
- @IBOutlet @objc weak var advancedPurchaseOriPriceLbl: NSTextField!
- // 买断
- @IBOutlet @objc weak var permanentInfoView: NSView!
- @IBOutlet @objc weak var permanentInfoLabel: NSTextField!
- @IBOutlet @objc weak var permanentPurchaseLabel: NSTextField!
- @IBOutlet @objc weak var permanentPurchaseSubLabel: NSTextField!
- @IBOutlet @objc weak var permanentPurchaseButton: NSButton!
- @IBOutlet @objc weak var permanentPurchaseLbl: NSTextField!
- @IBOutlet @objc weak var permanentPurchaseLblBtn: NSButton!
- @IBOutlet @objc weak var permanentPurchaseSubLabel2: NSTextField!
- @IBOutlet @objc weak var discountPermanent4: NSImageView!
- @IBOutlet @objc weak var permanentPurchaseOriPriceLbl: NSTextField!
- @IBOutlet @objc weak var aboutButton: NSButton!
- @IBOutlet @objc weak var btnRestore: HyperLinkButton!
- @IBOutlet @objc weak var privacyPolicyBtn: HyperLinkButton!
- @IBOutlet @objc weak var termOfSerBtn: HyperLinkButton!
- @IBOutlet @objc weak var textView: NSTextView!
- @IBOutlet @objc weak var specialView: NSView!
- @IBOutlet @objc weak var specialImageView: NSImageView!
- @IBOutlet @objc weak var specialLabel: NSTextField!
- @IBOutlet @objc weak var specialView1: NSView!
- @IBOutlet @objc weak var specialImageView1: NSImageView!
- @IBOutlet @objc weak var specialLabel1: NSTextField!
- @IBOutlet @objc weak var box: NSBox!
- @IBOutlet @objc weak var labelbox: NSBox!
- // @IBOutlet @objc weak var topButtonOffset: NSLayoutConstraint!
-
- @objc var value1Layer: CALayer?
- @objc var discountToSaveWinC: KMDiscountToSaveWindowController?
- @IBOutlet @objc weak var billedTopConst: NSLayoutConstraint!
- @IBOutlet @objc weak var discountYearly: NSImageView!
- @IBOutlet @objc weak var discountPermanent: NSImageView!
- // @IBOutlet @objc weak var discountPremium: NSImageView!
-
- @IBOutlet @objc weak var platformsView1: NSView!
- @IBOutlet @objc weak var platformsView2: NSView!
- @IBOutlet @objc weak var platformsView3: NSView!
- @IBOutlet @objc weak var platformsView4: NSView!
- @IBOutlet @objc weak var giftAIImage1: NSImageView!
- @IBOutlet @objc weak var giftAILabel1: NSTextField!
- @IBOutlet @objc weak var giftAIImage2: NSImageView!
- @IBOutlet @objc weak var giftAILabel2: NSTextField!
- @IBOutlet @objc weak var giftAIImage3: NSImageView!
- @IBOutlet @objc weak var giftAILabel3: NSTextField!
- @IBOutlet @objc weak var giftAIImage4: NSImageView!
- @IBOutlet @objc weak var giftAILabel4: NSTextField!
-
- @IBOutlet weak var value1PurchaseDiscountBox: NSBox!
- @IBOutlet weak var permanentInfoDiscountBox: NSBox!
- @IBOutlet weak var standardPlanInfoDiscountBox: NSBox!
- @IBOutlet weak var advancedPlanInfoDiscountBox: NSBox!
-
- private lazy var value1PurchaseDiscountView_: KMProductCompareDiscountView = {
- let view = KMProductCompareDiscountView()
- view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
- return view
- }()
- private lazy var permanentInfoDiscountView_: KMProductCompareDiscountView = {
- let view = KMProductCompareDiscountView()
- view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
- return view
- }()
- private lazy var standardPlanInfoDiscountView_: KMProductCompareDiscountView = {
- let view = KMProductCompareDiscountView()
- view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
- return view
- }()
- private lazy var advancedPlanInfoDiscountView_: KMProductCompareDiscountView = {
- let view = KMProductCompareDiscountView()
- view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
- return view
- }()
-
- private var model = KMProductModel.shared
- private var cancellables = Set<AnyCancellable>()
-
- private var subscribeType_: KMSubscribeWaterMarkType?
- var subscribeType: KMSubscribeWaterMarkType? {
- get {
- return subscribeType_
- }
- }
- private var discountType_: KMDiscountType = .none
- var discountType: KMDiscountType {
- get {
- return discountType_
- }
- }
-
- private lazy var originalPriceAttri_: [NSAttributedString.Key : Any] = {
- return [.font : NSFont.SFProTextRegularFont(12),
- .foregroundColor: NSColor(hex: "#FFE76A"),
- .strikethroughStyle: NSUnderlineStyle.single.rawValue]
- }()
-
- var orientation: Bool = false // 是否定向跳转
- var orientationType: KMCompareTableType = .trial // 定向跳转比较表
-
- static let shared: KMProductCompareWC = {
- let windowC = KMProductCompareWC(windowNibName: "KMProductCompareWC")
- return windowC
- }()
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- override init(window: NSWindow?) {
- super.init(window: window)
- setupNotifications()
- }
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- window?.backgroundColor = KMAppearance.Upgrade.vipBGColor()
- window?.isMovableByWindowBackground = true
-
- #if VERSION_DMG
- btnRestore.isHidden = true
- #endif
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- bindViewModel()
- if orientation {
- model.state = orientationType
- } else {
- model.getCurrentComparisonTableType()
- }
- value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
- value1InfoLabel.font = NSFont.UbuntuMediumFontWithSize(16)
- value1PurchaseButton.wantsLayer = true
- value1PurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
- value1PurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
- value1PurchaseBtnLblBtn.wantsLayer = true
- value1PurchaseButton.mouseMoveCallback = { [weak self] mouseEntered in
- guard let self = self else { return }
- if self.value1PurchaseBtnLblBtn.isEnabled == true {
- self.value1PurchaseBtnLblBtn.layer?.backgroundColor = mouseEntered ? NSColor.black.withAlphaComponent(0.15).cgColor : NSColor.clear.cgColor
- }
- }
- value1PurchaseBtnLblBtn.layer?.cornerRadius = value1PurchaseBtnLblBtn.frame.height / 2
- value1PurchaseBtnLblBtn.layer?.masksToBounds = true
- standardPlanPurchaseButton.wantsLayer = true
- standardPlanPurchaseButton.layer?.cornerRadius = standardPlanPurchaseButton.frame.height / 2
- self.standardPlanPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
- switchLabel.stringValue = NSLocalizedString("Choose your favorite payment and enjoy flexible upgrades.", comment: "")
- switchLabel.textColor = KMAppearance.Interactive.m0Color()
- box.wantsLayer = true
- box.shadow = NSShadow()
- box.layer?.shadowOpacity = 0.3
- box.layer?.shadowColor = NSColor.black.withAlphaComponent(0.3).cgColor
- box.layer?.shadowOffset = NSMakeSize(0, 3)
- box.layer?.shadowRadius = 8
- box.layer?.masksToBounds = false
-
- permanentPurchaseButton.wantsLayer = true
- permanentPurchaseButton.layer?.cornerRadius = permanentPurchaseButton.frame.height / 2
- self.permanentPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
- let txtColor = NSColor(red: 102/255, green: 102/255, blue: 102/255, alpha: 1)
- aboutButton.title = NSLocalizedString("About Subscriptions", comment: "")
- aboutButton.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
- aboutButton.isHidden = true
-
- self.value1PurchaseDiscountBox.borderWidth = 0
- self.value1PurchaseDiscountBox.contentView = self.value1PurchaseDiscountView_
- self.value1PurchaseDiscountView_.label.stringValue = "-$10"
- self.standardPlanInfoDiscountBox.borderWidth = 0
- self.standardPlanInfoDiscountBox.contentView = self.standardPlanInfoDiscountView_
- self.advancedPlanInfoDiscountBox.borderWidth = 0
- self.advancedPlanInfoDiscountBox.contentView = self.advancedPlanInfoDiscountView_
- self.permanentInfoDiscountBox.borderWidth = 0
- self.permanentInfoDiscountBox.contentView = self.permanentInfoDiscountView_
- self.permanentInfoDiscountView_.label.stringValue = "-$20"
- reloadData()
- reloadDataContent()
- #if !VERSION_DMG
- IAPProductsManager.default().loadProducts()
- #endif
-
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- textView.string = String(format: "Subscription plans:\nPDF Reader Pro Standard - Annual Plan: $79.99/year\nPDF Reader Pro Advanced - Annual Plan: $99.99/year\nPDF Reader Pro Permanent: $119.99\n\nSubscriptions: %@\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", "", NSLocalizedString("USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", comment: ""))
- #else
- // AppStore 免费版本
- textView.string = String(format: "Subscription plans:\nPDF Reader Pro Advanced - 6-Month Plan: $49.99/year\nPDF Reader Pro Advanced - Annual Plan: $99.99/year\nPDF Reader Pro Permanent: $119.99\n\nSubscriptions: %@\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", "", NSLocalizedString("USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", comment: ""))
- #endif
- #else
- // AppStore 付费版
- textView.string = String(format: "Subscriptions: %@\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", "", NSLocalizedString("USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", comment: ""))
- #endif
- showDiscount()
-
- comparativeStatementHead()
-
- let closeButton = window?.standardWindowButton(.closeButton)
- closeButton?.target = self
- closeButton?.action = #selector(closeAction)
- }
-
- func windowShouldClose(sender:Any) -> Bool {
- FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn":"PUW_Btn_Upgrade_Cancel"])
- if model.isShowSale {
- trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn":"PUW_7OffUpgrade_Cancel"], platform: .AppCenter)
- }
- return true
- }
- @objc func showWindowRestore(_ sender: Any) {
- showWindow(sender)
- buttonItemClicked_Restore(sender)
- }
- override func showWindow(_ sender: Any?) {
- super.showWindow(sender)
-
- subscribeType_ = nil
- discountType_ = .none
- clearEventData()
-
- _trackComparisonEvent(params: ["Exposure" : "ComparisonTable_Exposure"])
-
- alertingCodeForRefreshUserInfo_ = nil
- alertingForRefreshUserInfo_ = false
- #if VERSION_DMG
- model.getDMGProductDatas(discountCode: "") { success, result in
-
- }
- #endif
- if orientation {
- model.state = orientationType
- } else {
- model.getCurrentComparisonTableType()
- }
- model.isPurchaseSwitch = true
-
- languageLocalized()
- initializeUI()
- reloadData()
- if model.isShowSale {
- showDiscountToSaveWindow()
- }
- reloadDataContent()
-
- showDiscount()
-
- comparativeStatementHead()
- }
-
- // MARK: - Public Methods
-
- public func openWindow(type: KMSubscribeWaterMarkType) {
- showWindow(nil)
-
- subscribeType_ = type
- }
-
- public func openWindow(discountType: KMDiscountType) {
- showWindow(nil)
-
- discountType_ = discountType
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- if discountType == .newUserGift {
- model.isPurchaseSwitch = false
- }
- #endif
- #endif
-
- comparativeStatementHead()
- #if VERSION_DMG
- var discountCode: String = ""
- if discountType == .newUserGift {
- discountCode = kKMNewUserGiftDiscountCodeId
- } else if discountType == .advancedYearSubscribeTrialingCancel {
- discountCode = kKMAdvancedYearSubscribeDiscountCodeId
- }
- model.getDMGProductDatas(discountCode: discountCode) { success, result in
- self.comparativeStatementHead()
- }
- #endif
- }
-
- public func closeWindow() {
- window?.close()
- }
- // MARK: - Private Methods
-
- private func languageLocalized() -> Void {
- titleLabel.stringValue = NSLocalizedString("Subscribe to All Access Pack to enjoy more expanded features.", comment: "")
- btnRestore.title = NSLocalizedString("Restore", comment: "")
- btnRestore.toolTip = NSLocalizedString("Restore", comment: "")
- privacyPolicyBtn.title = NSLocalizedString("Privacy Policy", comment: "")
- privacyPolicyBtn.toolTip = NSLocalizedString("Privacy Policy", comment: "")
- termOfSerBtn.title = NSLocalizedString("Terms of Service", comment: "")
- termOfSerBtn.toolTip = NSLocalizedString("Terms of Service", comment: "")
- sixMouthProLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
- oneYearProLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
- freeInfoLabel.stringValue = NSLocalizedString("Free", comment: "")
- standardPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
- standardPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
- standardPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
-
- advancedPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Advanced - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
- advancedPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
- advancedPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
- permanentInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Permanent", tableName: "MemberCenterLocalizable", comment: "")
- permanentPurchaseSubLabel.stringValue = NSLocalizedString("one-time purchase", comment: "")
- permanentPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
-
- standardPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- if KMMemberInfo.shared.userScenarioType == .lite_type3 ||
- KMMemberInfo.shared.userScenarioType == .lite_type11 {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Renew now",tableName: "MemberCenterLocalizable", comment: "")
- } else {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- }
- permanentPurchaseLbl.stringValue = NSLocalizedString("Purchase", comment: "")
-
- giftAILabel1.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
- giftAILabel2.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
- giftAILabel3.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
- giftAILabel4.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- if KMMemberInfo.shared.canTrail && model.state == .trial {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- }
- if model.state == .dmg_Base {
- if discountType_ == .newUserGift || discountType_ == .advancedYearSubscribeTrialingCancel {
- standardPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProStandard_dmg)
- advancedPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProAdvanced_dmg)
- permanentPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProPermanent_dmg)
-
- standardPurchaseOriPriceLbl.isHidden = false
- standardPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProStandard_dmg), attributes: originalPriceAttri_)
- advancedPurchaseOriPriceLbl.isHidden = false
- advancedPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProAdvanced_dmg), attributes: originalPriceAttri_)
- permanentPurchaseOriPriceLbl.isHidden = false
- permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProPermanent_dmg), attributes: originalPriceAttri_)
- } else {
- standardPurchaseOriPriceLbl.isHidden = true
- advancedPurchaseOriPriceLbl.isHidden = true
- permanentPurchaseOriPriceLbl.isHidden = true
- standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
- permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
- }
- } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
- guard let productModels = model.dmgProductDatas?.listingProducts else { return }
- for productModel in productModels {
- if productModel.code == "advanced-annual-subscription" {
- model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
- guard let self = self else { return }
- guard let results: KMMemberProductResult = result else { return }
- guard let productModels2 = results.listingProducts else { return }
- for productModel2 in productModels2 {
- if productModel2.code == "advanced-annual-subscription" {
- self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
- }
- }
- }
- } else if productModel.code == "advanced-permanent-blackFive" {
- model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
- guard let self = self else { return }
- guard let results: KMMemberProductResult = result else { return }
- guard let productModels2 = results.listingProducts else { return }
- for productModel2 in productModels2 {
- if productModel2.code == "advanced-annual-subscription-blackFive" {
- self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
- }
- }
- }
- }
- }
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
- }
- #else
- var isTrialPeriod = false
- if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == true {
- isTrialPeriod = true
- }
- if KMMemberInfo.shared.isLogin {
- if(!isTrialPeriod &&
- KMMemberInfo.shared.canTrail &&
- model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- }
- } else {
- if(!isTrialPeriod &&
- model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- }
- }
- // AppStore 免费版本
- if model.state == .lite_Base {
- permanentPurchaseLabel.stringValue = model.getProductPrice(.allAccessPackPermanent_lite)
- } else if model.state == .lite_MacWindows {
- if KMMemberInfo.shared.userScenarioType == .lite_type5 {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if platformsArray.count == 1 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
- } else if platformsArray.count == 2 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
- }
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
- }
- } else {
- // model.state == .trial
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPackNew12months_lite)
- }
- #endif
- #else
- // AppStore 付费版
- if model.state == .pro_Base {
- if KMMemberInfo.shared.userScenarioType == .pro_type3 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.standardAddDevicesAllAccessPack12months_pro)
- permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfToOfficePackPermanent_pro)
- }
- } else if model.state == .pro_Advanced {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if KMMemberInfo.shared.userScenarioType == .pro_type1 {
- if platformsArray.count == 1 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
- } else if platformsArray.count == 2 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
- } else if KMMemberInfo.shared.vip_levels == "1" {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
- }
- } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
- if platformsArray.count == 1 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
- } else if platformsArray.count == 2 {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
- }
- }
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPack12months_pro)
- }
- #endif
- }
-
- private func initializeUI() -> Void {
- btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- btnRestore.font = NSFont.SFProTextRegularFont(13)
- btnRestore.mouseMoveCallback = { [weak self] mouseEntered in
- guard let self = self else { return }
- if mouseEntered {
- self.btnRestore.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
- } else {
- self.btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- }
- }
- privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- privacyPolicyBtn.font = NSFont.SFProTextRegularFont(13)
- privacyPolicyBtn.mouseMoveCallback = { [weak self] mouseEntered in
- guard let self = self else { return }
- if mouseEntered {
- self.privacyPolicyBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
- } else {
- self.privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- }
- }
- termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- termOfSerBtn.font = NSFont.SFProTextRegularFont(13)
- termOfSerBtn.mouseMoveCallback = { [weak self] mouseEntered in
- guard let self = self else { return }
- if mouseEntered {
- self.termOfSerBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
- } else {
- self.termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
- }
- }
-
- giftAILabel1.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
- giftAILabel1.font = NSFont.SFProTextRegularFont(12)
- giftAILabel2.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
- giftAILabel2.font = NSFont.SFProTextRegularFont(12)
- giftAILabel3.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
- giftAILabel3.font = NSFont.SFProTextRegularFont(12)
- giftAILabel4.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
- giftAILabel4.font = NSFont.SFProTextRegularFont(12)
- value1InfoTypeBox.fillColor = NSColor.clear
- value1InfoTypeBox.borderWidth = 0
- sixMouthProLabel.textColor = .white
- sixMouthProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- sixMouthProLabel.lineBreakMode = .byTruncatingTail
- sixMouthProLabel.toolTip = sixMouthProLabel.stringValue
- sixMouthProLabel.alignment = .center
- oneYearProLabel.textColor = .white
- oneYearProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- oneYearProLabel.lineBreakMode = .byTruncatingTail
- oneYearProLabel.toolTip = oneYearProLabel.stringValue
- oneYearProLabel.alignment = .center
- switchBox.fillColor = NSColor(white: 1, alpha: 0.2)
- switchBox.cornerRadius = 12
- switchBox.borderWidth = 1
- switchBox.borderColor = NSColor(red: 235/255, green: 236/255, blue: 240/255, alpha: 1.0)
- switchCircleView.wantsLayer = true
- switchCircleView.layer?.cornerRadius = 8
- switchCircleView.layer?.backgroundColor = NSColor.white.cgColor
- switchBtn.title = ""
- switchBtn.target = self
- switchBtn.action = #selector(switchAction)
- saleLabel.isHidden = true
- saleLabel.superview?.isHidden = true
- saleBox.borderWidth = 0
-
- topMainBox.contentView = topMainView
- if let contentView = topMainBox.contentView {
- contentView.wantsLayer = true
- contentView.layer?.masksToBounds = false
- }
- if let contentView = topMainView {
- contentView.wantsLayer = true
- contentView.layer?.masksToBounds = false
- }
- topsubBox1.isHidden = false
- topsubBox2.isHidden = false
- topsubBox3.isHidden = false
- topsubBox4.isHidden = false
- topSelectBox1.isHidden = true
- topSelectBox2.isHidden = true
- topSelectBox3.isHidden = true
- topSelectBox4.isHidden = true
- giftAIImage1.isHidden = true
- giftAILabel1.isHidden = true
- giftAIImage2.isHidden = true
- giftAILabel2.isHidden = true
- giftAIImage3.isHidden = true
- giftAILabel3.isHidden = true
- giftAIImage4.isHidden = true
- giftAILabel4.isHidden = true
- freeInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- standardPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- advancedPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- permanentInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
- standardPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
- standardPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
- advancedPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
- advancedPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
- permanentPurchaseSubLabel.font = NSFont.UbuntuMediumFontWithSize(11)
- permanentPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
- value1PurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
- standardPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
- standardPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
- advancedPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
- advancedPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
- permanentPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
- permanentPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
- backgroundImage1.wantsLayer = true
- backgroundImage1.layer?.cornerRadius = 12
- backgroundImage1.layer?.masksToBounds = true
- backgroundImage3.wantsLayer = true
- backgroundImage3.layer?.cornerRadius = 12
- backgroundImage3.layer?.masksToBounds = true
- advancedPlanPurchaseButton.wantsLayer = true
- advancedPlanPurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
- advancedPlanPurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
- standardPlanPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
- advancedPlanPurchaseLbl.textColor = NSColor(named: "FFFFFF") ?? .white
- permanentPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
- var contentWidth = 970.0
- var contentHeight = 660.0
- if model.state == .dmg_Base {
- contentWidth = 970.0
- contentHeight = 660.0
- topsubBox1.contentView = freeInfoView
- topsubBox2.contentView = standardPlanInfoView
- topsubBox3.contentView = advancedPlanInfoView
- topsubBox4.contentView = permanentInfoView
- backgroundImage1.isHidden = true
- topSelectBox3.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage3.isHidden = false
- // giftAILabel3.isHidden = false
- // }
- topsubBoxWidth1.constant = 149.5
- topsubBoxWidth2.constant = 149.5
- topsubBoxWidth3.constant = 149.5
- topsubBoxWidth3.constant = 149.5
- } else if model.state == .dmg_Upgrades1 {
- contentWidth = 689.0
- contentHeight = 660.0
- topsubBox2.isHidden = true
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = advancedPlanInfoView
- topSelectBox1.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage1.isHidden = false
- // giftAILabel1.isHidden = false
- // }
- topsubBoxWidth1.constant = 320.0
- } else if model.state == .dmg_Upgrades2 {
- contentWidth = 689.0
- contentHeight = 660.0
- topsubBox2.isHidden = true
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = advancedPlanInfoView
- topSelectBox1.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage1.isHidden = false
- // giftAILabel1.isHidden = false
- // }
- topsubBoxWidth1.constant = 320.0
- } else if model.state == .lite_Base {
- contentWidth = 970.0
- contentHeight = 660.0
- topsubBox4.isHidden = true
- topsubBox1.contentView = freeInfoView
- topsubBox2.contentView = value1InfoView
- topsubBox3.contentView = permanentInfoView
- topSelectBox2.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage2.isHidden = false
- // giftAILabel2.isHidden = false
- // }
- topsubBoxWidth1.constant = 179.0
- topsubBoxWidth2.constant = 240.0
- topsubBoxWidth3.constant = 179.0
- } else if model.state == .lite_MacWindows {
- contentWidth = 689.0
- contentHeight = 660.0
- topsubBox2.isHidden = true
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = advancedPlanInfoView
- topSelectBox1.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage1.isHidden = false
- // giftAILabel1.isHidden = false
- // }
- topsubBoxWidth1.constant = 320.0
- } else if model.state == .pro_Base {
- contentWidth = 970.0
- contentHeight = 660.0
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = advancedPlanInfoView
- topsubBox2.contentView = permanentInfoView
- backgroundImage1.isHidden = true
- topSelectBox1.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage1.isHidden = false
- // giftAILabel1.isHidden = false
- // }
- topsubBoxWidth1.constant = 299.0
- topsubBoxWidth2.constant = 299.0
- } else if model.state == .pro_Advanced {
- contentWidth = 689.0
- contentHeight = 660.0
- topsubBox2.isHidden = true
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = advancedPlanInfoView
- topSelectBox1.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage1.isHidden = false
- // giftAILabel1.isHidden = false
- // }
- topsubBoxWidth1.constant = 320.0
- } else {
- // model.state == .trial
- contentWidth = 785.0
- contentHeight = 660.0
- topsubBox3.isHidden = true
- topsubBox4.isHidden = true
- topsubBox1.contentView = freeInfoView
- topsubBox2.contentView = advancedPlanInfoView
- backgroundImage1.isHidden = true
- topSelectBox2.isHidden = false
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage2.isHidden = false
- // giftAILabel2.isHidden = false
- // }
- topsubBoxWidth1.constant = 179.0
- topsubBoxWidth2.constant = 240.0
- }
- self.window?.setContentSize(NSSize(width: contentWidth, height: contentHeight))
- self.window?.maxSize = NSSize(width: contentWidth, height: contentHeight)
- self.window?.minSize = NSSize(width: contentWidth, height: contentHeight)
-
- box.fillColor = KMAppearance.Layout.l1Color()
- labelbox.fillColor = .clear
- tableView.backgroundColor = KMAppearance.Layout.l0Color()
- textView.backgroundColor = .clear
- textView.textColor = NSColor.white.withAlphaComponent(0.5)
- value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- standardPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- standardPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
- advancedPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- advancedPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
- permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- permanentPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
-
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- #else
- // AppStore 免费版本
- refreshPurchaseSwitch()
- #endif
- #else
- // AppStore 付费版
- #endif
- }
- private func setupNotifications() {
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPProductLoadedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPProductLoadedNotification"),
- object: nil
- )
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPSubscriptionLoadedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
- object: nil
- )
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPProductPurchasedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"),
- object: nil
- )
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPProductFailedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
- object: nil
- )
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPProductRestoreFinishedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"),
- object: nil
- )
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(IAPProductRestoreFailedNotification(_:)),
- name: NSNotification.Name(rawValue: "KMIAPProductRestoreFailedNotification"),
- object: nil
- )
-
- DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
- }
-
- func reloadData() {
- saleBox.isHidden = true
- saleIv.isHidden = true
- if model.isShowSale {
- if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
- let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.saleImage, highlight: true)) {
- KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
- guard let self = self else { return }
- self.saleIv.image = image
- self.saleBox.isHidden = false
- self.saleIv.isHidden = false
- self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_7OffUpgrade"], platform: .AppCenter)
- }
- }
- } else {
- saleBox.isHidden = true
- }
-
- // if KMMemberInfo.shared.isMemberAllFunction == true {
- // value1PurchaseButton.isEnabled = false
- // permanentPurchaseButton.isEnabled = false
- // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 0.5)
- // } else {
- // value1PurchaseButton.isEnabled = true
- // permanentPurchaseButton.isEnabled = true
- // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 1.0)
- // }
-
- permanentPurchaseLbl.font = NSFont.UbuntuBoldFontWithSize(16)
- value1PurchaseOriPriceLbl.font = NSFont.SFProTextRegularFont(12)
- }
-
- func refreshPurchaseSwitch() -> Void {
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- #else
- // AppStore 免费版本
- reloadData()
- if model.isPurchaseSwitch {
- // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
- // giftAIImage2.isHidden = false
- // giftAILabel2.isHidden = false
- // }
- discountYearly.isHidden = false
- sixMouthProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
- oneYearProLabel.textColor = NSColor.white
- switchCircleLeftConst.constant = 22
- value1InfoLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
- } else {
- giftAIImage2.isHidden = true
- giftAILabel2.isHidden = true
- discountYearly.isHidden = true
- sixMouthProLabel.textColor = NSColor.white
- oneYearProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
- switchCircleLeftConst.constant = 4
- value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
- }
-
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
- let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
- let isTrialPeriod_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isTrialPeriod ?? false
- let isSubscribed_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isSubscribed ?? false
- let isTrialPeriod_year = fourDevicesAllAccessPackNew12months_lite?.isTrialPeriod ?? false
- let isSubscribed_year = fourDevicesAllAccessPackNew12months_lite?.isSubscribed ?? false
- let introductoryPrice_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.product?.introductoryPrice
- let introductoryPrice_year = fourDevicesAllAccessPackNew12months_lite?.product?.introductoryPrice
-
- // 购买按钮
- if(isSubscribed_year) {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
- value1PurchaseButton.isEnabled = false
- } else {
- value1PurchaseButton.isEnabled = true
- if(model.isPurchaseSwitch == true) {
- if KMMemberInfo.shared.isLogin {
- if(!isTrialPeriod_year &&
- KMMemberInfo.shared.canTrail &&
- model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- } else {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- }
- } else {
- if(!isTrialPeriod_year &&
- model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- } else {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- }
- }
- } else {
- value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- }
- }
- value1PurchaseBtnLblBtn.isEnabled = value1PurchaseButton.isEnabled
- value1PurchaseBtnLbl.textColor = value1PurchaseBtnLblBtn.isEnabled ? NSColor.white : NSColor.white.withAlphaComponent(0.5)
- permanentPurchaseLblBtn.isEnabled = permanentPurchaseButton.isEnabled
- standardPlanPurchaseLblBtn.isEnabled = standardPlanPurchaseButton.isEnabled
- advancedPlanPurchaseLblBtn.isEnabled = advancedPlanPurchaseButton.isEnabled
- var averageMonthPrice: String? = nil
- var monthPrice: String? = nil
- var averageMonthPriceDiscount: String? = nil
- var monthPriceDiscount: String? = nil
- var allPrice: String? = nil
- let isOffers_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isOffers ?? false
- let isOffers_year = fourDevicesAllAccessPackNew12months_lite?.isOffers ?? false
-
- var introPrice: String? = nil
- var introAveragePrice: String? = nil
- if isOffers_newlyMonth {
- specialView1.isHidden = false
- averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersAveragePrice()
- monthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersPrice()
- averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
- monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
- introPrice = fourDevicesAllAccessPackNew6Months_lite?.introPrice()
- introAveragePrice = fourDevicesAllAccessPackNew6Months_lite?.introAveragePrice()
- } else if isOffers_year {
- averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.offersAveragePrice()
- monthPrice = fourDevicesAllAccessPackNew12months_lite?.offersPrice()
- averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
- monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
- introPrice = fourDevicesAllAccessPackNew12months_lite?.introPrice()
- introAveragePrice = fourDevicesAllAccessPackNew12months_lite?.introAveragePrice()
- } else {
- specialView1.isHidden = true
- if !model.isPurchaseSwitch {
- averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.averagePrice()
- monthPrice = fourDevicesAllAccessPackNew6Months_lite?.price()
- averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
- monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
- introPrice = fourDevicesAllAccessPackNew6Months_lite?.introPrice()
- introAveragePrice = fourDevicesAllAccessPackNew6Months_lite?.introAveragePrice()
- } else {
- averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.averagePrice()
- monthPrice = fourDevicesAllAccessPackNew12months_lite?.price()
- averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
- monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
- introPrice = fourDevicesAllAccessPackNew12months_lite?.introPrice()
- introAveragePrice = fourDevicesAllAccessPackNew12months_lite?.introAveragePrice()
- }
- }
-
- if let allAccessPackPermanent_lite = IAPProductsManager.default().allAccessPackPermanent_lite, allAccessPackPermanent_lite.isOffers {
- specialView.isHidden = false
- allPrice = allAccessPackPermanent_lite.offersPrice()
- } else {
- specialView.isHidden = true
- allPrice = IAPProductsManager.default().allAccessPackPermanent_lite?.price()
- }
-
- var off = 1 - (IAPProductsManager.default().allAccessPackPermanent_lite?.offers ?? 0)
- var offString = String(format: "%.f%%", off * 100)
- specialLabel.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
-
- if model.isPurchaseSwitch {
- off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.offers
- } else {
- off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.offers
- }
- offString = String(format: "%.f%%", off * 100)
- specialLabel1.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
-
- let image = NSImage(named: "KMImageNameCompareTagBG")
-
- specialImageView.image = image
- specialImageView1.image = image
- let showAveragePrice = KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice()
- // 商品是否有推介优惠
- let hasIntroPrice = (introPrice != nil && introPrice?.isEmpty == false)
- self.value1PurchaseDiscountBox.isHidden = true
- if model.isPurchaseSwitch { // 年订阅
- let iapProduct = fourDevicesAllAccessPackNew12months_lite
- if model.isShowSale { // 旧订阅优惠
- if showAveragePrice {
- value1PurchaseSubLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("12 months", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
- } else {
- // 是否为新用户
- let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
- if hasIntroPrice && isNewUser { // 推介优惠
- if showAveragePrice {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", introAveragePrice ?? "" , NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", introPrice ?? "", NSLocalizedString("12 months", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
- } else { // 促销优惠
- var useDiscountCode: String? = nil
- if discountType_ == .advancedYearSubscribeTrialingCancel {
- let discountCode = "4_devices_all_access_pack_12months_20250102"
- if let priceString = iapProduct?.discountPrice(withDiscountCode: discountCode), priceString.isEmpty == false {
- self.value1PurchaseDiscountBox.isHidden = false
-
- self.value1PurchaseDiscountView_.label.stringValue = String(format: NSLocalizedString("%@ OFF", comment: ""), _fetchDiscountNumber(70))
-
- useDiscountCode = discountCode
- }
- }
-
- if let data = iapProduct?.productPrice(withDiscountCode: useDiscountCode ?? ""), data.isEmpty == false {
- if showAveragePrice {
- let priceS = iapProduct?.productAveragePrice(withDiscountCode: useDiscountCode ?? "") ?? ""
- value1PurchaseLabel.stringValue = String(format: "%@/%@", priceS , NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", data, NSLocalizedString("12 months", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
- } else {
- if showAveragePrice {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = true
- billedTopConst.constant = 0
- }
- }
- }
- } else {
- let iapProduct = fourDevicesAllAccessPackNew6Months_lite
- if model.isShowSale { // [旧订阅][活动][可移除]
- if showAveragePrice {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("6mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
- } else {
- let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
- if hasIntroPrice && isNewUser { // 推介优惠
- if showAveragePrice {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", introAveragePrice ?? "" , NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", introPrice ?? "", NSLocalizedString("6mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
-
- if discountType_ == .newUserGift || discountType == .freeTrail {
- self.value1PurchaseDiscountBox.isHidden = false
- // let priceString = iapProduct?.introDiscountPrice() ?? "$10"
- self.value1PurchaseDiscountView_.label.stringValue = String(format: NSLocalizedString("%@ OFF", comment: ""), _fetchDiscountNumber(80))
- }
- } else { // 促销优惠
- var useDiscountCode: String? = nil
- if discountType_ == .advancedYearSubscribeTrialingCancel {
- let discountCode = "4_devices_all_access_pack_new_6month_20250102"
- if let priceString = iapProduct?.discountPrice(withDiscountCode: discountCode), priceString.isEmpty == false {
- self.value1PurchaseDiscountBox.isHidden = false
- self.value1PurchaseDiscountView_.label.stringValue = String(format: NSLocalizedString("%@ OFF", comment: ""), _fetchDiscountNumber(80))
-
- useDiscountCode = discountCode
- }
- }
-
- if let data = iapProduct?.productPrice(withDiscountCode: useDiscountCode ?? ""), data.isEmpty == false {
- if showAveragePrice {
- let priceS = iapProduct?.productAveragePrice(withDiscountCode: useDiscountCode ?? "") ?? ""
- value1PurchaseLabel.stringValue = String(format: "%@/%@", priceS , NSLocalizedString("mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", data, NSLocalizedString("6mon", comment: ""))
- value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = false
- billedTopConst.constant = 16
- } else {
- if showAveragePrice {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
- } else {
- value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
- }
- value1PurchaseOriPriceLbl.isHidden = true
- billedTopConst.constant = 0
- }
- }
- }
- }
-
- if self.discountYearly.image != nil { // 有活动
- self.value1PurchaseDiscountBox.isHidden = true
- }
-
- value1PurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
- value1PurchaseOriPriceLbl.textColor = NSColor(hex: "#FFE76A")
-
- value1PurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: value1PurchaseOriPriceLbl.stringValue, attributes: originalPriceAttri_)
- var tTips: String
- if model.isShowSale {
- tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
- } else {
- tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
- }
- if value1PurchaseBtnLbl.stringValue == NSLocalizedString("Free Trial", comment: "") {
- tTips = String(format: NSLocalizedString("Billed every 6 months at %@ after 7-day trial ends.", comment: ""), monthPrice ?? "")
- #if !VERSION_DMG
- if model.isPurchaseSwitch {
- if let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product {
- if #available(macOS 10.13.2, *) {
- let trialDays = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product?.introductoryPrice?.subscriptionPeriod.numberOfUnits
- tTips = String(
- format: NSLocalizedString("Billed every 12 months at %@ after %@-day trial ends.", comment: ""),
- monthPrice ?? "",
- "\(trialDays ?? 0)"
- )
- }
- }
- } else {
- if let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product {
- if #available(macOS 10.13.2, *) {
- let trialDays = fourDevicesAllAccessPackNew6Months_lite.introductoryPrice?.subscriptionPeriod.numberOfUnits
- tTips = String(
- format: NSLocalizedString("Billed every 6 months at %@ after %@-day trial ends.", comment: ""),
- monthPrice ?? "",
- "\(trialDays ?? 0)"
- )
- }
- }
- }
- #endif
- }
- if #available(macOS 10.13.2, *) {
- #if !VERSION_DMG
- if model.isPurchaseSwitch {
- if model.isShowSale {
- tTips = String(format: NSLocalizedString("%@ for the first year's subscription", comment: ""), monthPriceDiscount ?? "")
- } else {
- if let data = introPrice, data.isEmpty == false {
- tTips = String(format: NSLocalizedString("Auto-renew at %@/year after expiration. Cancel anytime (Tax Incl.)", comment: ""), monthPrice ?? "")
- } else {
- tTips = String(format: NSLocalizedString("Billed every 12 months at %@", comment: ""), monthPrice ?? "")
- }
- }
- } else {
- if model.isShowSale {
- tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
- } else {
- if let data = introPrice, data.isEmpty == false {
- tTips = String(format: NSLocalizedString("Auto-renew at %@/6-month after expiration. Cancel anytime (Tax Incl.)", comment: ""), monthPrice ?? "")
- } else {
- tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
- }
- }
- }
- #endif
- }
- value1PurchaseSubLabel.stringValue = String(format: NSLocalizedString("%@", comment: ""), tTips)
- value1PurchaseBtnLbl.font = NSFont.UbuntuBoldFontWithSize(16)
- #endif
- #else
- // AppStore 付费版
- // value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
- let fourDevicesAllAccessPack12months_pro = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro
- let standardAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro
- let advancedAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro
- let advancedAdd2DevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro
- // let pdfToOfficePackPermanent_pro = IAPProductsManager.default().pdfToOfficePackPermanent_pro
- let isTrialPeriod_year = fourDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
- let isTrialPeriod_standard = standardAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
- let isTrialPeriod_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
- let isTrialPeriod_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
- let isSubscribed_year = fourDevicesAllAccessPack12months_pro?.isSubscribed ?? false
- let isSubscribed_standard = standardAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
- let isSubscribed_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
- let isSubscribed_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isSubscribed ?? false
- let introductoryPrice_year = fourDevicesAllAccessPack12months_pro?.product?.introductoryPrice
- let introductoryPrice_standard = standardAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
- let introductoryPrice_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
- let introductoryPrice_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.product?.introductoryPrice
-
-
- #endif
- }
-
- @objc func reloadDataContent() {
- tableView.reloadData()
- }
-
- func addWaitingView(to view: NSView) {
- removeWaitingView(from: view)
- let waitingView = WaitingView(frame: view.bounds)
- waitingView.autoresizingMask = [.width, .height]
- view.addSubview(waitingView)
- waitingView.startAnimation()
- }
- func removeWaitingView(from view: NSView) {
- KMMainThreadExecute {
- for subview in view.subviews {
- if subview is WaitingView {
- subview.removeFromSuperview()
- break
- }
- }
- }
- }
- func showDiscount() {
- discountYearly.isHidden = true
- discountPermanent.isHidden = true
- discountPermanent2.isHidden = true
- discountPermanent.isHidden = true
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- if model.state != .dmg_Base { return }
- #else
- // AppStore 免费版本
- if model.state != .lite_Base { return }
- #endif
- #else
- // AppStore 付费版
- if model.state != .pro_Base { return }
- #endif
- let content = KMAdvertisementManager.manager.info.StoreUserRecovery?.content ?? []
- if content.count > 0 {
- for (index, item) in content.enumerated() {
- switch index {
- case 1:
- configureDiscountView(discountYearly, with: item)
- case 2:
- configureDiscountView(discountPermanent4, with: item)
- case 3:
- configureDiscountView(discountPermanent2, with: item)
- case 4:
- configureDiscountView(discountPermanent, with: item)
- default:
- break
- }
- }
- }
- }
- private func configureDiscountView(_ view: NSImageView, with itemInfo: KMAdvertisementItemInfo) {
- if KMAdvertisementManager.checkAdvertisementValid(itemInfo) {
- view.isHidden = false
- let urlString = KMAdvertisementModelTransition.transitionImagePath(image: itemInfo.image, highlight: false)
- if let url = URL(string: urlString) {
- view.image = KMAdvertisementImage.imageWithURL(url: url) { image in
- view.image = image
- }
- }
- } else {
- view.isHidden = true
- }
- }
-
- private func showAlert(message: String) {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = message
- alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
- alert.runModal()
- }
- private var alertingForRefreshUserInfo_ = false
- private var alertingCodeForRefreshUserInfo_: Int?
- private func handleVerificationFailure(msg: KMMemberProductResult?) {
- if self.alertingForRefreshUserInfo_ {
- KMPrint("刷新用户信息-Alert中。。。")
- return
- }
-
- if msg?.code == 500 {
- KMPrint("错误信息: One record is expected, but the query result is multiple records。。。")
- return
- }
-
- if msg?.code == alertingCodeForRefreshUserInfo_ {
- KMPrint("刷新用户信息-Alert中 重复Code 。。。")
- return
- }
-
- var message = msg?.msg ?? ""
- if !message.isEmpty {
- alertingForRefreshUserInfo_ = true
- alertingCodeForRefreshUserInfo_ = msg?.code
- KMMemberCenterManager.showAlert(code: .init(rawValue: msg?.code ?? 0), message: msg?.msg) { [weak self] resp, _ in
- DispatchQueue.main.async {
- self?.alertingForRefreshUserInfo_ = false
- // self?.alertingCodeForRefreshUserInfo_ = nil
- }
- }
- }
- }
-
- private func comparativeStatementHead() -> Void {
- value1PurchaseOriPriceLbl.isHidden = true
- standardPlanInfoDiscountBox.isHidden = true
- advancedPlanInfoDiscountBox.isHidden = true
- permanentInfoDiscountBox.isHidden = true
- advancedPurchaseOriPriceLbl.isHidden = true
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- if KMMemberInfo.shared.canTrail && model.state == .trial {
- advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
- }
- if model.state == .dmg_Base {
- if discountType_ == .newUserGift || discountType_ == .advancedYearSubscribeTrialingCancel {
- standardPlanInfoDiscountBox.isHidden = false
- advancedPlanInfoDiscountBox.isHidden = false
- permanentInfoDiscountBox.isHidden = false
-
- standardPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProStandard_dmg)
- advancedPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProAdvanced_dmg)
- permanentPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProPermanent_dmg)
- standardPlanInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProStandard_dmg, pointNum: 0, hasPrefix: false)
- advancedPlanInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProAdvanced_dmg, pointNum: 0, hasPrefix: false)
- permanentInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProPermanent_dmg, pointNum: 0, hasPrefix: false)
-
- standardPurchaseOriPriceLbl.isHidden = false
- standardPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProStandard_dmg), attributes: originalPriceAttri_)
- advancedPurchaseOriPriceLbl.isHidden = false
- advancedPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProAdvanced_dmg), attributes: originalPriceAttri_)
- permanentPurchaseOriPriceLbl.isHidden = false
- permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProPermanent_dmg), attributes: originalPriceAttri_)
- } else {
- standardPurchaseOriPriceLbl.isHidden = true
- advancedPurchaseOriPriceLbl.isHidden = true
- permanentPurchaseOriPriceLbl.isHidden = true
- standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
- permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
- }
- } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
- guard let productModels = model.dmgProductDatas?.listingProducts else { return }
- for productModel in productModels {
- if productModel.code == "advanced-annual-subscription" {
- model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
- guard let self = self else { return }
- guard let results: KMMemberProductResult = result else { return }
- guard let productModels2 = results.listingProducts else { return }
- for productModel2 in productModels2 {
- if productModel2.code == "advanced-annual-subscription" {
- self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
- }
- }
- }
- } else if productModel.code == "advanced-permanent-blackFive" {
- model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
- guard let self = self else { return }
- guard let results: KMMemberProductResult = result else { return }
- guard let productModels2 = results.listingProducts else { return }
- for productModel2 in productModels2 {
- if productModel2.code == "advanced-annual-subscription-blackFive" {
- self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
- }
- }
- }
- }
- }
- } else {
- advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
- }
- #else
- // AppStore 免费版本
- if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product, model.checkSubscriptionOffer(for: product) == .freeTrial {
-
- }
-
- var showCNY = false
- if let localeId = IAPProductsManager.default()?.allAccessPackPermanent_lite?.product?.priceLocale.identifier {
- // "zh_TW@currency=TWD"
- showCNY = localeId.contains("zh_CN") || localeId.contains("zh_TW")
- }
-
- self.permanentInfoDiscountView_.label.stringValue = String(format: NSLocalizedString("%@ OFF", comment: ""), _fetchDiscountNumber(83))
- if discountType_ == .newUserGift {
- permanentInfoDiscountBox.isHidden = false
- permanentPurchaseOriPriceLbl.isHidden = false
- // if showCNY {
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 778.00", attributes: originalPriceAttri_)
- // } else{
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
- // }
- let iapProduct = IAPProductsManager.default()?.allAccessPackPermanent_lite
- let priceString = iapProduct?.priceByMultiplying(byOff: 100.0/83) ?? "$ 119.99"
- permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: priceString, attributes: originalPriceAttri_)
- } else if discountType_ == .advancedYearSubscribeTrialingCancel {
- permanentInfoDiscountBox.isHidden = false
- permanentPurchaseOriPriceLbl.isHidden = false
- // if showCNY {
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 778.00", attributes: originalPriceAttri_)
- // } else{
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
- // }
- let iapProduct = IAPProductsManager.default()?.allAccessPackPermanent_lite
- let priceString = iapProduct?.priceByMultiplying(byOff: 100.0/83) ?? "$ 119.99"
- permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: priceString, attributes: originalPriceAttri_)
- } else {
- let iapProduct = IAPProductsManager.default()?.fourDevicesAllAccessPackNew6Months_lite
- let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
- if isNewUser {
- permanentInfoDiscountBox.isHidden = false
- permanentPurchaseOriPriceLbl.isHidden = false
- // if showCNY {
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 778.00", attributes: originalPriceAttri_)
- // } else{
- // permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
- // }
- let iapProduct = IAPProductsManager.default()?.allAccessPackPermanent_lite
- let priceString = iapProduct?.priceByMultiplying(byOff: 100.0/83) ?? "$ 119.99"
- permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: priceString, attributes: originalPriceAttri_)
- } else {
- permanentPurchaseOriPriceLbl.isHidden = true
- }
- }
-
- if self.discountPermanent4.isHidden == false { // 有活动
- permanentInfoDiscountBox.isHidden = true
- }
-
- // 重新刷新 UI
- self.refreshPurchaseSwitch()
- #endif
- #else
- // AppStore 付费版
- advancedPurchaseOriPriceLbl.isHidden = true
- permanentPurchaseOriPriceLbl.isHidden = true
- #endif
- }
-
- private func _trackComparisonEvent(params: [String : String]) {
- #if VERSION_FREE
- #if VERSION_DMG
- #else
- FMTrackEventManager.defaultManager.trackEvent(event: "ComparisonTableNew", withProperties: params)
- #endif
- #endif
- }
-
- private func _loginAfterAction(type: KMSubscribeWaterMarkType?) {
- let info = KMMemberInfo.shared
- var expired = info.vip_status == 2 || info.vip_status == 4
- let state = info.userScenarioType
- let platforms = info.userPlatforms()
- let vip_levels = info.vip_levels
- let vip_paymentModel = info.vip_paymentModel
-
- if platforms.contains("mac") == false && vip_paymentModel == "1" {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
- alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
- alert.runModal()
-
- window?.close()
- } else if platforms.count == 1 && platforms.first == "ios" && info.vip_levels == "3" && vip_paymentModel == "2" { // ios单平台高级版永久账户
- KMMemberInfo.shared.productCompareShow()
- return
- } else if platforms.count == 1 && platforms.first == "mac" && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac 单平台高级版永久账户
- // 关闭比较表,可以直接使用高级功能
- window?.close()
- return
- } else if platforms.count == 2 && platforms.contains("windows") && platforms.contains("mac") && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac & Windows 双平台高级永久账户
- // 关闭比较表,可以直接使用高级功能
- window?.close()
- return
- } else if platforms.count == 1 && platforms.first == "android" && info.vip_levels == "3" && vip_paymentModel == "1" && info.vip_cycle == 1 { // Android单平台高级版月订阅账户
- // 关闭比较表,可以直接使用高级功能
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
- alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
- alert.runModal()
-
- window?.close()
- return
-
- } else if platforms.count == 4 && vip_levels == "2" && vip_paymentModel == "1" && info.vip_cycle == 4 { // 全平台标准版年订阅账户 不支持升级,关闭比较表,可以直接使用非转档的高级功能
- if type?.isConvertType() == false {
- self.closeWindow()
- return
- }
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
- alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
- alert.runModal()
-
- self.closeWindow()
- return
- } else {
- self.closeWindow()
- return
- }
- }
-
- private func _trackPurchaseCampaignEvent() {
- if self.discountType == .newUserGift {
- self.trackEvent(eventName: "Purchase_Campaign", params: ["Campaign_NewUser":"Tbr_Coupon"], platform: .firebase)
- } else if self.discountType == .freeTrail {
- self.trackEvent(eventName: "Purchase_Campaign", params: ["Campaign_NewUser":"Tbr_FreeTrial"], platform: .firebase)
- } else if self.discountType_ == .advancedYearSubscribeTrialingCancel {
- self.trackEvent(eventName: self.kEventName, params: self.kEventParams, platform: .firebase)
- }
- }
-
- private func _appstoreCanPurchase(product: IAPProduct?) -> Bool {
- #if VERSION_FREE
- if discountType == .advancedYearSubscribeTrialingCancel {
- if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite ||
- product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
- #if VERSION_DMG
- #else
- if KMMemberInfo.shared.isLogin == false {
- let iapProduct = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
- let result = IAPReceiptTool.isFreeTrailing(with: IAPProductsManager.default().receiptModel, withProductId: iapProduct?.product?.productIdentifier)
- if result {
- showAlert(message: NSLocalizedString("You are in a 7-day free trial. Please purchase the product after it expires.", comment: ""))
- return false
- }
- } else {
- let member = KMMemberInfo.shared
- if member.is_advanced_year_subscribe() && member.is_trailing() {
- showAlert(message: NSLocalizedString("You are in a 7-day free trial. Please purchase the product after it expires.", comment: ""))
- return false
- }
- }
- #endif
- }
- }
- #endif
- return true
- }
-
- private func _dmgCanPurchase(state: KMCompareTableType, tag: Int) -> Bool {
- let isStandardAnnualSubscription = tag == 1
- if state == .dmg_Base && isStandardAnnualSubscription && discountType == .advancedYearSubscribeTrialingCancel {
- let member = KMMemberInfo.shared
- if member.is_advanced_year_subscribe() && member.is_trailing() {
- showAlert(message: NSLocalizedString("You are in a 7-day free trial. Please purchase the product after it expires.", comment: ""))
- return false
- }
- }
- return true
- }
-
- private func _appstorePurchaseGetProduct(state: KMCompareTableType, tag: Int, isPurchaseSwitch: Bool) -> IAPProduct? {
- var product: IAPProduct?
- if state == .lite_Base {
- if tag == 0 {
- if isPurchaseSwitch {
- product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
- } else {
- product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
- }
- } else if tag == 3 {
- product = IAPProductsManager.default().allAccessPackPermanent_lite
- } else {
- product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
- }
- } else if state == .lite_MacWindows {
- if tag == 2 {
- let platforms = KMMemberInfo.shared.vip_platforms
- let platformsArray = platforms
- .components(separatedBy: ",")
- .map { $0.trimmingCharacters(in: .whitespaces) }
- if KMMemberInfo.shared.userScenarioType == .lite_type5 {
- if platformsArray.count == 1 {
- product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
- } else if platformsArray.count == 2 {
- product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
- }
- } else {
- if platformsArray.count == 1 {
- product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
- } else if platformsArray.count == 2 {
- product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
- } else {
- product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
- }
- }
- }
- }
- return product
- }
-
- // 获取 Apple 凭证模型
- private func _fetchReceiptModel() -> IAPReceiptModel? {
- return IAPProductsManager.default().receiptModel
- }
-
- private func _fetchDiscountNumber(_ num: Int) -> String {
- if num > 100 || num < 0 {
- return ""
- }
- if NSLocalizedString("USD", comment: "") == "USD" {
- return "\(100-num)%"
- } else {
- if num % 10 == 0 {
- return "\(num/10)"
- }
- return "\(num)"
- }
- }
-
- // MARK: Button Actions
-
- @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
- if model.isPurchaseSwitch {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
- } else {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
- }
-
- if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
- var product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
- if model.isPurchaseSwitch {
- product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
- }
- let type = subscribeType
- KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
- if KMMemberInfo.shared.isLogin == false {
- return
- }
-
- let info = KMMemberInfo.shared
- let expired = info.vip_status == 2 || info.vip_status == 4
- if info.vip_levels == "1" || expired {
- if self.model.isPurchaseSwitch { // 免费账户/订阅过期账户
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: self.model.isCancelAutoRenew)
- } else {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: self.model.isCancelAutoRenew)
- }
- return
- } else {
- self._loginAfterAction(type: type)
- }
- }
- return
- }
- if KMMemberInfo.shared.validFlag == "5" {
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .signouting
- } else {
- if model.isPurchaseSwitch {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: model.isCancelAutoRenew)
- } else {
- IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: model.isCancelAutoRenew)
- }
-
- addWaitingView(to: window?.contentView ?? NSView())
- FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_6Mon"])
- if model.isShowSale {
- kEventTag = 1
- if model.isPurchaseSwitch {
- trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12Mon"], platform: .AppCenter)
- } else {
- trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6Mon"], platform: .AppCenter)
- }
- }
- }
- }
- func showDiscountToSaveWindow() {
- guard KMDiscountToSaveWindowController.needShow() else { return }
-
- guard let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
- let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.image, highlight: true)) else { return }
-
- addWaitingView(to: window?.contentView ?? NSView())
- KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
- guard let self = self else { return }
- self.removeWaitingView(from: self.window?.contentView ?? NSView())
- self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_PromotionalOffer"], platform: .AppCenter)
-
- let winC = KMDiscountToSaveWindowController(windowNibName: "KMDiscountToSaveWindowController")
- self.discountToSaveWinC = winC
- self.window?.beginSheet(winC.window!) { _ in }
-
- winC.imgIv.image = image
- winC.itemClick = { idx in
- self.window?.endSheet(self.discountToSaveWinC?.window ?? NSWindow())
- self.discountToSaveWinC = nil
-
- if idx == 2 {
- self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Subscribe"], platform: .AppCenter)
- } else if idx == 1 {
- self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Cancel"], platform: .AppCenter)
- }
- }
- }
- }
- @IBAction func buttonItemClicked_Restore(_ sender: Any) {
- model.productRestore()
- addWaitingView(to: window?.contentView ?? NSView())
- }
- @IBAction func buttonItemClicked_Upgrade(_ sender: Any) {
- NSWorkspace.shared.open(URL(string: "macappstore://apps.apple.com/app/id825459243?mt=12")!)
- FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Premium"])
- }
- @IBAction func privacyPolicyAction(_ sender: NSButton) {
- model.privacyPolicyAction()
- }
- @IBAction func termOfSerAction(_ sender: NSButton) {
- model.termOfSerAction()
- }
- @IBAction func buttonItemClicked_LicenseUpgrade(_ sender: Any) {
- IAPProductsManager.default().make(IAPProductsManager.default().allAccessPackPermanent_lite)
- addWaitingView(to: window?.contentView ?? NSView())
- FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Permanent"])
-
- trackEvent_free(eventName: "ComparisonTableNew", params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"], platform: .AppCenter)
- }
- @IBAction func buttonItemClicked_AboutSubscriptions(_ sender: Any) {
- let tMessage = """
- Subscription plans:
- Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)
-
- - Subscriptions will be charged through your iTunes account at the confirmation of purchase.
- - Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.
- - Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.
- - You may manage your subscriptions in your iTunes Account Settings after purchase.
- - No cancellation of the current subscription is allowed during an active subscription period.
- - Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service
- - Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy
- """
-
- let alert = NSAlert()
- alert.alertStyle = .informational
- alert.messageText = NSLocalizedString(tMessage, comment: "")
- alert.runModal()
- }
- @IBAction func buttonItemClicked_CloseWindow(_ sender: Any) {
- close()
- }
- @objc func switchAction(_ sender: NSButton) {
- model.isPurchaseSwitch.toggle()
- }
-
- @IBAction func appstorePurchaseAction(_ sender: NSButton) {
- if KMMemberInfo.shared.validFlag == "5" {
- KMMemberPromptWC.shared.showWindow(nil)
- KMMemberPromptWC.shared.tipType = .signouting
- } else {
- #if !VERSION_DMG
- // addWaitingView(to: window?.contentView ?? NSView())
- #endif
- let product = self._appstorePurchaseGetProduct(state: model.state, tag: sender.tag, isPurchaseSwitch: model.isPurchaseSwitch)
- if product == IAPProductsManager.default().allAccessPackPermanent_lite {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"])
- } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
- } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
- }
-
- let type = subscribeType
- if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
- KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
- if KMMemberInfo.shared.isLogin == false {
- return
- }
-
- let info = KMMemberInfo.shared
- let expired = info.vip_status == 2 || info.vip_status == 4
- if info.vip_levels == "1" || expired {
- self.model.appstorePurchaseAction(sender.tag, discountType: self.discountType_) { [weak self] success, msg in
-
- }
- return
- } else {
- self._loginAfterAction(type: type)
- return
- }
- }
- return
- }
- // addWaitingView(to: window?.contentView ?? NSView())
- #if VERSION_DMG
- if _dmgCanPurchase(state: model.state, tag: sender.tag) == false {
- return
- }
- #else
- if _appstoreCanPurchase(product: product) == false {
- return
- }
- #endif
- model.appstorePurchaseAction(sender.tag, discountType: discountType_) { [weak self] success, msg in
- guard let self = self else { return }
- }
- #if VERSION_DMG
- close()
- #endif
- }
- }
-
- @objc func closeAction() {
- _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_Cancel"])
-
- self.window?.close()
- }
-
- // MARK: - InAppPurchaseManager Notification
- @objc func IAPProductFailedNotification(_ notification: Notification) {
- removeWaitingView(from: window?.contentView ?? NSView())
- }
-
- @objc func IAPProductPurchasedNotification(_ notification: Notification) {
- KMMainThreadExecute {
- self.removeWaitingView(from: self.window?.contentView ?? NSView())
- self.reloadData()
-
- if KMMemberInfo.shared.isLogin {
-
- } else {
- if let _ = KMLoginWindowsController.shared.subscribeType { // 付费->比较表->购买回来后 需要关闭登陆窗口
- KMLoginWindowsController.shared.closeWindow()
- }
- }
- }
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- #else
- // AppStore 免费版本
- if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
- if kEventTag == 1 {
- trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6MonthPaid"], platform: .AppCenter)
- }
- } else if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
- if kEventTag == 1 {
- trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12MonthPaid"], platform: .AppCenter)
- }
- }
- #endif
- #else
- // AppStore 付费版
- #endif
- }
- @objc func IAPProductLoadedNotification(_ notification: Notification) {
- KMMainThreadExecute {
- self.reloadData()
- }
- }
-
- @objc func IAPProductRestoreFinishedNotification(_ notification: Notification) {
- KMMainThreadExecute {
- self.removeWaitingView(from: self.window?.contentView ?? NSView())
- self.reloadData()
- }
- }
-
- @objc func IAPProductRestoreFailedNotification(_ notification: Notification) {
- removeWaitingView(from: window?.contentView ?? NSView())
- }
-
- @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
- KMMainThreadExecute {
- self.removeWaitingView(from: self.window?.contentView ?? NSView())
- self.reloadData()
- DispatchQueue.global().async { [weak self] in
- guard let self = self else { return }
- if KMMemberInfo.shared.isLogin {
- self.model.appStoreEquityVerification(notification) { success, msg in
- DispatchQueue.main.async {
- if success {
- // self.showAlert(message: NSLocalizedString("Binding Interest Success!", comment: ""))
-
- KMUserInfoVCModel().refreshUserInfo { success, msg,dic in
- if(success) {
- // 签到
- KMCheckInManager.default.checkIn(refreshData: true, callback: nil)
-
- NotificationCenter.default.post(name: NSNotification.Name.KMMemberInfoChange, object: self)
-
- KMCancelSubscribeSuccessWindowController.shared.saveRecord()
-
- self._trackPurchaseCampaignEvent()
- }
- }
-
- KMMemberCenterManager.judgeTrailCancel { success, resultModel, error in
- if success {
- KMCheckInManager.default.trailCancel = resultModel?.result ?? false
- }
- }
-
- self.window?.close()
- } else {
- self.handleVerificationFailure(msg: msg)
- }
- }
- }
- }
- }
- }
- }
-
- @objc func themeChanged(_ notification: Notification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.box.fillColor = KMAppearance.Layout.l1Color()
- self.labelbox.fillColor = .clear
- self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
- self.textView.backgroundColor = .clear
- self.textView.textColor = NSColor.white.withAlphaComponent(0.5)
- self.value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- self.permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
- }
- }
-
- // MARK: - Bind Method
-
- func bindViewModel() -> Void {
- model.$state
- .receive(on: RunLoop.main)
- .sink { [weak self] newValue in
-
- }
- .store(in: &cancellables)
- model.$isPurchaseSwitch
- .receive(on: RunLoop.main)
- .sink { [weak self] newValue in
- self?.reloadDataContent()
- #if VERSION_FREE
- #if VERSION_DMG
- // DMG
- #else
- // AppStore 免费版本
- self?.refreshPurchaseSwitch()
- #endif
- #else
- // AppStore 付费版
- #endif
- }
- .store(in: &cancellables)
- }
- }
- // MARK: - NSTableViewDelegate, NSTableViewDataSource
- extension KMProductCompareWC: NSTableViewDelegate, NSTableViewDataSource {
- func numberOfRows(in tableView: NSTableView) -> Int {
- return model.dataSource.count
- }
- func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
- let object = model.dataSource[row]
-
- if let stringObject = object as? String {
- if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
- cellView.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
- if stringObject == "Membership Benefits" {
- cellView.leftImageView?.isHidden = false
- cellView.textField?.textColor = NSColor(named: "6D4D09") ?? .gray
- } else {
- cellView.leftImageView?.isHidden = true
- cellView.textField?.textColor = NSColor(named: "0E1114") ?? .white
- }
- cellView.textfieldLeft.constant = cellView.leftImageView!.isHidden ? 32.0 : 62.0
- if model.state == .dmg_Base {
- cellView.selectBoxLeft.constant = 352.0 + 149.5 + 149.5
- cellView.selectBoxWidth.constant = 149.5
- } else if model.state == .dmg_Upgrades1 {
- cellView.selectBoxLeft.constant = 352.0
- cellView.selectBoxWidth.constant = 320.0
- } else if model.state == .dmg_Upgrades2 {
- cellView.selectBoxLeft.constant = 352.0
- cellView.selectBoxWidth.constant = 320.0
- } else if model.state == .lite_Base {
- cellView.selectBoxLeft.constant = 352.0 + 179.0
- cellView.selectBoxWidth.constant = 240.0
- } else if model.state == .lite_MacWindows {
- cellView.selectBoxLeft.constant = 352.0
- cellView.selectBoxWidth.constant = 320.0
- } else if model.state == .pro_Base {
- cellView.selectBoxLeft.constant = 352.0
- cellView.selectBoxWidth.constant = 299.0
- } else if model.state == .pro_Advanced {
- cellView.selectBoxLeft.constant = 352.0
- cellView.selectBoxWidth.constant = 320.0
- } else {
- // model.state == .trial
- cellView.selectBoxLeft.constant = 352.0 + 179.0
- cellView.selectBoxWidth.constant = 240.0
- }
- return cellView
- }
- } else if let arrayObject = object as? [String] {
- if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
-
- let value1 = arrayObject.indices.contains(0) ? arrayObject[0] : ""
- let value2 = arrayObject.indices.contains(1) ? arrayObject[1] : ""
- let value3 = arrayObject.indices.contains(2) ? arrayObject[2] : ""
- let value4 = arrayObject.indices.contains(3) ? arrayObject[3] : ""
- let value5 = arrayObject.indices.contains(4) ? arrayObject[4] : ""
- let value6 = arrayObject.indices.contains(5) ? arrayObject[5] : ""
- cellView.textField?.stringValue = NSLocalizedString(value1, comment: "")
- cellView.lineBox?.isHidden = false
-
- if row + 1 == model.dataSource.count || model.dataSource[row + 1] is String {
- cellView.lineBox?.isHidden = true
- }
- checkOrNot(cellView)
- cellView.boxBottomConst?.constant = (row + 2 == model.dataSource.count) ? 0 : -4
- updateCellView(cellView, value1: value2, value2: value3, value3: value4, value4: value5, value5: value6)
- return cellView
- }
- } else if object is [String: Any] {
- if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableEmptyCell"), owner: self) as? KMProductCompareTableEmptyCell {
- return cellView
- }
- }
- return nil
- }
- func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
- let object = model.dataSource[row]
- var cellView: NSTableCellView?
- if let stringObject = object as? String {
- if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
- cell.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
- cellView = cell
- }
- } else if let arrayObject = object as? [String] {
- if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
- cell.textField?.stringValue = NSLocalizedString(arrayObject[0], comment: "")
- cellView = cell
- }
- } else if object is [String: Any] {
- return 40
- }
- if let view = cellView {
- view.layoutSubtreeIfNeeded()
- return view.frame.size.height
- } else {
- return 44
- }
- }
- private func updateCellView(_ cellView: KMProductCompareTableCell, value1: String, value2: String, value3: String, value4: String, value5: String) {
- if model.state == .dmg_Base {
- configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- configureCellView(cellView, value: value2, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
- configureCellView(cellView, value: value3, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
- configureCellView(cellView, value: value4, label: cellView.value4Label, imageView: cellView.value4ImageView, platformsBox: cellView.platformsBox4)
- } else if model.state == .dmg_Upgrades1 {
- configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- } else if model.state == .dmg_Upgrades2 {
- configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- } else if model.state == .lite_Base {
- configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
- configureCellView(cellView, value: value4, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
- } else if model.state == .lite_MacWindows {
- configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- } else if model.state == .pro_Base {
- configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- configureCellView(cellView, value: value5, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
- } else if model.state == .pro_Advanced {
- configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- } else {
- // model.state == .trial
- configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
- configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
- }
- }
- private func configureCellView(_ cellView: KMProductCompareTableCell, value: String, label: NSTextField?, imageView: NSImageView?, platformsBox: NSBox?) {
- platformsBox?.isHidden = true
- label?.isHidden = false
- imageView?.isHidden = false
- switch value {
- case "X":
- label?.stringValue = ""
- imageView?.image = NSImage(named: "compare_nosupport")
- case "✓":
- label?.stringValue = ""
- imageView?.image = NSImage(named: "compare_support")
- case "∞":
- label?.stringValue = ""
- imageView?.image = NSImage(named: "compare_00")
- default:
- if value == "mac, windows, ios, android" ||
- value == "mac, windows" ||
- value == "mac" {
- platformsBox?.isHidden = false
- label?.isHidden = true
- imageView?.isHidden = true
- if value == "mac, windows, ios, android" {
- // platformsBox?.contentView = platformsView4
- } else if value == "mac, windows" {
- platformsBox?.contentView = platformsView2
- } else if value == "mac" {
- platformsBox?.contentView = platformsView1
- }
- } else {
- label?.stringValue = NSLocalizedString(value, comment: "")
- imageView?.image = nil
- }
- }
- }
-
- private func checkOrNot(_ cellView: KMProductCompareTableCell) {
- cellView.selectBox1.isHidden = true
- cellView.selectBox2.isHidden = true
- cellView.selectBox3.isHidden = true
- cellView.selectBox4.isHidden = true
- cellView.cellView1.isHidden = true
- cellView.cellView2.isHidden = true
- cellView.cellView3.isHidden = true
- cellView.cellView4.isHidden = true
- if model.state == .dmg_Base {
- cellView.selectBox3.isHidden = false
- cellView.cellView1.isHidden = false
- cellView.cellView2.isHidden = false
- cellView.cellView3.isHidden = false
- cellView.cellView4.isHidden = false
- cellView.viewWidth1.constant = 149.5
- cellView.viewWidth2.constant = 149.5
- cellView.viewWidth3.constant = 149.5
- cellView.viewWidth4.constant = 149.5
- } else if model.state == .dmg_Upgrades1 {
- cellView.selectBox1.isHidden = false
- cellView.cellView1.isHidden = false
- cellView.viewWidth1.constant = 320.0
- } else if model.state == .dmg_Upgrades2 {
- cellView.selectBox1.isHidden = false
- cellView.cellView1.isHidden = false
- cellView.viewWidth1.constant = 320.0
- } else if model.state == .lite_Base {
- cellView.selectBox2.isHidden = false
- cellView.cellView1.isHidden = false
- cellView.cellView2.isHidden = false
- cellView.cellView3.isHidden = false
- cellView.viewWidth1.constant = 179.0
- cellView.viewWidth2.constant = 240.0
- cellView.viewWidth3.constant = 240.0
- } else if model.state == .lite_MacWindows {
- cellView.selectBox1.isHidden = false
- cellView.viewWidth1.constant = 320.0
- cellView.cellView1.isHidden = false
- } else if model.state == .pro_Base {
- cellView.selectBox1.isHidden = false
- cellView.viewWidth1.constant = 299.0
- cellView.cellView1.isHidden = false
- cellView.cellView2.isHidden = false
- cellView.viewWidth2.constant = 299.0
- } else if model.state == .pro_Advanced {
- cellView.selectBox1.isHidden = false
- cellView.viewWidth1.constant = 320.0
- cellView.cellView1.isHidden = false
- } else {
- // model.state == .trial
- cellView.cellView1.isHidden = false
- cellView.cellView2.isHidden = false
- cellView.selectBox2.isHidden = false
- cellView.viewWidth1.constant = 179.0
- cellView.viewWidth2.constant = 240.0
- }
- }
- }
- class KMProductCompareTableCell: NSTableCellView {
- @IBOutlet weak var bgColorView: NSView!
- @IBOutlet @objc weak var cellView1: NSView!
- @IBOutlet @objc weak var cellView2: NSView!
- @IBOutlet @objc weak var cellView3: NSView!
- @IBOutlet @objc weak var cellView4: NSView!
- @IBOutlet weak var value1Label: NSTextField!
- @IBOutlet weak var value2Label: NSTextField!
- @IBOutlet weak var value3Label: NSTextField!
- @IBOutlet weak var value4Label: NSTextField!
- @IBOutlet weak var value1ImageView: NSImageView!
- @IBOutlet weak var value2ImageView: NSImageView!
- @IBOutlet weak var value3ImageView: NSImageView!
- @IBOutlet weak var value4ImageView: NSImageView!
- @IBOutlet weak var lineBox: NSBox!
- @IBOutlet weak var boxBottomConst: NSLayoutConstraint!
- @IBOutlet @objc weak var platformsBox1: NSBox!
- @IBOutlet @objc weak var platformsBox2: NSBox!
- @IBOutlet @objc weak var platformsBox3: NSBox!
- @IBOutlet @objc weak var platformsBox4: NSBox!
- @IBOutlet @objc weak var selectBox1: NSBox!
- @IBOutlet @objc weak var selectBox2: NSBox!
- @IBOutlet @objc weak var selectBox3: NSBox!
- @IBOutlet @objc weak var selectBox4: NSBox!
- @IBOutlet weak var viewWidth1: NSLayoutConstraint!
- @IBOutlet weak var viewWidth2: NSLayoutConstraint!
- @IBOutlet weak var viewWidth3: NSLayoutConstraint!
- @IBOutlet weak var viewWidth4: NSLayoutConstraint!
- override func awakeFromNib() {
- super.awakeFromNib()
-
- bgColorView.wantsLayer = true
- updateViewColor()
-
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(themeChanged(_:)),
- name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
- object: nil
- )
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- @objc func themeChanged(_ notification: Notification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateViewColor()
- }
- }
- private func updateViewColor() {
- var textColor = NSColor(red: 68.0 / 255.0, green: 68.0 / 255.0, blue: 68.0 / 255.0, alpha: 1.0)
- var subtextColor = NSColor(red: 141.0 / 255.0, green: 141.0 / 255.0, blue: 141.0 / 255.0, alpha: 1.0)
- var lineColor = NSColor(red: 204.0 / 255.0, green: 204.0 / 255.0, blue: 204.0 / 255.0, alpha: 0.4)
-
- if let layer = bgColorView.layer {
- if KMAppearance.isDarkMode() {
- layer.backgroundColor = NSColor(red: 24.0 / 255.0, green: 22.0 / 255.0, blue: 31.0 / 255.0, alpha: 1.0).cgColor
- textColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.8)
- subtextColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.6)
- lineColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.15)
- } else {
- layer.backgroundColor = NSColor(red: 247.0 / 255.0, green: 245.0 / 255.0, blue: 1.0, alpha: 1.0).cgColor
- }
- }
-
- value1Label.textColor = subtextColor
- value2Label.textColor = subtextColor
- value3Label.textColor = subtextColor
- value4Label.textColor = subtextColor
- lineBox.fillColor = lineColor
- textField?.textColor = textColor
- }
- }
- class KMProductCompareTableHeaderCell: NSTableCellView {
- @IBOutlet weak var contentView: NSView?
- @IBOutlet weak var leftImageView: NSImageView?
- @IBOutlet weak var textfieldLeft: NSLayoutConstraint!
- @IBOutlet weak var selectBoxLeft: NSLayoutConstraint!
- @IBOutlet weak var selectBoxWidth: NSLayoutConstraint!
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- override func awakeFromNib() {
- super.awakeFromNib()
- contentView?.wantsLayer = true
- updateViewColor()
-
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(themeChanged(_:)),
- name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
- object: nil
- )
- }
- @objc private func themeChanged(_ notification: Notification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateViewColor()
- }
- }
- private func updateViewColor() {
- if KMAppearance.isDarkMode() {
- contentView?.layer?.backgroundColor = NSColor(red: 40/255, green: 38/255, blue: 47/255, alpha: 1).cgColor
- } else {
- contentView?.layer?.backgroundColor = NSColor(red: 237/255, green: 231/255, blue: 255/255, alpha: 1).cgColor
- }
- textField?.textColor = KMAppearance.Layout.h0Color()
- textField?.font = NSFont.boldSystemFont(ofSize: 14.0)
- }
- }
- class KMProductCompareTableEmptyCell: NSTableCellView {
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.wantsLayer = true
- updateViewColor()
-
- DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
- }
-
- deinit {
- DistributedNotificationCenter.default.removeObserver(self)
- }
-
- @objc private func themeChanged(_ notification: Notification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateViewColor()
- }
- }
-
- private func updateViewColor() {
- if KMAppearance.isDarkMode() {
- self.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1.0).cgColor
- } else {
- self.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1.0, alpha: 1.0).cgColor
- }
- }
- }
|