KMProductCompareWC.swift 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  1. //
  2. // KMProductCompareWC.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/11/6.
  6. //
  7. import Cocoa
  8. import Combine
  9. @objc enum KMDiscountType: UInt {
  10. case none = 0
  11. case newUserGift // 新手活动
  12. case advancedYearSubscribeTrialingCancel // 高级年订阅 试用退订
  13. case freeTrail // 免费试用
  14. }
  15. @objcMembers class KMProductCompareWC: NSWindowController {
  16. @IBOutlet @objc weak var tableView: NSTableView!
  17. @IBOutlet @objc weak var titleLabel: NSTextField!
  18. @IBOutlet @objc weak var topMainBox: NSBox!
  19. @IBOutlet @objc weak var topMainView: NSView!
  20. @IBOutlet @objc weak var topsubBox1: NSBox!
  21. @IBOutlet @objc weak var topSelectBox1: NSBox!
  22. @IBOutlet @objc weak var topsubBox2: NSBox!
  23. @IBOutlet @objc weak var topSelectBox2: NSBox!
  24. @IBOutlet @objc weak var topsubBox3: NSBox!
  25. @IBOutlet @objc weak var topSelectBox3: NSBox!
  26. @IBOutlet @objc weak var topsubBox4: NSBox!
  27. @IBOutlet @objc weak var topSelectBox4: NSBox!
  28. @IBOutlet weak var topsubBoxWidth1: NSLayoutConstraint!
  29. @IBOutlet weak var topsubBoxWidth2: NSLayoutConstraint!
  30. @IBOutlet weak var topsubBoxWidth3: NSLayoutConstraint!
  31. @IBOutlet weak var topsubBoxWidth4: NSLayoutConstraint!
  32. @IBOutlet @objc weak var switchLabel: NSTextField!
  33. // @IBOutlet @objc weak var switchButton: NSButton!
  34. @IBOutlet @objc weak var freeInfoView: NSView!
  35. @IBOutlet @objc weak var freeInfoLabel: NSTextField!
  36. @IBOutlet @objc weak var value1InfoView: NSView!
  37. // @IBOutlet @objc weak var value1InfoBox: NSBox!
  38. @IBOutlet @objc weak var value1InfoTypeBox: NSBox!
  39. @IBOutlet @objc weak var sixMouthProLabel: NSTextField!
  40. @IBOutlet @objc weak var oneYearProLabel: NSTextField!
  41. @IBOutlet weak var backgroundImage1: NSImageView!
  42. @IBOutlet @objc weak var switchBox: NSBox!
  43. @IBOutlet @objc weak var switchBtn: NSButton!
  44. @IBOutlet @objc weak var switchCircleView: NSView!
  45. @IBOutlet @objc weak var switchCircleLeftConst: NSLayoutConstraint!
  46. @IBOutlet @objc weak var saleBox: NSBox!
  47. @IBOutlet @objc weak var saleIv: NSImageView!
  48. @IBOutlet @objc weak var saleLabel: NSTextField!
  49. @IBOutlet @objc weak var value1InfoLabel: NSTextField!
  50. @IBOutlet @objc weak var value1PurchaseLabel: NSTextField!
  51. @IBOutlet @objc weak var value1PurchaseSubLabel: NSTextField!
  52. @IBOutlet @objc weak var value1PurchaseButton: KMCustomButton!
  53. @IBOutlet @objc weak var value1PurchaseBtnLbl: NSTextField!
  54. @IBOutlet @objc weak var value1PurchaseOriPriceLbl: NSTextField!
  55. @IBOutlet @objc weak var value1PurchaseBtnLblBtn: NSButton!
  56. // 标准版年订阅
  57. @IBOutlet @objc weak var standardPlanInfoView: NSView!
  58. @IBOutlet @objc weak var standardPlanInfoLabel: NSTextField!
  59. @IBOutlet @objc weak var standardPlanPurchaseLabel: NSTextField!
  60. @IBOutlet @objc weak var standardPlanPurchaseSubLabel: NSTextField!
  61. @IBOutlet @objc weak var standardPlanPurchaseButton: NSButton!
  62. @IBOutlet @objc weak var standardPlanPurchaseLbl: NSTextField!
  63. @IBOutlet @objc weak var standardPlanPurchaseLblBtn: NSButton!
  64. @IBOutlet @objc weak var standardPlanPurchaseSubLabel2: NSTextField!
  65. @IBOutlet @objc weak var standardPurchaseOriPriceLbl: NSTextField!
  66. // 高级版年订阅
  67. @IBOutlet @objc weak var advancedPlanInfoView: NSView!
  68. @IBOutlet @objc weak var advancedPlanInfoLabel: NSTextField!
  69. @IBOutlet @objc weak var advancedPlanPurchaseLabel: NSTextField!
  70. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel: NSTextField!
  71. @IBOutlet @objc weak var advancedPlanPurchaseButton: NSButton!
  72. @IBOutlet @objc weak var advancedPlanPurchaseLbl: NSTextField!
  73. @IBOutlet @objc weak var advancedPlanPurchaseLblBtn: NSButton!
  74. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel2: NSTextField!
  75. @IBOutlet weak var backgroundImage3: NSImageView!
  76. @IBOutlet @objc weak var discountPermanent2: NSImageView!
  77. @IBOutlet @objc weak var advancedPurchaseOriPriceLbl: NSTextField!
  78. // 买断
  79. @IBOutlet @objc weak var permanentInfoView: NSView!
  80. @IBOutlet @objc weak var permanentInfoLabel: NSTextField!
  81. @IBOutlet @objc weak var permanentPurchaseLabel: NSTextField!
  82. @IBOutlet @objc weak var permanentPurchaseSubLabel: NSTextField!
  83. @IBOutlet @objc weak var permanentPurchaseButton: NSButton!
  84. @IBOutlet @objc weak var permanentPurchaseLbl: NSTextField!
  85. @IBOutlet @objc weak var permanentPurchaseLblBtn: NSButton!
  86. @IBOutlet @objc weak var permanentPurchaseSubLabel2: NSTextField!
  87. @IBOutlet @objc weak var discountPermanent4: NSImageView!
  88. @IBOutlet @objc weak var permanentPurchaseOriPriceLbl: NSTextField!
  89. @IBOutlet @objc weak var aboutButton: NSButton!
  90. @IBOutlet @objc weak var btnRestore: HyperLinkButton!
  91. @IBOutlet @objc weak var privacyPolicyBtn: HyperLinkButton!
  92. @IBOutlet @objc weak var termOfSerBtn: HyperLinkButton!
  93. @IBOutlet @objc weak var textView: NSTextView!
  94. @IBOutlet @objc weak var specialView: NSView!
  95. @IBOutlet @objc weak var specialImageView: NSImageView!
  96. @IBOutlet @objc weak var specialLabel: NSTextField!
  97. @IBOutlet @objc weak var specialView1: NSView!
  98. @IBOutlet @objc weak var specialImageView1: NSImageView!
  99. @IBOutlet @objc weak var specialLabel1: NSTextField!
  100. @IBOutlet @objc weak var box: NSBox!
  101. @IBOutlet @objc weak var labelbox: NSBox!
  102. // @IBOutlet @objc weak var topButtonOffset: NSLayoutConstraint!
  103. @objc var value1Layer: CALayer?
  104. @objc var discountToSaveWinC: KMDiscountToSaveWindowController?
  105. @IBOutlet @objc weak var billedTopConst: NSLayoutConstraint!
  106. @IBOutlet @objc weak var discountYearly: NSImageView!
  107. @IBOutlet @objc weak var discountPermanent: NSImageView!
  108. // @IBOutlet @objc weak var discountPremium: NSImageView!
  109. @IBOutlet @objc weak var platformsView1: NSView!
  110. @IBOutlet @objc weak var platformsView2: NSView!
  111. @IBOutlet @objc weak var platformsView3: NSView!
  112. @IBOutlet @objc weak var platformsView4: NSView!
  113. @IBOutlet @objc weak var giftAIImage1: NSImageView!
  114. @IBOutlet @objc weak var giftAILabel1: NSTextField!
  115. @IBOutlet @objc weak var giftAIImage2: NSImageView!
  116. @IBOutlet @objc weak var giftAILabel2: NSTextField!
  117. @IBOutlet @objc weak var giftAIImage3: NSImageView!
  118. @IBOutlet @objc weak var giftAILabel3: NSTextField!
  119. @IBOutlet @objc weak var giftAIImage4: NSImageView!
  120. @IBOutlet @objc weak var giftAILabel4: NSTextField!
  121. @IBOutlet weak var value1PurchaseDiscountBox: NSBox!
  122. @IBOutlet weak var permanentInfoDiscountBox: NSBox!
  123. @IBOutlet weak var standardPlanInfoDiscountBox: NSBox!
  124. @IBOutlet weak var advancedPlanInfoDiscountBox: NSBox!
  125. private lazy var value1PurchaseDiscountView_: KMProductCompareDiscountView = {
  126. let view = KMProductCompareDiscountView()
  127. view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
  128. return view
  129. }()
  130. private lazy var permanentInfoDiscountView_: KMProductCompareDiscountView = {
  131. let view = KMProductCompareDiscountView()
  132. view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
  133. return view
  134. }()
  135. private lazy var standardPlanInfoDiscountView_: KMProductCompareDiscountView = {
  136. let view = KMProductCompareDiscountView()
  137. view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
  138. return view
  139. }()
  140. private lazy var advancedPlanInfoDiscountView_: KMProductCompareDiscountView = {
  141. let view = KMProductCompareDiscountView()
  142. view.backgroundIv.image = NSImage(named: "KMImageNameCompareDiscount")
  143. return view
  144. }()
  145. private var model = KMProductModel.shared
  146. private var cancellables = Set<AnyCancellable>()
  147. private var subscribeType_: KMSubscribeWaterMarkType?
  148. var subscribeType: KMSubscribeWaterMarkType? {
  149. get {
  150. return subscribeType_
  151. }
  152. }
  153. private var discountType_: KMDiscountType = .none
  154. var discountType: KMDiscountType {
  155. get {
  156. return discountType_
  157. }
  158. }
  159. private lazy var originalPriceAttri_: [NSAttributedString.Key : Any] = {
  160. return [.font : NSFont.SFProTextRegularFont(12),
  161. .foregroundColor: NSColor(hex: "#FFE76A"),
  162. .strikethroughStyle: NSUnderlineStyle.single.rawValue]
  163. }()
  164. var orientation: Bool = false // 是否定向跳转
  165. var orientationType: KMCompareTableType = .trial // 定向跳转比较表
  166. static let shared: KMProductCompareWC = {
  167. let windowC = KMProductCompareWC(windowNibName: "KMProductCompareWC")
  168. return windowC
  169. }()
  170. deinit {
  171. NotificationCenter.default.removeObserver(self)
  172. }
  173. override init(window: NSWindow?) {
  174. super.init(window: window)
  175. setupNotifications()
  176. }
  177. required init?(coder: NSCoder) {
  178. super.init(coder: coder)
  179. }
  180. override func windowDidLoad() {
  181. super.windowDidLoad()
  182. window?.backgroundColor = KMAppearance.Upgrade.vipBGColor()
  183. window?.isMovableByWindowBackground = true
  184. #if VERSION_DMG
  185. btnRestore.isHidden = true
  186. #endif
  187. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  188. bindViewModel()
  189. if orientation {
  190. model.state = orientationType
  191. } else {
  192. model.getCurrentComparisonTableType()
  193. }
  194. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  195. value1InfoLabel.font = NSFont.UbuntuMediumFontWithSize(16)
  196. value1PurchaseButton.wantsLayer = true
  197. value1PurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  198. value1PurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  199. value1PurchaseBtnLblBtn.wantsLayer = true
  200. value1PurchaseButton.mouseMoveCallback = { [weak self] mouseEntered in
  201. guard let self = self else { return }
  202. if self.value1PurchaseBtnLblBtn.isEnabled == true {
  203. self.value1PurchaseBtnLblBtn.layer?.backgroundColor = mouseEntered ? NSColor.black.withAlphaComponent(0.15).cgColor : NSColor.clear.cgColor
  204. }
  205. }
  206. value1PurchaseBtnLblBtn.layer?.cornerRadius = value1PurchaseBtnLblBtn.frame.height / 2
  207. value1PurchaseBtnLblBtn.layer?.masksToBounds = true
  208. standardPlanPurchaseButton.wantsLayer = true
  209. standardPlanPurchaseButton.layer?.cornerRadius = standardPlanPurchaseButton.frame.height / 2
  210. self.standardPlanPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  211. switchLabel.stringValue = NSLocalizedString("Choose your favorite payment and enjoy flexible upgrades.", comment: "")
  212. switchLabel.textColor = KMAppearance.Interactive.m0Color()
  213. box.wantsLayer = true
  214. box.shadow = NSShadow()
  215. box.layer?.shadowOpacity = 0.3
  216. box.layer?.shadowColor = NSColor.black.withAlphaComponent(0.3).cgColor
  217. box.layer?.shadowOffset = NSMakeSize(0, 3)
  218. box.layer?.shadowRadius = 8
  219. box.layer?.masksToBounds = false
  220. permanentPurchaseButton.wantsLayer = true
  221. permanentPurchaseButton.layer?.cornerRadius = permanentPurchaseButton.frame.height / 2
  222. self.permanentPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  223. let txtColor = NSColor(red: 102/255, green: 102/255, blue: 102/255, alpha: 1)
  224. aboutButton.title = NSLocalizedString("About Subscriptions", comment: "")
  225. aboutButton.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  226. aboutButton.isHidden = true
  227. self.value1PurchaseDiscountBox.borderWidth = 0
  228. self.value1PurchaseDiscountBox.contentView = self.value1PurchaseDiscountView_
  229. self.value1PurchaseDiscountView_.label.stringValue = "-$10"
  230. self.standardPlanInfoDiscountBox.borderWidth = 0
  231. self.standardPlanInfoDiscountBox.contentView = self.standardPlanInfoDiscountView_
  232. self.advancedPlanInfoDiscountBox.borderWidth = 0
  233. self.advancedPlanInfoDiscountBox.contentView = self.advancedPlanInfoDiscountView_
  234. self.permanentInfoDiscountBox.borderWidth = 0
  235. self.permanentInfoDiscountBox.contentView = self.permanentInfoDiscountView_
  236. self.permanentInfoDiscountView_.label.stringValue = "-$20"
  237. reloadData()
  238. reloadDataContent()
  239. #if !VERSION_DMG
  240. IAPProductsManager.default().loadProducts()
  241. #endif
  242. #if VERSION_FREE
  243. #if VERSION_DMG
  244. // DMG
  245. 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: ""))
  246. #else
  247. // AppStore 免费版本
  248. 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: ""))
  249. #endif
  250. #else
  251. // AppStore 付费版
  252. 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: ""))
  253. #endif
  254. showDiscount()
  255. comparativeStatementHead()
  256. let closeButton = window?.standardWindowButton(.closeButton)
  257. closeButton?.target = self
  258. closeButton?.action = #selector(closeAction)
  259. }
  260. func windowShouldClose(sender:Any) -> Bool {
  261. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn":"PUW_Btn_Upgrade_Cancel"])
  262. if model.isShowSale {
  263. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn":"PUW_7OffUpgrade_Cancel"], platform: .AppCenter)
  264. }
  265. return true
  266. }
  267. @objc func showWindowRestore(_ sender: Any) {
  268. showWindow(sender)
  269. buttonItemClicked_Restore(sender)
  270. }
  271. override func showWindow(_ sender: Any?) {
  272. super.showWindow(sender)
  273. subscribeType_ = nil
  274. discountType_ = .none
  275. clearEventData()
  276. _trackComparisonEvent(params: ["Exposure" : "ComparisonTable_Exposure"])
  277. alertingCodeForRefreshUserInfo_ = nil
  278. alertingForRefreshUserInfo_ = false
  279. #if VERSION_DMG
  280. model.getDMGProductDatas(discountCode: "") { success, result in
  281. }
  282. #endif
  283. if orientation {
  284. model.state = orientationType
  285. } else {
  286. model.getCurrentComparisonTableType()
  287. }
  288. model.isPurchaseSwitch = true
  289. languageLocalized()
  290. initializeUI()
  291. reloadData()
  292. if model.isShowSale {
  293. showDiscountToSaveWindow()
  294. }
  295. reloadDataContent()
  296. showDiscount()
  297. comparativeStatementHead()
  298. }
  299. // MARK: - Public Methods
  300. public func openWindow(type: KMSubscribeWaterMarkType) {
  301. showWindow(nil)
  302. subscribeType_ = type
  303. }
  304. public func openWindow(discountType: KMDiscountType) {
  305. showWindow(nil)
  306. discountType_ = discountType
  307. if discountType == .newUserGift {
  308. model.isPurchaseSwitch = false
  309. }
  310. comparativeStatementHead()
  311. #if VERSION_DMG
  312. var discountCode: String = ""
  313. if discountType == .newUserGift {
  314. discountCode = kKMNewUserGiftDiscountCodeId
  315. } else if discountType == .advancedYearSubscribeTrialingCancel {
  316. discountCode = kKMAdvancedYearSubscribeDiscountCodeId
  317. }
  318. model.getDMGProductDatas(discountCode: discountCode) { success, result in
  319. self.comparativeStatementHead()
  320. }
  321. #endif
  322. }
  323. public func closeWindow() {
  324. window?.close()
  325. }
  326. // MARK: - Private Methods
  327. private func languageLocalized() -> Void {
  328. titleLabel.stringValue = NSLocalizedString("Subscribe to All Access Pack to enjoy more expanded features.", comment: "")
  329. btnRestore.title = NSLocalizedString("Restore", comment: "")
  330. btnRestore.toolTip = NSLocalizedString("Restore", comment: "")
  331. privacyPolicyBtn.title = NSLocalizedString("Privacy Policy", comment: "")
  332. privacyPolicyBtn.toolTip = NSLocalizedString("Privacy Policy", comment: "")
  333. termOfSerBtn.title = NSLocalizedString("Terms of Service", comment: "")
  334. termOfSerBtn.toolTip = NSLocalizedString("Terms of Service", comment: "")
  335. sixMouthProLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  336. oneYearProLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  337. freeInfoLabel.stringValue = NSLocalizedString("Free", comment: "")
  338. standardPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  339. standardPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  340. standardPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  341. advancedPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Advanced - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  342. advancedPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  343. advancedPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  344. permanentInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Permanent", tableName: "MemberCenterLocalizable", comment: "")
  345. permanentPurchaseSubLabel.stringValue = NSLocalizedString("one-time purchase", comment: "")
  346. permanentPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  347. standardPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  348. if KMMemberInfo.shared.userScenarioType == .lite_type3 ||
  349. KMMemberInfo.shared.userScenarioType == .lite_type11 {
  350. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Renew now",tableName: "MemberCenterLocalizable", comment: "")
  351. } else {
  352. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  353. }
  354. permanentPurchaseLbl.stringValue = NSLocalizedString("Purchase", comment: "")
  355. giftAILabel1.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  356. giftAILabel2.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  357. giftAILabel3.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  358. giftAILabel4.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  359. #if VERSION_FREE
  360. #if VERSION_DMG
  361. // DMG
  362. if KMMemberInfo.shared.canTrail && model.state == .trial {
  363. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  364. }
  365. if model.state == .dmg_Base {
  366. if discountType_ == .newUserGift || discountType_ == .advancedYearSubscribeTrialingCancel {
  367. standardPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProStandard_dmg)
  368. advancedPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProAdvanced_dmg)
  369. permanentPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProPermanent_dmg)
  370. standardPurchaseOriPriceLbl.isHidden = false
  371. standardPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProStandard_dmg), attributes: originalPriceAttri_)
  372. advancedPurchaseOriPriceLbl.isHidden = false
  373. advancedPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProAdvanced_dmg), attributes: originalPriceAttri_)
  374. permanentPurchaseOriPriceLbl.isHidden = false
  375. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getProductPrice(.pdfReaderProPermanent_dmg), attributes: originalPriceAttri_)
  376. } else {
  377. standardPurchaseOriPriceLbl.isHidden = true
  378. advancedPurchaseOriPriceLbl.isHidden = true
  379. permanentPurchaseOriPriceLbl.isHidden = true
  380. standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
  381. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  382. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
  383. }
  384. } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
  385. guard let productModels = model.dmgProductDatas?.listingProducts else { return }
  386. for productModel in productModels {
  387. if productModel.code == "advanced-annual-subscription" {
  388. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  389. guard let self = self else { return }
  390. guard let results: KMMemberProductResult = result else { return }
  391. guard let productModels2 = results.listingProducts else { return }
  392. for productModel2 in productModels2 {
  393. if productModel2.code == "advanced-annual-subscription" {
  394. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  395. }
  396. }
  397. }
  398. } else if productModel.code == "advanced-permanent-blackFive" {
  399. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  400. guard let self = self else { return }
  401. guard let results: KMMemberProductResult = result else { return }
  402. guard let productModels2 = results.listingProducts else { return }
  403. for productModel2 in productModels2 {
  404. if productModel2.code == "advanced-annual-subscription-blackFive" {
  405. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  406. }
  407. }
  408. }
  409. }
  410. }
  411. } else {
  412. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  413. }
  414. #else
  415. var isTrialPeriod = false
  416. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == true {
  417. isTrialPeriod = true
  418. }
  419. if KMMemberInfo.shared.isLogin {
  420. if(!isTrialPeriod &&
  421. KMMemberInfo.shared.canTrail &&
  422. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  423. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  424. }
  425. } else {
  426. if(!isTrialPeriod &&
  427. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  428. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  429. }
  430. }
  431. // AppStore 免费版本
  432. if model.state == .lite_Base {
  433. permanentPurchaseLabel.stringValue = model.getProductPrice(.allAccessPackPermanent_lite)
  434. } else if model.state == .lite_MacWindows {
  435. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  436. let platforms = KMMemberInfo.shared.vip_platforms
  437. let platformsArray = platforms
  438. .components(separatedBy: ",")
  439. .map { $0.trimmingCharacters(in: .whitespaces) }
  440. if platformsArray.count == 1 {
  441. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  442. } else if platformsArray.count == 2 {
  443. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  444. } else {
  445. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  446. }
  447. } else {
  448. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  449. }
  450. } else {
  451. // model.state == .trial
  452. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPackNew12months_lite)
  453. }
  454. #endif
  455. #else
  456. // AppStore 付费版
  457. if model.state == .pro_Base {
  458. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  459. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.standardAddDevicesAllAccessPack12months_pro)
  460. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfToOfficePackPermanent_pro)
  461. }
  462. } else if model.state == .pro_Advanced {
  463. let platforms = KMMemberInfo.shared.vip_platforms
  464. let platformsArray = platforms
  465. .components(separatedBy: ",")
  466. .map { $0.trimmingCharacters(in: .whitespaces) }
  467. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  468. if platformsArray.count == 1 {
  469. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  470. } else if platformsArray.count == 2 {
  471. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  472. } else if KMMemberInfo.shared.vip_levels == "1" {
  473. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  474. } else {
  475. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  476. }
  477. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  478. if platformsArray.count == 1 {
  479. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  480. } else if platformsArray.count == 2 {
  481. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  482. } else {
  483. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  484. }
  485. }
  486. } else {
  487. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPack12months_pro)
  488. }
  489. #endif
  490. }
  491. private func initializeUI() -> Void {
  492. btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  493. btnRestore.font = NSFont.SFProTextRegularFont(13)
  494. btnRestore.mouseMoveCallback = { [weak self] mouseEntered in
  495. guard let self = self else { return }
  496. if mouseEntered {
  497. self.btnRestore.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  498. } else {
  499. self.btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  500. }
  501. }
  502. privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  503. privacyPolicyBtn.font = NSFont.SFProTextRegularFont(13)
  504. privacyPolicyBtn.mouseMoveCallback = { [weak self] mouseEntered in
  505. guard let self = self else { return }
  506. if mouseEntered {
  507. self.privacyPolicyBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  508. } else {
  509. self.privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  510. }
  511. }
  512. termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  513. termOfSerBtn.font = NSFont.SFProTextRegularFont(13)
  514. termOfSerBtn.mouseMoveCallback = { [weak self] mouseEntered in
  515. guard let self = self else { return }
  516. if mouseEntered {
  517. self.termOfSerBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  518. } else {
  519. self.termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  520. }
  521. }
  522. giftAILabel1.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  523. giftAILabel1.font = NSFont.SFProTextRegularFont(12)
  524. giftAILabel2.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  525. giftAILabel2.font = NSFont.SFProTextRegularFont(12)
  526. giftAILabel3.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  527. giftAILabel3.font = NSFont.SFProTextRegularFont(12)
  528. giftAILabel4.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  529. giftAILabel4.font = NSFont.SFProTextRegularFont(12)
  530. value1InfoTypeBox.fillColor = NSColor.clear
  531. value1InfoTypeBox.borderWidth = 0
  532. sixMouthProLabel.textColor = .white
  533. sixMouthProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  534. sixMouthProLabel.lineBreakMode = .byTruncatingTail
  535. sixMouthProLabel.toolTip = sixMouthProLabel.stringValue
  536. sixMouthProLabel.alignment = .center
  537. oneYearProLabel.textColor = .white
  538. oneYearProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  539. oneYearProLabel.lineBreakMode = .byTruncatingTail
  540. oneYearProLabel.toolTip = oneYearProLabel.stringValue
  541. oneYearProLabel.alignment = .center
  542. switchBox.fillColor = NSColor(white: 1, alpha: 0.2)
  543. switchBox.cornerRadius = 12
  544. switchBox.borderWidth = 1
  545. switchBox.borderColor = NSColor(red: 235/255, green: 236/255, blue: 240/255, alpha: 1.0)
  546. switchCircleView.wantsLayer = true
  547. switchCircleView.layer?.cornerRadius = 8
  548. switchCircleView.layer?.backgroundColor = NSColor.white.cgColor
  549. switchBtn.title = ""
  550. switchBtn.target = self
  551. switchBtn.action = #selector(switchAction)
  552. saleLabel.isHidden = true
  553. saleLabel.superview?.isHidden = true
  554. saleBox.borderWidth = 0
  555. topMainBox.contentView = topMainView
  556. if let contentView = topMainBox.contentView {
  557. contentView.wantsLayer = true
  558. contentView.layer?.masksToBounds = false
  559. }
  560. if let contentView = topMainView {
  561. contentView.wantsLayer = true
  562. contentView.layer?.masksToBounds = false
  563. }
  564. topsubBox1.isHidden = false
  565. topsubBox2.isHidden = false
  566. topsubBox3.isHidden = false
  567. topsubBox4.isHidden = false
  568. topSelectBox1.isHidden = true
  569. topSelectBox2.isHidden = true
  570. topSelectBox3.isHidden = true
  571. topSelectBox4.isHidden = true
  572. giftAIImage1.isHidden = true
  573. giftAILabel1.isHidden = true
  574. giftAIImage2.isHidden = true
  575. giftAILabel2.isHidden = true
  576. giftAIImage3.isHidden = true
  577. giftAILabel3.isHidden = true
  578. giftAIImage4.isHidden = true
  579. giftAILabel4.isHidden = true
  580. freeInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  581. standardPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  582. advancedPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  583. permanentInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  584. standardPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  585. standardPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  586. advancedPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  587. advancedPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  588. permanentPurchaseSubLabel.font = NSFont.UbuntuMediumFontWithSize(11)
  589. permanentPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  590. value1PurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  591. standardPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  592. standardPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  593. advancedPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  594. advancedPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  595. permanentPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  596. permanentPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  597. backgroundImage1.wantsLayer = true
  598. backgroundImage1.layer?.cornerRadius = 12
  599. backgroundImage1.layer?.masksToBounds = true
  600. backgroundImage3.wantsLayer = true
  601. backgroundImage3.layer?.cornerRadius = 12
  602. backgroundImage3.layer?.masksToBounds = true
  603. advancedPlanPurchaseButton.wantsLayer = true
  604. advancedPlanPurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  605. advancedPlanPurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  606. standardPlanPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  607. advancedPlanPurchaseLbl.textColor = NSColor(named: "FFFFFF") ?? .white
  608. permanentPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  609. var contentWidth = 970.0
  610. var contentHeight = 660.0
  611. if model.state == .dmg_Base {
  612. contentWidth = 970.0
  613. contentHeight = 660.0
  614. topsubBox1.contentView = freeInfoView
  615. topsubBox2.contentView = standardPlanInfoView
  616. topsubBox3.contentView = advancedPlanInfoView
  617. topsubBox4.contentView = permanentInfoView
  618. backgroundImage1.isHidden = true
  619. topSelectBox3.isHidden = false
  620. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  621. // giftAIImage3.isHidden = false
  622. // giftAILabel3.isHidden = false
  623. // }
  624. topsubBoxWidth1.constant = 149.5
  625. topsubBoxWidth2.constant = 149.5
  626. topsubBoxWidth3.constant = 149.5
  627. topsubBoxWidth3.constant = 149.5
  628. } else if model.state == .dmg_Upgrades1 {
  629. contentWidth = 689.0
  630. contentHeight = 660.0
  631. topsubBox2.isHidden = true
  632. topsubBox3.isHidden = true
  633. topsubBox4.isHidden = true
  634. topsubBox1.contentView = advancedPlanInfoView
  635. topSelectBox1.isHidden = false
  636. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  637. // giftAIImage1.isHidden = false
  638. // giftAILabel1.isHidden = false
  639. // }
  640. topsubBoxWidth1.constant = 320.0
  641. } else if model.state == .dmg_Upgrades2 {
  642. contentWidth = 689.0
  643. contentHeight = 660.0
  644. topsubBox2.isHidden = true
  645. topsubBox3.isHidden = true
  646. topsubBox4.isHidden = true
  647. topsubBox1.contentView = advancedPlanInfoView
  648. topSelectBox1.isHidden = false
  649. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  650. // giftAIImage1.isHidden = false
  651. // giftAILabel1.isHidden = false
  652. // }
  653. topsubBoxWidth1.constant = 320.0
  654. } else if model.state == .lite_Base {
  655. contentWidth = 970.0
  656. contentHeight = 660.0
  657. topsubBox4.isHidden = true
  658. topsubBox1.contentView = freeInfoView
  659. topsubBox2.contentView = value1InfoView
  660. topsubBox3.contentView = permanentInfoView
  661. topSelectBox2.isHidden = false
  662. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  663. // giftAIImage2.isHidden = false
  664. // giftAILabel2.isHidden = false
  665. // }
  666. topsubBoxWidth1.constant = 179.0
  667. topsubBoxWidth2.constant = 240.0
  668. topsubBoxWidth3.constant = 179.0
  669. } else if model.state == .lite_MacWindows {
  670. contentWidth = 689.0
  671. contentHeight = 660.0
  672. topsubBox2.isHidden = true
  673. topsubBox3.isHidden = true
  674. topsubBox4.isHidden = true
  675. topsubBox1.contentView = advancedPlanInfoView
  676. topSelectBox1.isHidden = false
  677. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  678. // giftAIImage1.isHidden = false
  679. // giftAILabel1.isHidden = false
  680. // }
  681. topsubBoxWidth1.constant = 320.0
  682. } else if model.state == .pro_Base {
  683. contentWidth = 970.0
  684. contentHeight = 660.0
  685. topsubBox3.isHidden = true
  686. topsubBox4.isHidden = true
  687. topsubBox1.contentView = advancedPlanInfoView
  688. topsubBox2.contentView = permanentInfoView
  689. backgroundImage1.isHidden = true
  690. topSelectBox1.isHidden = false
  691. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  692. // giftAIImage1.isHidden = false
  693. // giftAILabel1.isHidden = false
  694. // }
  695. topsubBoxWidth1.constant = 299.0
  696. topsubBoxWidth2.constant = 299.0
  697. } else if model.state == .pro_Advanced {
  698. contentWidth = 689.0
  699. contentHeight = 660.0
  700. topsubBox2.isHidden = true
  701. topsubBox3.isHidden = true
  702. topsubBox4.isHidden = true
  703. topsubBox1.contentView = advancedPlanInfoView
  704. topSelectBox1.isHidden = false
  705. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  706. // giftAIImage1.isHidden = false
  707. // giftAILabel1.isHidden = false
  708. // }
  709. topsubBoxWidth1.constant = 320.0
  710. } else {
  711. // model.state == .trial
  712. contentWidth = 785.0
  713. contentHeight = 660.0
  714. topsubBox3.isHidden = true
  715. topsubBox4.isHidden = true
  716. topsubBox1.contentView = freeInfoView
  717. topsubBox2.contentView = advancedPlanInfoView
  718. backgroundImage1.isHidden = true
  719. topSelectBox2.isHidden = false
  720. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  721. // giftAIImage2.isHidden = false
  722. // giftAILabel2.isHidden = false
  723. // }
  724. topsubBoxWidth1.constant = 179.0
  725. topsubBoxWidth2.constant = 240.0
  726. }
  727. self.window?.setContentSize(NSSize(width: contentWidth, height: contentHeight))
  728. self.window?.maxSize = NSSize(width: contentWidth, height: contentHeight)
  729. self.window?.minSize = NSSize(width: contentWidth, height: contentHeight)
  730. box.fillColor = KMAppearance.Layout.l1Color()
  731. labelbox.fillColor = .clear
  732. tableView.backgroundColor = KMAppearance.Layout.l0Color()
  733. textView.backgroundColor = .clear
  734. textView.textColor = NSColor.white.withAlphaComponent(0.5)
  735. value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  736. standardPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  737. standardPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  738. advancedPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  739. advancedPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  740. permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  741. permanentPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  742. #if VERSION_FREE
  743. #if VERSION_DMG
  744. // DMG
  745. #else
  746. // AppStore 免费版本
  747. refreshPurchaseSwitch()
  748. #endif
  749. #else
  750. // AppStore 付费版
  751. #endif
  752. }
  753. private func setupNotifications() {
  754. NotificationCenter.default.addObserver(
  755. self,
  756. selector: #selector(IAPProductLoadedNotification(_:)),
  757. name: NSNotification.Name(rawValue: "KMIAPProductLoadedNotification"),
  758. object: nil
  759. )
  760. NotificationCenter.default.addObserver(
  761. self,
  762. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  763. name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
  764. object: nil
  765. )
  766. NotificationCenter.default.addObserver(
  767. self,
  768. selector: #selector(IAPProductPurchasedNotification(_:)),
  769. name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"),
  770. object: nil
  771. )
  772. NotificationCenter.default.addObserver(
  773. self,
  774. selector: #selector(IAPProductFailedNotification(_:)),
  775. name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
  776. object: nil
  777. )
  778. NotificationCenter.default.addObserver(
  779. self,
  780. selector: #selector(IAPProductRestoreFinishedNotification(_:)),
  781. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"),
  782. object: nil
  783. )
  784. NotificationCenter.default.addObserver(
  785. self,
  786. selector: #selector(IAPProductRestoreFailedNotification(_:)),
  787. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFailedNotification"),
  788. object: nil
  789. )
  790. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  791. }
  792. func reloadData() {
  793. saleBox.isHidden = true
  794. saleIv.isHidden = true
  795. if model.isShowSale {
  796. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  797. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.saleImage, highlight: true)) {
  798. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  799. guard let self = self else { return }
  800. self.saleIv.image = image
  801. self.saleBox.isHidden = false
  802. self.saleIv.isHidden = false
  803. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_7OffUpgrade"], platform: .AppCenter)
  804. }
  805. }
  806. } else {
  807. saleBox.isHidden = true
  808. }
  809. // if KMMemberInfo.shared.isMemberAllFunction == true {
  810. // value1PurchaseButton.isEnabled = false
  811. // permanentPurchaseButton.isEnabled = false
  812. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 0.5)
  813. // } else {
  814. // value1PurchaseButton.isEnabled = true
  815. // permanentPurchaseButton.isEnabled = true
  816. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 1.0)
  817. // }
  818. permanentPurchaseLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  819. value1PurchaseOriPriceLbl.font = NSFont.SFProTextRegularFont(12)
  820. }
  821. func refreshPurchaseSwitch() -> Void {
  822. #if VERSION_FREE
  823. #if VERSION_DMG
  824. // DMG
  825. #else
  826. // AppStore 免费版本
  827. reloadData()
  828. if model.isPurchaseSwitch {
  829. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  830. // giftAIImage2.isHidden = false
  831. // giftAILabel2.isHidden = false
  832. // }
  833. discountYearly.isHidden = false
  834. sixMouthProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  835. oneYearProLabel.textColor = NSColor.white
  836. switchCircleLeftConst.constant = 22
  837. value1InfoLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  838. } else {
  839. giftAIImage2.isHidden = true
  840. giftAILabel2.isHidden = true
  841. discountYearly.isHidden = true
  842. sixMouthProLabel.textColor = NSColor.white
  843. oneYearProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  844. switchCircleLeftConst.constant = 4
  845. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  846. }
  847. value1PurchaseBtnLblBtn.isEnabled = value1PurchaseButton.isEnabled
  848. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  849. let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  850. let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  851. let isTrialPeriod_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isTrialPeriod ?? false
  852. let isSubscribed_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isSubscribed ?? false
  853. let isTrialPeriod_year = fourDevicesAllAccessPackNew12months_lite?.isTrialPeriod ?? false
  854. let isSubscribed_year = fourDevicesAllAccessPackNew12months_lite?.isSubscribed ?? false
  855. let introductoryPrice_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.product?.introductoryPrice
  856. let introductoryPrice_year = fourDevicesAllAccessPackNew12months_lite?.product?.introductoryPrice
  857. // 购买按钮
  858. if(isSubscribed_year) {
  859. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  860. } else {
  861. if(model.isPurchaseSwitch == true) {
  862. if KMMemberInfo.shared.isLogin {
  863. if(!isTrialPeriod_year &&
  864. KMMemberInfo.shared.canTrail &&
  865. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  866. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  867. } else {
  868. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  869. }
  870. } else {
  871. if(!isTrialPeriod_year &&
  872. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  873. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  874. } else {
  875. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  876. }
  877. }
  878. } else {
  879. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  880. }
  881. }
  882. value1PurchaseBtnLbl.textColor = value1PurchaseBtnLblBtn.isEnabled ? NSColor.white : NSColor.white.withAlphaComponent(0.5)
  883. permanentPurchaseLblBtn.isEnabled = permanentPurchaseButton.isEnabled
  884. standardPlanPurchaseLblBtn.isEnabled = standardPlanPurchaseButton.isEnabled
  885. advancedPlanPurchaseLblBtn.isEnabled = advancedPlanPurchaseButton.isEnabled
  886. var averageMonthPrice: String? = nil
  887. var monthPrice: String? = nil
  888. var averageMonthPriceDiscount: String? = nil
  889. var monthPriceDiscount: String? = nil
  890. var allPrice: String? = nil
  891. let isOffers_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isOffers ?? false
  892. let isOffers_year = fourDevicesAllAccessPackNew12months_lite?.isOffers ?? false
  893. var introPrice: String? = nil
  894. var introAveragePrice: String? = nil
  895. if isOffers_newlyMonth {
  896. specialView1.isHidden = false
  897. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersAveragePrice()
  898. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersPrice()
  899. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  900. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  901. introPrice = fourDevicesAllAccessPackNew6Months_lite?.introPrice()
  902. introAveragePrice = fourDevicesAllAccessPackNew6Months_lite?.introAveragePrice()
  903. } else if isOffers_year {
  904. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.offersAveragePrice()
  905. monthPrice = fourDevicesAllAccessPackNew12months_lite?.offersPrice()
  906. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  907. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  908. introPrice = fourDevicesAllAccessPackNew12months_lite?.introPrice()
  909. introAveragePrice = fourDevicesAllAccessPackNew12months_lite?.introAveragePrice()
  910. } else {
  911. specialView1.isHidden = true
  912. if !model.isPurchaseSwitch {
  913. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.averagePrice()
  914. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.price()
  915. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  916. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  917. introPrice = fourDevicesAllAccessPackNew6Months_lite?.introPrice()
  918. introAveragePrice = fourDevicesAllAccessPackNew6Months_lite?.introAveragePrice()
  919. } else {
  920. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.averagePrice()
  921. monthPrice = fourDevicesAllAccessPackNew12months_lite?.price()
  922. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  923. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  924. introPrice = fourDevicesAllAccessPackNew12months_lite?.introPrice()
  925. introAveragePrice = fourDevicesAllAccessPackNew12months_lite?.introAveragePrice()
  926. }
  927. }
  928. if let allAccessPackPermanent_lite = IAPProductsManager.default().allAccessPackPermanent_lite, allAccessPackPermanent_lite.isOffers {
  929. specialView.isHidden = false
  930. allPrice = allAccessPackPermanent_lite.offersPrice()
  931. } else {
  932. specialView.isHidden = true
  933. allPrice = IAPProductsManager.default().allAccessPackPermanent_lite?.price()
  934. }
  935. var off = 1 - (IAPProductsManager.default().allAccessPackPermanent_lite?.offers ?? 0)
  936. var offString = String(format: "%.f%%", off * 100)
  937. specialLabel.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  938. if model.isPurchaseSwitch {
  939. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.offers
  940. } else {
  941. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.offers
  942. }
  943. offString = String(format: "%.f%%", off * 100)
  944. specialLabel1.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  945. let image = NSImage(named: "KMImageNameCompareTagBG")
  946. specialImageView.image = image
  947. specialImageView1.image = image
  948. let showAveragePrice = KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice()
  949. // 商品是否有推介优惠
  950. let hasIntroPrice = (introPrice != nil && introPrice?.isEmpty == false)
  951. if model.isPurchaseSwitch { // 年订阅
  952. let iapProduct = fourDevicesAllAccessPackNew12months_lite
  953. if model.isShowSale { // 旧订阅优惠
  954. if showAveragePrice {
  955. value1PurchaseSubLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
  956. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  957. } else {
  958. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("12 months", comment: ""))
  959. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  960. }
  961. value1PurchaseOriPriceLbl.isHidden = false
  962. billedTopConst.constant = 16
  963. } else {
  964. // 是否为新用户
  965. let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
  966. if hasIntroPrice && isNewUser { // 推介优惠
  967. if showAveragePrice {
  968. value1PurchaseLabel.stringValue = String(format: "%@/%@", introAveragePrice ?? "" , NSLocalizedString("mon", comment: ""))
  969. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  970. } else {
  971. value1PurchaseLabel.stringValue = String(format: "%@/%@", introPrice ?? "", NSLocalizedString("12 months", comment: ""))
  972. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  973. }
  974. value1PurchaseOriPriceLbl.isHidden = false
  975. billedTopConst.constant = 16
  976. self.value1PurchaseDiscountBox.isHidden = true
  977. } else { // 促销优惠
  978. var useDiscountCode: String? = nil
  979. if discountType_ == .advancedYearSubscribeTrialingCancel {
  980. let discountCode = "4_devices_all_access_pack_12months_20250102"
  981. if let priceString = iapProduct?.discountPrice(withDiscountCode: discountCode), priceString.isEmpty == false {
  982. self.value1PurchaseDiscountBox.isHidden = false
  983. self.value1PurchaseDiscountView_.label.stringValue = "-"+priceString
  984. useDiscountCode = discountCode
  985. } else {
  986. self.value1PurchaseDiscountBox.isHidden = true
  987. }
  988. } else {
  989. self.value1PurchaseDiscountBox.isHidden = true
  990. }
  991. if let data = iapProduct?.productPrice(withDiscountCode: useDiscountCode ?? ""), data.isEmpty == false {
  992. if showAveragePrice {
  993. let priceS = iapProduct?.productAveragePrice(withDiscountCode: useDiscountCode ?? "") ?? ""
  994. value1PurchaseLabel.stringValue = String(format: "%@/%@", priceS , NSLocalizedString("mon", comment: ""))
  995. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  996. } else {
  997. value1PurchaseLabel.stringValue = String(format: "%@/%@", data ?? "", NSLocalizedString("12 months", comment: ""))
  998. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  999. }
  1000. value1PurchaseOriPriceLbl.isHidden = false
  1001. billedTopConst.constant = 16
  1002. } else {
  1003. if showAveragePrice {
  1004. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  1005. } else {
  1006. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  1007. }
  1008. value1PurchaseOriPriceLbl.isHidden = true
  1009. billedTopConst.constant = 0
  1010. }
  1011. }
  1012. }
  1013. } else {
  1014. let iapProduct = fourDevicesAllAccessPackNew6Months_lite
  1015. if model.isShowSale { // [旧订阅][活动][可移除]
  1016. if showAveragePrice {
  1017. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
  1018. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  1019. } else {
  1020. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("6mon", comment: ""))
  1021. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  1022. }
  1023. value1PurchaseOriPriceLbl.isHidden = false
  1024. billedTopConst.constant = 16
  1025. } else {
  1026. let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
  1027. if hasIntroPrice && isNewUser { // 推介优惠
  1028. if showAveragePrice {
  1029. value1PurchaseLabel.stringValue = String(format: "%@/%@", introAveragePrice ?? "" , NSLocalizedString("mon", comment: ""))
  1030. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  1031. } else {
  1032. value1PurchaseLabel.stringValue = String(format: "%@/%@", introPrice ?? "", NSLocalizedString("6mon", comment: ""))
  1033. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  1034. }
  1035. value1PurchaseOriPriceLbl.isHidden = false
  1036. billedTopConst.constant = 16
  1037. if discountType_ == .newUserGift {
  1038. self.value1PurchaseDiscountBox.isHidden = false
  1039. let priceString = iapProduct?.introDiscountPrice() ?? "$10"
  1040. self.value1PurchaseDiscountView_.label.stringValue = "-"+priceString
  1041. } else {
  1042. self.value1PurchaseDiscountBox.isHidden = true
  1043. }
  1044. } else { // 促销优惠
  1045. var useDiscountCode: String? = nil
  1046. if discountType_ == .advancedYearSubscribeTrialingCancel {
  1047. let discountCode = "4_devices_all_access_pack_new_6month_20250102"
  1048. if let priceString = iapProduct?.discountPrice(withDiscountCode: discountCode), priceString.isEmpty == false {
  1049. self.value1PurchaseDiscountBox.isHidden = false
  1050. self.value1PurchaseDiscountView_.label.stringValue = "-"+priceString
  1051. useDiscountCode = discountCode
  1052. } else {
  1053. self.value1PurchaseDiscountBox.isHidden = true
  1054. }
  1055. } else {
  1056. self.value1PurchaseDiscountBox.isHidden = true
  1057. }
  1058. if let data = iapProduct?.productPrice(withDiscountCode: useDiscountCode ?? ""), data.isEmpty == false {
  1059. if showAveragePrice {
  1060. let priceS = iapProduct?.productAveragePrice(withDiscountCode: useDiscountCode ?? "") ?? ""
  1061. value1PurchaseLabel.stringValue = String(format: "%@/%@", priceS , NSLocalizedString("mon", comment: ""))
  1062. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  1063. } else {
  1064. value1PurchaseLabel.stringValue = String(format: "%@/%@", data ?? "", NSLocalizedString("6mon", comment: ""))
  1065. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  1066. }
  1067. value1PurchaseOriPriceLbl.isHidden = false
  1068. billedTopConst.constant = 16
  1069. } else {
  1070. if showAveragePrice {
  1071. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  1072. } else {
  1073. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  1074. }
  1075. value1PurchaseOriPriceLbl.isHidden = true
  1076. billedTopConst.constant = 0
  1077. }
  1078. }
  1079. }
  1080. }
  1081. if self.discountYearly.image != nil { // 有活动
  1082. self.value1PurchaseDiscountBox.isHidden = true
  1083. }
  1084. value1PurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  1085. value1PurchaseOriPriceLbl.textColor = NSColor(hex: "#FFE76A")
  1086. value1PurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: value1PurchaseOriPriceLbl.stringValue, attributes: originalPriceAttri_)
  1087. var tTips: String
  1088. if model.isShowSale {
  1089. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  1090. } else {
  1091. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  1092. }
  1093. if value1PurchaseBtnLbl.stringValue == NSLocalizedString("Free Trial", comment: "") {
  1094. tTips = String(format: NSLocalizedString("Billed every 6 months at %@ after 7-day trial ends.", comment: ""), monthPrice ?? "")
  1095. #if !VERSION_DMG
  1096. if model.isPurchaseSwitch {
  1097. if let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product {
  1098. if #available(macOS 10.13.2, *) {
  1099. let trialDays = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product?.introductoryPrice?.subscriptionPeriod.numberOfUnits
  1100. tTips = String(
  1101. format: NSLocalizedString("Billed every 12 months at %@ after %@-day trial ends.", comment: ""),
  1102. monthPrice ?? "",
  1103. "\(trialDays ?? 0)"
  1104. )
  1105. }
  1106. }
  1107. } else {
  1108. if let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product {
  1109. if #available(macOS 10.13.2, *) {
  1110. let trialDays = fourDevicesAllAccessPackNew6Months_lite.introductoryPrice?.subscriptionPeriod.numberOfUnits
  1111. tTips = String(
  1112. format: NSLocalizedString("Billed every 6 months at %@ after %@-day trial ends.", comment: ""),
  1113. monthPrice ?? "",
  1114. "\(trialDays ?? 0)"
  1115. )
  1116. }
  1117. }
  1118. }
  1119. #endif
  1120. }
  1121. if #available(macOS 10.13.2, *) {
  1122. #if !VERSION_DMG
  1123. if model.isPurchaseSwitch {
  1124. if model.isShowSale {
  1125. tTips = String(format: NSLocalizedString("%@ for the first year's subscription", comment: ""), monthPriceDiscount ?? "")
  1126. } else {
  1127. if let data = introPrice, data.isEmpty == false {
  1128. tTips = String(format: NSLocalizedString("Auto-renew at %@/year after expiration. Cancel anytime (Tax Incl.)", comment: ""), monthPrice ?? "")
  1129. } else {
  1130. tTips = String(format: NSLocalizedString("Billed every 12 months at %@", comment: ""), monthPrice ?? "")
  1131. }
  1132. }
  1133. } else {
  1134. if model.isShowSale {
  1135. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  1136. } else {
  1137. if let data = introPrice, data.isEmpty == false {
  1138. tTips = String(format: NSLocalizedString("Auto-renew at %@/6-month after expiration. Cancel anytime (Tax Incl.)", comment: ""), monthPrice ?? "")
  1139. } else {
  1140. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  1141. }
  1142. }
  1143. }
  1144. #endif
  1145. }
  1146. value1PurchaseSubLabel.stringValue = String(format: NSLocalizedString("%@", comment: ""), tTips)
  1147. value1PurchaseBtnLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  1148. #endif
  1149. #else
  1150. // AppStore 付费版
  1151. // value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  1152. let fourDevicesAllAccessPack12months_pro = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro
  1153. let standardAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro
  1154. let advancedAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro
  1155. let advancedAdd2DevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro
  1156. // let pdfToOfficePackPermanent_pro = IAPProductsManager.default().pdfToOfficePackPermanent_pro
  1157. let isTrialPeriod_year = fourDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  1158. let isTrialPeriod_standard = standardAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  1159. let isTrialPeriod_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  1160. let isTrialPeriod_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  1161. let isSubscribed_year = fourDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  1162. let isSubscribed_standard = standardAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  1163. let isSubscribed_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  1164. let isSubscribed_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isSubscribed ?? false
  1165. let introductoryPrice_year = fourDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  1166. let introductoryPrice_standard = standardAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  1167. let introductoryPrice_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  1168. let introductoryPrice_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.product?.introductoryPrice
  1169. #endif
  1170. }
  1171. @objc func reloadDataContent() {
  1172. tableView.reloadData()
  1173. }
  1174. func addWaitingView(to view: NSView) {
  1175. removeWaitingView(from: view)
  1176. let waitingView = WaitingView(frame: view.bounds)
  1177. waitingView.autoresizingMask = [.width, .height]
  1178. view.addSubview(waitingView)
  1179. waitingView.startAnimation()
  1180. }
  1181. func removeWaitingView(from view: NSView) {
  1182. KMMainThreadExecute {
  1183. for subview in view.subviews {
  1184. if subview is WaitingView {
  1185. subview.removeFromSuperview()
  1186. break
  1187. }
  1188. }
  1189. }
  1190. }
  1191. func showDiscount() {
  1192. discountYearly.isHidden = true
  1193. discountPermanent.isHidden = true
  1194. discountPermanent2.isHidden = true
  1195. discountPermanent.isHidden = true
  1196. #if VERSION_FREE
  1197. #if VERSION_DMG
  1198. // DMG
  1199. if model.state != .dmg_Base { return }
  1200. #else
  1201. // AppStore 免费版本
  1202. if model.state != .lite_Base { return }
  1203. #endif
  1204. #else
  1205. // AppStore 付费版
  1206. if model.state != .pro_Base { return }
  1207. #endif
  1208. let content = KMAdvertisementManager.manager.info.StoreUserRecovery?.content ?? []
  1209. if content.count > 0 {
  1210. for (index, item) in content.enumerated() {
  1211. switch index {
  1212. case 1:
  1213. configureDiscountView(discountYearly, with: item)
  1214. case 2:
  1215. configureDiscountView(discountPermanent4, with: item)
  1216. case 3:
  1217. configureDiscountView(discountPermanent2, with: item)
  1218. case 4:
  1219. configureDiscountView(discountPermanent, with: item)
  1220. default:
  1221. break
  1222. }
  1223. }
  1224. }
  1225. }
  1226. private func configureDiscountView(_ view: NSImageView, with itemInfo: KMAdvertisementItemInfo) {
  1227. if KMAdvertisementManager.checkAdvertisementValid(itemInfo) {
  1228. view.isHidden = false
  1229. let urlString = KMAdvertisementModelTransition.transitionImagePath(image: itemInfo.image, highlight: false)
  1230. if let url = URL(string: urlString) {
  1231. view.image = KMAdvertisementImage.imageWithURL(url: url) { image in
  1232. view.image = image
  1233. }
  1234. }
  1235. } else {
  1236. view.isHidden = true
  1237. }
  1238. }
  1239. private func showAlert(message: String) {
  1240. let alert = NSAlert()
  1241. alert.alertStyle = .critical
  1242. alert.messageText = message
  1243. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1244. alert.runModal()
  1245. }
  1246. private var alertingForRefreshUserInfo_ = false
  1247. private var alertingCodeForRefreshUserInfo_: Int?
  1248. private func handleVerificationFailure(msg: KMMemberProductResult?) {
  1249. if self.alertingForRefreshUserInfo_ {
  1250. KMPrint("刷新用户信息-Alert中。。。")
  1251. return
  1252. }
  1253. if msg?.code == 500 {
  1254. KMPrint("错误信息: One record is expected, but the query result is multiple records。。。")
  1255. return
  1256. }
  1257. if msg?.code == alertingCodeForRefreshUserInfo_ {
  1258. KMPrint("刷新用户信息-Alert中 重复Code 。。。")
  1259. return
  1260. }
  1261. var message = msg?.msg ?? ""
  1262. if !message.isEmpty {
  1263. alertingForRefreshUserInfo_ = true
  1264. alertingCodeForRefreshUserInfo_ = msg?.code
  1265. KMMemberCenterManager.showAlert(code: .init(rawValue: msg?.code ?? 0), message: msg?.msg) { [weak self] resp, _ in
  1266. DispatchQueue.main.async {
  1267. self?.alertingForRefreshUserInfo_ = false
  1268. // self?.alertingCodeForRefreshUserInfo_ = nil
  1269. }
  1270. }
  1271. }
  1272. }
  1273. private func comparativeStatementHead() -> Void {
  1274. value1PurchaseOriPriceLbl.isHidden = true
  1275. standardPlanInfoDiscountBox.isHidden = true
  1276. advancedPlanInfoDiscountBox.isHidden = true
  1277. permanentInfoDiscountBox.isHidden = true
  1278. advancedPurchaseOriPriceLbl.isHidden = true
  1279. #if VERSION_FREE
  1280. #if VERSION_DMG
  1281. // DMG
  1282. if KMMemberInfo.shared.canTrail && model.state == .trial {
  1283. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  1284. }
  1285. if model.state == .dmg_Base {
  1286. if discountType_ == .newUserGift || discountType_ == .advancedYearSubscribeTrialingCancel {
  1287. standardPlanInfoDiscountBox.isHidden = false
  1288. advancedPlanInfoDiscountBox.isHidden = false
  1289. permanentInfoDiscountBox.isHidden = false
  1290. standardPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProStandard_dmg)
  1291. advancedPlanPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProAdvanced_dmg)
  1292. permanentPurchaseLabel.stringValue = model.getDisplayPrice(.pdfReaderProPermanent_dmg)
  1293. standardPlanInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProStandard_dmg, pointNum: 0, hasPrefix: false)
  1294. advancedPlanInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProAdvanced_dmg, pointNum: 0, hasPrefix: false)
  1295. permanentInfoDiscountView_.label.stringValue = "-"+model.getDMGDisplayAmountPrice(.pdfReaderProPermanent_dmg, pointNum: 0, hasPrefix: false)
  1296. standardPurchaseOriPriceLbl.isHidden = false
  1297. standardPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProStandard_dmg), attributes: originalPriceAttri_)
  1298. advancedPurchaseOriPriceLbl.isHidden = false
  1299. advancedPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProAdvanced_dmg), attributes: originalPriceAttri_)
  1300. permanentPurchaseOriPriceLbl.isHidden = false
  1301. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: model.getOriginalPrice(.pdfReaderProPermanent_dmg), attributes: originalPriceAttri_)
  1302. } else {
  1303. standardPurchaseOriPriceLbl.isHidden = true
  1304. advancedPurchaseOriPriceLbl.isHidden = true
  1305. permanentPurchaseOriPriceLbl.isHidden = true
  1306. standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
  1307. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  1308. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
  1309. }
  1310. } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
  1311. guard let productModels = model.dmgProductDatas?.listingProducts else { return }
  1312. for productModel in productModels {
  1313. if productModel.code == "advanced-annual-subscription" {
  1314. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  1315. guard let self = self else { return }
  1316. guard let results: KMMemberProductResult = result else { return }
  1317. guard let productModels2 = results.listingProducts else { return }
  1318. for productModel2 in productModels2 {
  1319. if productModel2.code == "advanced-annual-subscription" {
  1320. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  1321. }
  1322. }
  1323. }
  1324. } else if productModel.code == "advanced-permanent-blackFive" {
  1325. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  1326. guard let self = self else { return }
  1327. guard let results: KMMemberProductResult = result else { return }
  1328. guard let productModels2 = results.listingProducts else { return }
  1329. for productModel2 in productModels2 {
  1330. if productModel2.code == "advanced-annual-subscription-blackFive" {
  1331. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. } else {
  1338. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  1339. }
  1340. #else
  1341. // AppStore 免费版本
  1342. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product, model.checkSubscriptionOffer(for: product) == .freeTrial {
  1343. }
  1344. var showCNY = false
  1345. if let localeId = IAPProductsManager.default()?.allAccessPackPermanent_lite?.product?.priceLocale.identifier {
  1346. showCNY = localeId.contains("zh_CN")
  1347. }
  1348. if discountType_ == .newUserGift {
  1349. permanentInfoDiscountBox.isHidden = false
  1350. permanentPurchaseOriPriceLbl.isHidden = false
  1351. if showCNY {
  1352. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 798.00", attributes: originalPriceAttri_)
  1353. } else{
  1354. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
  1355. }
  1356. } else if discountType_ == .advancedYearSubscribeTrialingCancel {
  1357. permanentInfoDiscountBox.isHidden = false
  1358. permanentPurchaseOriPriceLbl.isHidden = false
  1359. if showCNY {
  1360. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 798.00", attributes: originalPriceAttri_)
  1361. } else{
  1362. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
  1363. }
  1364. } else {
  1365. let iapProduct = IAPProductsManager.default()?.fourDevicesAllAccessPackNew6Months_lite
  1366. let isNewUser = IAPReceiptTool.isNewUser(with: _fetchReceiptModel(), withGroupIdentifier: iapProduct?.product?.subscriptionGroupIdentifier)
  1367. if isNewUser {
  1368. permanentInfoDiscountBox.isHidden = false
  1369. permanentPurchaseOriPriceLbl.isHidden = false
  1370. if showCNY {
  1371. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "¥ 798.00", attributes: originalPriceAttri_)
  1372. } else{
  1373. permanentPurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: "$ 119.99", attributes: originalPriceAttri_)
  1374. }
  1375. } else {
  1376. permanentPurchaseOriPriceLbl.isHidden = true
  1377. }
  1378. }
  1379. if self.discountPermanent4.isHidden == false { // 有活动
  1380. permanentInfoDiscountBox.isHidden = true
  1381. }
  1382. // 重新刷新 UI
  1383. self.refreshPurchaseSwitch()
  1384. #endif
  1385. #else
  1386. // AppStore 付费版
  1387. advancedPurchaseOriPriceLbl.isHidden = true
  1388. permanentPurchaseOriPriceLbl.isHidden = true
  1389. #endif
  1390. }
  1391. private func _trackComparisonEvent(params: [String : String]) {
  1392. #if VERSION_FREE
  1393. #if VERSION_DMG
  1394. #else
  1395. FMTrackEventManager.defaultManager.trackEvent(event: "ComparisonTableNew", withProperties: params)
  1396. #endif
  1397. #endif
  1398. }
  1399. private func _loginAfterAction(type: KMSubscribeWaterMarkType?) {
  1400. let info = KMMemberInfo.shared
  1401. var expired = info.vip_status == 2 || info.vip_status == 4
  1402. let state = info.userScenarioType
  1403. let platforms = info.userPlatforms()
  1404. let vip_levels = info.vip_levels
  1405. let vip_paymentModel = info.vip_paymentModel
  1406. if platforms.contains("mac") == false && vip_paymentModel == "1" {
  1407. let alert = NSAlert()
  1408. alert.alertStyle = .critical
  1409. 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: "")
  1410. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1411. alert.runModal()
  1412. window?.close()
  1413. } else if platforms.count == 1 && platforms.first == "ios" && info.vip_levels == "3" && vip_paymentModel == "2" { // ios单平台高级版永久账户
  1414. KMMemberInfo.shared.productCompareShow()
  1415. return
  1416. } else if platforms.count == 1 && platforms.first == "mac" && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac 单平台高级版永久账户
  1417. // 关闭比较表,可以直接使用高级功能
  1418. window?.close()
  1419. return
  1420. } else if platforms.count == 2 && platforms.contains("windows") && platforms.contains("mac") && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac & Windows 双平台高级永久账户
  1421. // 关闭比较表,可以直接使用高级功能
  1422. window?.close()
  1423. return
  1424. } else if platforms.count == 1 && platforms.first == "android" && info.vip_levels == "3" && vip_paymentModel == "1" && info.vip_cycle == 1 { // Android单平台高级版月订阅账户
  1425. // 关闭比较表,可以直接使用高级功能
  1426. let alert = NSAlert()
  1427. alert.alertStyle = .critical
  1428. 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: "")
  1429. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1430. alert.runModal()
  1431. window?.close()
  1432. return
  1433. } else if platforms.count == 4 && vip_levels == "2" && vip_paymentModel == "1" && info.vip_cycle == 4 { // 全平台标准版年订阅账户 不支持升级,关闭比较表,可以直接使用非转档的高级功能
  1434. if type?.isConvertType() == false {
  1435. self.closeWindow()
  1436. return
  1437. }
  1438. let alert = NSAlert()
  1439. alert.alertStyle = .critical
  1440. 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: "")
  1441. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1442. alert.runModal()
  1443. self.closeWindow()
  1444. return
  1445. } else {
  1446. self.closeWindow()
  1447. return
  1448. }
  1449. }
  1450. private func _trackPurchaseCampaignEvent() {
  1451. if self.discountType == .newUserGift {
  1452. self.trackEvent(eventName: "Purchase_Campaign", params: ["Campaign_NewUser":"Tbr_Coupon"], platform: .firebase)
  1453. } else if self.discountType == .freeTrail {
  1454. self.trackEvent(eventName: "Purchase_Campaign", params: ["Campaign_NewUser":"Tbr_FreeTrial"], platform: .firebase)
  1455. } else if self.discountType_ == .advancedYearSubscribeTrialingCancel {
  1456. self.trackEvent(eventName: self.kEventName, params: self.kEventParams, platform: .firebase)
  1457. }
  1458. }
  1459. private func _appstoreCanPurchase(product: IAPProduct?) -> Bool {
  1460. #if VERSION_FREE
  1461. if discountType == .advancedYearSubscribeTrialingCancel {
  1462. if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite ||
  1463. product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
  1464. #if VERSION_DMG
  1465. #else
  1466. if KMMemberInfo.shared.isLogin == false {
  1467. let result = IAPReceiptTool.isFreeTrailing(with: IAPProductsManager.default().receiptModel, withProductId: (product?.product?.productIdentifier)!)
  1468. if result {
  1469. // return
  1470. }
  1471. } else {
  1472. let member = KMMemberInfo.shared
  1473. if member.is_advanced_year_subscribe() && member.is_trailing() {
  1474. showAlert(message: NSLocalizedString("You are in a 7-day free trial. Please purchase the product after it expires.", comment: ""))
  1475. return false
  1476. }
  1477. }
  1478. #endif
  1479. }
  1480. }
  1481. #endif
  1482. return true
  1483. }
  1484. private func _dmgCanPurchase(state: KMCompareTableType, tag: Int) -> Bool {
  1485. let isStandardAnnualSubscription = tag == 1
  1486. if state == .dmg_Base && isStandardAnnualSubscription && discountType == .advancedYearSubscribeTrialingCancel {
  1487. let member = KMMemberInfo.shared
  1488. if member.is_advanced_year_subscribe() && member.is_trailing() {
  1489. showAlert(message: NSLocalizedString("You are in a 7-day free trial. Please purchase the product after it expires.", comment: ""))
  1490. return false
  1491. }
  1492. }
  1493. return true
  1494. }
  1495. private func _appstorePurchaseGetProduct(state: KMCompareTableType, tag: Int, isPurchaseSwitch: Bool) -> IAPProduct? {
  1496. var product: IAPProduct?
  1497. if state == .lite_Base {
  1498. if tag == 0 {
  1499. if isPurchaseSwitch {
  1500. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1501. } else {
  1502. product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  1503. }
  1504. } else if tag == 3 {
  1505. product = IAPProductsManager.default().allAccessPackPermanent_lite
  1506. } else {
  1507. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1508. }
  1509. } else if state == .lite_MacWindows {
  1510. if tag == 2 {
  1511. let platforms = KMMemberInfo.shared.vip_platforms
  1512. let platformsArray = platforms
  1513. .components(separatedBy: ",")
  1514. .map { $0.trimmingCharacters(in: .whitespaces) }
  1515. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  1516. if platformsArray.count == 1 {
  1517. product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
  1518. } else if platformsArray.count == 2 {
  1519. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1520. }
  1521. } else {
  1522. if platformsArray.count == 1 {
  1523. product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
  1524. } else if platformsArray.count == 2 {
  1525. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1526. } else {
  1527. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1528. }
  1529. }
  1530. }
  1531. }
  1532. return product
  1533. }
  1534. // 获取 Apple 凭证模型
  1535. private func _fetchReceiptModel() -> IAPReceiptModel? {
  1536. return IAPProductsManager.default().receiptModel
  1537. }
  1538. // MARK: Button Actions
  1539. @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
  1540. if model.isPurchaseSwitch {
  1541. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
  1542. } else {
  1543. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
  1544. }
  1545. if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
  1546. var product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  1547. if model.isPurchaseSwitch {
  1548. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1549. }
  1550. let type = subscribeType
  1551. KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
  1552. if KMMemberInfo.shared.isLogin == false {
  1553. return
  1554. }
  1555. let info = KMMemberInfo.shared
  1556. let expired = info.vip_status == 2 || info.vip_status == 4
  1557. if info.vip_levels == "1" || expired {
  1558. if self.model.isPurchaseSwitch { // 免费账户/订阅过期账户
  1559. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: self.model.isCancelAutoRenew)
  1560. } else {
  1561. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: self.model.isCancelAutoRenew)
  1562. }
  1563. return
  1564. } else {
  1565. self._loginAfterAction(type: type)
  1566. }
  1567. }
  1568. return
  1569. }
  1570. if KMMemberInfo.shared.validFlag == "5" {
  1571. KMMemberPromptWC.shared.showWindow(nil)
  1572. KMMemberPromptWC.shared.tipType = .signouting
  1573. } else {
  1574. if model.isPurchaseSwitch {
  1575. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: model.isCancelAutoRenew)
  1576. } else {
  1577. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: model.isCancelAutoRenew)
  1578. }
  1579. addWaitingView(to: window?.contentView ?? NSView())
  1580. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_6Mon"])
  1581. if model.isShowSale {
  1582. kEventTag = 1
  1583. if model.isPurchaseSwitch {
  1584. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12Mon"], platform: .AppCenter)
  1585. } else {
  1586. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6Mon"], platform: .AppCenter)
  1587. }
  1588. }
  1589. }
  1590. }
  1591. func showDiscountToSaveWindow() {
  1592. guard KMDiscountToSaveWindowController.needShow() else { return }
  1593. guard let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  1594. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.image, highlight: true)) else { return }
  1595. addWaitingView(to: window?.contentView ?? NSView())
  1596. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  1597. guard let self = self else { return }
  1598. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1599. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_PromotionalOffer"], platform: .AppCenter)
  1600. let winC = KMDiscountToSaveWindowController(windowNibName: "KMDiscountToSaveWindowController")
  1601. self.discountToSaveWinC = winC
  1602. self.window?.beginSheet(winC.window!) { _ in }
  1603. winC.imgIv.image = image
  1604. winC.itemClick = { idx in
  1605. self.window?.endSheet(self.discountToSaveWinC?.window ?? NSWindow())
  1606. self.discountToSaveWinC = nil
  1607. if idx == 2 {
  1608. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Subscribe"], platform: .AppCenter)
  1609. } else if idx == 1 {
  1610. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Cancel"], platform: .AppCenter)
  1611. }
  1612. }
  1613. }
  1614. }
  1615. @IBAction func buttonItemClicked_Restore(_ sender: Any) {
  1616. model.productRestore()
  1617. addWaitingView(to: window?.contentView ?? NSView())
  1618. }
  1619. @IBAction func buttonItemClicked_Upgrade(_ sender: Any) {
  1620. NSWorkspace.shared.open(URL(string: "macappstore://apps.apple.com/app/id825459243?mt=12")!)
  1621. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Premium"])
  1622. }
  1623. @IBAction func privacyPolicyAction(_ sender: NSButton) {
  1624. model.privacyPolicyAction()
  1625. }
  1626. @IBAction func termOfSerAction(_ sender: NSButton) {
  1627. model.termOfSerAction()
  1628. }
  1629. @IBAction func buttonItemClicked_LicenseUpgrade(_ sender: Any) {
  1630. IAPProductsManager.default().make(IAPProductsManager.default().allAccessPackPermanent_lite)
  1631. addWaitingView(to: window?.contentView ?? NSView())
  1632. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Permanent"])
  1633. trackEvent_free(eventName: "ComparisonTableNew", params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"], platform: .AppCenter)
  1634. }
  1635. @IBAction func buttonItemClicked_AboutSubscriptions(_ sender: Any) {
  1636. let tMessage = """
  1637. Subscription plans:
  1638. Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)
  1639. - Subscriptions will be charged through your iTunes account at the confirmation of purchase.
  1640. - Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.
  1641. - 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.
  1642. - You may manage your subscriptions in your iTunes Account Settings after purchase.
  1643. - No cancellation of the current subscription is allowed during an active subscription period.
  1644. - Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service
  1645. - Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy
  1646. """
  1647. let alert = NSAlert()
  1648. alert.alertStyle = .informational
  1649. alert.messageText = NSLocalizedString(tMessage, comment: "")
  1650. alert.runModal()
  1651. }
  1652. @IBAction func buttonItemClicked_CloseWindow(_ sender: Any) {
  1653. close()
  1654. }
  1655. @objc func switchAction(_ sender: NSButton) {
  1656. model.isPurchaseSwitch.toggle()
  1657. }
  1658. @IBAction func appstorePurchaseAction(_ sender: NSButton) {
  1659. if KMMemberInfo.shared.validFlag == "5" {
  1660. KMMemberPromptWC.shared.showWindow(nil)
  1661. KMMemberPromptWC.shared.tipType = .signouting
  1662. } else {
  1663. #if !VERSION_DMG
  1664. // addWaitingView(to: window?.contentView ?? NSView())
  1665. #endif
  1666. let product = self._appstorePurchaseGetProduct(state: model.state, tag: sender.tag, isPurchaseSwitch: model.isPurchaseSwitch)
  1667. if product == IAPProductsManager.default().allAccessPackPermanent_lite {
  1668. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"])
  1669. } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite {
  1670. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
  1671. } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
  1672. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
  1673. }
  1674. let type = subscribeType
  1675. if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
  1676. KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
  1677. if KMMemberInfo.shared.isLogin == false {
  1678. return
  1679. }
  1680. let info = KMMemberInfo.shared
  1681. let expired = info.vip_status == 2 || info.vip_status == 4
  1682. if info.vip_levels == "1" || expired {
  1683. self.model.appstorePurchaseAction(sender.tag, discountType: self.discountType_) { [weak self] success, msg in
  1684. }
  1685. return
  1686. } else {
  1687. self._loginAfterAction(type: type)
  1688. return
  1689. }
  1690. }
  1691. return
  1692. }
  1693. // addWaitingView(to: window?.contentView ?? NSView())
  1694. #if VERSION_DMG
  1695. if _dmgCanPurchase(state: model.state, tag: sender.tag) == false {
  1696. return
  1697. }
  1698. #else
  1699. if _appstoreCanPurchase(product: product) == false {
  1700. return
  1701. }
  1702. #endif
  1703. model.appstorePurchaseAction(sender.tag, discountType: discountType_) { [weak self] success, msg in
  1704. guard let self = self else { return }
  1705. }
  1706. #if VERSION_DMG
  1707. close()
  1708. #endif
  1709. }
  1710. }
  1711. @objc func closeAction() {
  1712. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_Cancel"])
  1713. self.window?.close()
  1714. }
  1715. // MARK: - InAppPurchaseManager Notification
  1716. @objc func IAPProductFailedNotification(_ notification: Notification) {
  1717. removeWaitingView(from: window?.contentView ?? NSView())
  1718. }
  1719. @objc func IAPProductPurchasedNotification(_ notification: Notification) {
  1720. KMMainThreadExecute {
  1721. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1722. self.reloadData()
  1723. if KMMemberInfo.shared.isLogin {
  1724. } else {
  1725. if let _ = KMLoginWindowsController.shared.subscribeType { // 付费->比较表->购买回来后 需要关闭登陆窗口
  1726. KMLoginWindowsController.shared.closeWindow()
  1727. }
  1728. }
  1729. }
  1730. #if VERSION_FREE
  1731. #if VERSION_DMG
  1732. // DMG
  1733. #else
  1734. // AppStore 免费版本
  1735. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  1736. if kEventTag == 1 {
  1737. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6MonthPaid"], platform: .AppCenter)
  1738. }
  1739. } else if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  1740. if kEventTag == 1 {
  1741. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12MonthPaid"], platform: .AppCenter)
  1742. }
  1743. }
  1744. #endif
  1745. #else
  1746. // AppStore 付费版
  1747. #endif
  1748. }
  1749. @objc func IAPProductLoadedNotification(_ notification: Notification) {
  1750. KMMainThreadExecute {
  1751. self.reloadData()
  1752. }
  1753. }
  1754. @objc func IAPProductRestoreFinishedNotification(_ notification: Notification) {
  1755. KMMainThreadExecute {
  1756. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1757. self.reloadData()
  1758. }
  1759. }
  1760. @objc func IAPProductRestoreFailedNotification(_ notification: Notification) {
  1761. removeWaitingView(from: window?.contentView ?? NSView())
  1762. }
  1763. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  1764. KMMainThreadExecute {
  1765. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1766. self.reloadData()
  1767. DispatchQueue.global().async { [weak self] in
  1768. guard let self = self else { return }
  1769. if KMMemberInfo.shared.isLogin {
  1770. self.model.appStoreEquityVerification(notification) { success, msg in
  1771. DispatchQueue.main.async {
  1772. if success {
  1773. // self.showAlert(message: NSLocalizedString("Binding Interest Success!", comment: ""))
  1774. KMUserInfoVCModel().refreshUserInfo { success, msg,dic in
  1775. if(success) {
  1776. // 签到
  1777. KMCheckInManager.default.checkIn(refreshData: true, callback: nil)
  1778. NotificationCenter.default.post(name: NSNotification.Name.KMMemberInfoChange, object: self)
  1779. KMCancelSubscribeSuccessWindowController.shared.saveRecord()
  1780. self._trackPurchaseCampaignEvent()
  1781. }
  1782. }
  1783. KMMemberCenterManager.judgeTrailCancel { success, resultModel, error in
  1784. if success {
  1785. KMCheckInManager.default.trailCancel = resultModel?.result ?? false
  1786. }
  1787. }
  1788. self.window?.close()
  1789. } else {
  1790. self.handleVerificationFailure(msg: msg)
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. }
  1797. }
  1798. @objc func themeChanged(_ notification: Notification) {
  1799. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1800. self.box.fillColor = KMAppearance.Layout.l1Color()
  1801. self.labelbox.fillColor = .clear
  1802. self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
  1803. self.textView.backgroundColor = .clear
  1804. self.textView.textColor = NSColor.white.withAlphaComponent(0.5)
  1805. self.value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1806. self.permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1807. }
  1808. }
  1809. // MARK: - Bind Method
  1810. func bindViewModel() -> Void {
  1811. model.$state
  1812. .receive(on: RunLoop.main)
  1813. .sink { [weak self] newValue in
  1814. }
  1815. .store(in: &cancellables)
  1816. model.$isPurchaseSwitch
  1817. .receive(on: RunLoop.main)
  1818. .sink { [weak self] newValue in
  1819. self?.reloadDataContent()
  1820. #if VERSION_FREE
  1821. #if VERSION_DMG
  1822. // DMG
  1823. #else
  1824. // AppStore 免费版本
  1825. self?.refreshPurchaseSwitch()
  1826. #endif
  1827. #else
  1828. // AppStore 付费版
  1829. #endif
  1830. }
  1831. .store(in: &cancellables)
  1832. }
  1833. }
  1834. // MARK: - NSTableViewDelegate, NSTableViewDataSource
  1835. extension KMProductCompareWC: NSTableViewDelegate, NSTableViewDataSource {
  1836. func numberOfRows(in tableView: NSTableView) -> Int {
  1837. return model.dataSource.count
  1838. }
  1839. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1840. let object = model.dataSource[row]
  1841. if let stringObject = object as? String {
  1842. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1843. cellView.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1844. if stringObject == "Membership Benefits" {
  1845. cellView.leftImageView?.isHidden = false
  1846. cellView.textField?.textColor = NSColor(named: "6D4D09") ?? .gray
  1847. } else {
  1848. cellView.leftImageView?.isHidden = true
  1849. cellView.textField?.textColor = NSColor(named: "0E1114") ?? .white
  1850. }
  1851. cellView.textfieldLeft.constant = cellView.leftImageView!.isHidden ? 32.0 : 62.0
  1852. if model.state == .dmg_Base {
  1853. cellView.selectBoxLeft.constant = 352.0 + 149.5 + 149.5
  1854. cellView.selectBoxWidth.constant = 149.5
  1855. } else if model.state == .dmg_Upgrades1 {
  1856. cellView.selectBoxLeft.constant = 352.0
  1857. cellView.selectBoxWidth.constant = 320.0
  1858. } else if model.state == .dmg_Upgrades2 {
  1859. cellView.selectBoxLeft.constant = 352.0
  1860. cellView.selectBoxWidth.constant = 320.0
  1861. } else if model.state == .lite_Base {
  1862. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1863. cellView.selectBoxWidth.constant = 240.0
  1864. } else if model.state == .lite_MacWindows {
  1865. cellView.selectBoxLeft.constant = 352.0
  1866. cellView.selectBoxWidth.constant = 320.0
  1867. } else if model.state == .pro_Base {
  1868. cellView.selectBoxLeft.constant = 352.0
  1869. cellView.selectBoxWidth.constant = 299.0
  1870. } else if model.state == .pro_Advanced {
  1871. cellView.selectBoxLeft.constant = 352.0
  1872. cellView.selectBoxWidth.constant = 320.0
  1873. } else {
  1874. // model.state == .trial
  1875. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1876. cellView.selectBoxWidth.constant = 240.0
  1877. }
  1878. return cellView
  1879. }
  1880. } else if let arrayObject = object as? [String] {
  1881. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1882. let value1 = arrayObject.indices.contains(0) ? arrayObject[0] : ""
  1883. let value2 = arrayObject.indices.contains(1) ? arrayObject[1] : ""
  1884. let value3 = arrayObject.indices.contains(2) ? arrayObject[2] : ""
  1885. let value4 = arrayObject.indices.contains(3) ? arrayObject[3] : ""
  1886. let value5 = arrayObject.indices.contains(4) ? arrayObject[4] : ""
  1887. let value6 = arrayObject.indices.contains(5) ? arrayObject[5] : ""
  1888. cellView.textField?.stringValue = NSLocalizedString(value1, comment: "")
  1889. cellView.lineBox?.isHidden = false
  1890. if row + 1 == model.dataSource.count || model.dataSource[row + 1] is String {
  1891. cellView.lineBox?.isHidden = true
  1892. }
  1893. checkOrNot(cellView)
  1894. cellView.boxBottomConst?.constant = (row + 2 == model.dataSource.count) ? 0 : -4
  1895. updateCellView(cellView, value1: value2, value2: value3, value3: value4, value4: value5, value5: value6)
  1896. return cellView
  1897. }
  1898. } else if object is [String: Any] {
  1899. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableEmptyCell"), owner: self) as? KMProductCompareTableEmptyCell {
  1900. return cellView
  1901. }
  1902. }
  1903. return nil
  1904. }
  1905. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1906. let object = model.dataSource[row]
  1907. var cellView: NSTableCellView?
  1908. if let stringObject = object as? String {
  1909. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1910. cell.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1911. cellView = cell
  1912. }
  1913. } else if let arrayObject = object as? [String] {
  1914. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1915. cell.textField?.stringValue = NSLocalizedString(arrayObject[0], comment: "")
  1916. cellView = cell
  1917. }
  1918. } else if object is [String: Any] {
  1919. return 40
  1920. }
  1921. if let view = cellView {
  1922. view.layoutSubtreeIfNeeded()
  1923. return view.frame.size.height
  1924. } else {
  1925. return 44
  1926. }
  1927. }
  1928. private func updateCellView(_ cellView: KMProductCompareTableCell, value1: String, value2: String, value3: String, value4: String, value5: String) {
  1929. if model.state == .dmg_Base {
  1930. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1931. configureCellView(cellView, value: value2, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1932. configureCellView(cellView, value: value3, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1933. configureCellView(cellView, value: value4, label: cellView.value4Label, imageView: cellView.value4ImageView, platformsBox: cellView.platformsBox4)
  1934. } else if model.state == .dmg_Upgrades1 {
  1935. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1936. } else if model.state == .dmg_Upgrades2 {
  1937. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1938. } else if model.state == .lite_Base {
  1939. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1940. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1941. configureCellView(cellView, value: value4, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1942. } else if model.state == .lite_MacWindows {
  1943. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1944. } else if model.state == .pro_Base {
  1945. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1946. configureCellView(cellView, value: value5, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1947. } else if model.state == .pro_Advanced {
  1948. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1949. } else {
  1950. // model.state == .trial
  1951. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1952. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1953. }
  1954. }
  1955. private func configureCellView(_ cellView: KMProductCompareTableCell, value: String, label: NSTextField?, imageView: NSImageView?, platformsBox: NSBox?) {
  1956. platformsBox?.isHidden = true
  1957. label?.isHidden = false
  1958. imageView?.isHidden = false
  1959. switch value {
  1960. case "X":
  1961. label?.stringValue = ""
  1962. imageView?.image = NSImage(named: "compare_nosupport")
  1963. case "✓":
  1964. label?.stringValue = ""
  1965. imageView?.image = NSImage(named: "compare_support")
  1966. case "∞":
  1967. label?.stringValue = ""
  1968. imageView?.image = NSImage(named: "compare_00")
  1969. default:
  1970. if value == "mac, windows, ios, android" ||
  1971. value == "mac, windows" ||
  1972. value == "mac" {
  1973. platformsBox?.isHidden = false
  1974. label?.isHidden = true
  1975. imageView?.isHidden = true
  1976. if value == "mac, windows, ios, android" {
  1977. // platformsBox?.contentView = platformsView4
  1978. } else if value == "mac, windows" {
  1979. platformsBox?.contentView = platformsView2
  1980. } else if value == "mac" {
  1981. platformsBox?.contentView = platformsView1
  1982. }
  1983. } else {
  1984. label?.stringValue = NSLocalizedString(value, comment: "")
  1985. imageView?.image = nil
  1986. }
  1987. }
  1988. }
  1989. private func checkOrNot(_ cellView: KMProductCompareTableCell) {
  1990. cellView.selectBox1.isHidden = true
  1991. cellView.selectBox2.isHidden = true
  1992. cellView.selectBox3.isHidden = true
  1993. cellView.selectBox4.isHidden = true
  1994. cellView.cellView1.isHidden = true
  1995. cellView.cellView2.isHidden = true
  1996. cellView.cellView3.isHidden = true
  1997. cellView.cellView4.isHidden = true
  1998. if model.state == .dmg_Base {
  1999. cellView.selectBox3.isHidden = false
  2000. cellView.cellView1.isHidden = false
  2001. cellView.cellView2.isHidden = false
  2002. cellView.cellView3.isHidden = false
  2003. cellView.cellView4.isHidden = false
  2004. cellView.viewWidth1.constant = 149.5
  2005. cellView.viewWidth2.constant = 149.5
  2006. cellView.viewWidth3.constant = 149.5
  2007. cellView.viewWidth4.constant = 149.5
  2008. } else if model.state == .dmg_Upgrades1 {
  2009. cellView.selectBox1.isHidden = false
  2010. cellView.cellView1.isHidden = false
  2011. cellView.viewWidth1.constant = 320.0
  2012. } else if model.state == .dmg_Upgrades2 {
  2013. cellView.selectBox1.isHidden = false
  2014. cellView.cellView1.isHidden = false
  2015. cellView.viewWidth1.constant = 320.0
  2016. } else if model.state == .lite_Base {
  2017. cellView.selectBox2.isHidden = false
  2018. cellView.cellView1.isHidden = false
  2019. cellView.cellView2.isHidden = false
  2020. cellView.cellView3.isHidden = false
  2021. cellView.viewWidth1.constant = 179.0
  2022. cellView.viewWidth2.constant = 240.0
  2023. cellView.viewWidth3.constant = 240.0
  2024. } else if model.state == .lite_MacWindows {
  2025. cellView.selectBox1.isHidden = false
  2026. cellView.viewWidth1.constant = 320.0
  2027. cellView.cellView1.isHidden = false
  2028. } else if model.state == .pro_Base {
  2029. cellView.selectBox1.isHidden = false
  2030. cellView.viewWidth1.constant = 299.0
  2031. cellView.cellView1.isHidden = false
  2032. cellView.cellView2.isHidden = false
  2033. cellView.viewWidth2.constant = 299.0
  2034. } else if model.state == .pro_Advanced {
  2035. cellView.selectBox1.isHidden = false
  2036. cellView.viewWidth1.constant = 320.0
  2037. cellView.cellView1.isHidden = false
  2038. } else {
  2039. // model.state == .trial
  2040. cellView.cellView1.isHidden = false
  2041. cellView.cellView2.isHidden = false
  2042. cellView.selectBox2.isHidden = false
  2043. cellView.viewWidth1.constant = 179.0
  2044. cellView.viewWidth2.constant = 240.0
  2045. }
  2046. }
  2047. }
  2048. class KMProductCompareTableCell: NSTableCellView {
  2049. @IBOutlet weak var bgColorView: NSView!
  2050. @IBOutlet @objc weak var cellView1: NSView!
  2051. @IBOutlet @objc weak var cellView2: NSView!
  2052. @IBOutlet @objc weak var cellView3: NSView!
  2053. @IBOutlet @objc weak var cellView4: NSView!
  2054. @IBOutlet weak var value1Label: NSTextField!
  2055. @IBOutlet weak var value2Label: NSTextField!
  2056. @IBOutlet weak var value3Label: NSTextField!
  2057. @IBOutlet weak var value4Label: NSTextField!
  2058. @IBOutlet weak var value1ImageView: NSImageView!
  2059. @IBOutlet weak var value2ImageView: NSImageView!
  2060. @IBOutlet weak var value3ImageView: NSImageView!
  2061. @IBOutlet weak var value4ImageView: NSImageView!
  2062. @IBOutlet weak var lineBox: NSBox!
  2063. @IBOutlet weak var boxBottomConst: NSLayoutConstraint!
  2064. @IBOutlet @objc weak var platformsBox1: NSBox!
  2065. @IBOutlet @objc weak var platformsBox2: NSBox!
  2066. @IBOutlet @objc weak var platformsBox3: NSBox!
  2067. @IBOutlet @objc weak var platformsBox4: NSBox!
  2068. @IBOutlet @objc weak var selectBox1: NSBox!
  2069. @IBOutlet @objc weak var selectBox2: NSBox!
  2070. @IBOutlet @objc weak var selectBox3: NSBox!
  2071. @IBOutlet @objc weak var selectBox4: NSBox!
  2072. @IBOutlet weak var viewWidth1: NSLayoutConstraint!
  2073. @IBOutlet weak var viewWidth2: NSLayoutConstraint!
  2074. @IBOutlet weak var viewWidth3: NSLayoutConstraint!
  2075. @IBOutlet weak var viewWidth4: NSLayoutConstraint!
  2076. override func awakeFromNib() {
  2077. super.awakeFromNib()
  2078. bgColorView.wantsLayer = true
  2079. updateViewColor()
  2080. NotificationCenter.default.addObserver(
  2081. self,
  2082. selector: #selector(themeChanged(_:)),
  2083. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  2084. object: nil
  2085. )
  2086. }
  2087. deinit {
  2088. NotificationCenter.default.removeObserver(self)
  2089. }
  2090. @objc func themeChanged(_ notification: Notification) {
  2091. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  2092. self.updateViewColor()
  2093. }
  2094. }
  2095. private func updateViewColor() {
  2096. var textColor = NSColor(red: 68.0 / 255.0, green: 68.0 / 255.0, blue: 68.0 / 255.0, alpha: 1.0)
  2097. var subtextColor = NSColor(red: 141.0 / 255.0, green: 141.0 / 255.0, blue: 141.0 / 255.0, alpha: 1.0)
  2098. var lineColor = NSColor(red: 204.0 / 255.0, green: 204.0 / 255.0, blue: 204.0 / 255.0, alpha: 0.4)
  2099. if let layer = bgColorView.layer {
  2100. if KMAppearance.isDarkMode() {
  2101. layer.backgroundColor = NSColor(red: 24.0 / 255.0, green: 22.0 / 255.0, blue: 31.0 / 255.0, alpha: 1.0).cgColor
  2102. textColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.8)
  2103. subtextColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.6)
  2104. lineColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.15)
  2105. } else {
  2106. layer.backgroundColor = NSColor(red: 247.0 / 255.0, green: 245.0 / 255.0, blue: 1.0, alpha: 1.0).cgColor
  2107. }
  2108. }
  2109. value1Label.textColor = subtextColor
  2110. value2Label.textColor = subtextColor
  2111. value3Label.textColor = subtextColor
  2112. value4Label.textColor = subtextColor
  2113. lineBox.fillColor = lineColor
  2114. textField?.textColor = textColor
  2115. }
  2116. }
  2117. class KMProductCompareTableHeaderCell: NSTableCellView {
  2118. @IBOutlet weak var contentView: NSView?
  2119. @IBOutlet weak var leftImageView: NSImageView?
  2120. @IBOutlet weak var textfieldLeft: NSLayoutConstraint!
  2121. @IBOutlet weak var selectBoxLeft: NSLayoutConstraint!
  2122. @IBOutlet weak var selectBoxWidth: NSLayoutConstraint!
  2123. deinit {
  2124. NotificationCenter.default.removeObserver(self)
  2125. }
  2126. override func awakeFromNib() {
  2127. super.awakeFromNib()
  2128. contentView?.wantsLayer = true
  2129. updateViewColor()
  2130. NotificationCenter.default.addObserver(
  2131. self,
  2132. selector: #selector(themeChanged(_:)),
  2133. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  2134. object: nil
  2135. )
  2136. }
  2137. @objc private func themeChanged(_ notification: Notification) {
  2138. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  2139. self.updateViewColor()
  2140. }
  2141. }
  2142. private func updateViewColor() {
  2143. if KMAppearance.isDarkMode() {
  2144. contentView?.layer?.backgroundColor = NSColor(red: 40/255, green: 38/255, blue: 47/255, alpha: 1).cgColor
  2145. } else {
  2146. contentView?.layer?.backgroundColor = NSColor(red: 237/255, green: 231/255, blue: 255/255, alpha: 1).cgColor
  2147. }
  2148. textField?.textColor = KMAppearance.Layout.h0Color()
  2149. textField?.font = NSFont.boldSystemFont(ofSize: 14.0)
  2150. }
  2151. }
  2152. class KMProductCompareTableEmptyCell: NSTableCellView {
  2153. override func awakeFromNib() {
  2154. super.awakeFromNib()
  2155. self.wantsLayer = true
  2156. updateViewColor()
  2157. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  2158. }
  2159. deinit {
  2160. DistributedNotificationCenter.default.removeObserver(self)
  2161. }
  2162. @objc private func themeChanged(_ notification: Notification) {
  2163. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  2164. self.updateViewColor()
  2165. }
  2166. }
  2167. private func updateViewColor() {
  2168. if KMAppearance.isDarkMode() {
  2169. self.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1.0).cgColor
  2170. } else {
  2171. self.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1.0, alpha: 1.0).cgColor
  2172. }
  2173. }
  2174. }