KMProductCompareWC.swift 124 KB

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