KMProductCompareWC.swift 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  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. @objcMembers
  10. class KMProductCompareWC: NSWindowController {
  11. @objc var modalSession: NSApplication.ModalSession?
  12. @IBOutlet @objc weak var tableView: NSTableView!
  13. @IBOutlet @objc weak var titleLabel: NSTextField!
  14. @IBOutlet @objc weak var topMainBox: NSBox!
  15. @IBOutlet @objc weak var topMainView: NSView!
  16. @IBOutlet @objc weak var topsubBox1: NSBox!
  17. @IBOutlet @objc weak var topSelectBox1: NSBox!
  18. @IBOutlet @objc weak var topsubBox2: NSBox!
  19. @IBOutlet @objc weak var topSelectBox2: NSBox!
  20. @IBOutlet @objc weak var topsubBox3: NSBox!
  21. @IBOutlet @objc weak var topSelectBox3: NSBox!
  22. @IBOutlet @objc weak var topsubBox4: NSBox!
  23. @IBOutlet @objc weak var topSelectBox4: NSBox!
  24. @IBOutlet weak var topsubBoxWidth1: NSLayoutConstraint!
  25. @IBOutlet weak var topsubBoxWidth2: NSLayoutConstraint!
  26. @IBOutlet weak var topsubBoxWidth3: NSLayoutConstraint!
  27. @IBOutlet weak var topsubBoxWidth4: NSLayoutConstraint!
  28. @IBOutlet @objc weak var switchLabel: NSTextField!
  29. // @IBOutlet @objc weak var switchButton: NSButton!
  30. @IBOutlet @objc weak var freeInfoView: NSView!
  31. @IBOutlet @objc weak var freeInfoLabel: NSTextField!
  32. @IBOutlet @objc weak var value1InfoView: NSView!
  33. // @IBOutlet @objc weak var value1InfoBox: NSBox!
  34. @IBOutlet @objc weak var value1InfoTypeBox: NSBox!
  35. @IBOutlet @objc weak var sixMouthProLabel: NSTextField!
  36. @IBOutlet @objc weak var oneYearProLabel: NSTextField!
  37. @IBOutlet weak var backgroundImage1: NSImageView!
  38. @IBOutlet @objc weak var switchBox: NSBox!
  39. @IBOutlet @objc weak var switchBtn: NSButton!
  40. @IBOutlet @objc weak var switchCircleView: NSView!
  41. @IBOutlet @objc weak var switchCircleLeftConst: NSLayoutConstraint!
  42. @IBOutlet @objc weak var saleBox: NSBox!
  43. @IBOutlet @objc weak var saleIv: NSImageView!
  44. @IBOutlet @objc weak var saleLabel: NSTextField!
  45. @IBOutlet @objc weak var value1InfoLabel: NSTextField!
  46. @IBOutlet @objc weak var value1PurchaseLabel: NSTextField!
  47. @IBOutlet @objc weak var value1PurchaseSubLabel: NSTextField!
  48. @IBOutlet @objc weak var value1PurchaseButton: KMCustomButton!
  49. @IBOutlet @objc weak var value1PurchaseBtnLbl: NSTextField!
  50. @IBOutlet @objc weak var value1PurchaseOriPriceLbl: NSTextField!
  51. @IBOutlet @objc weak var value1PurchaseBtnLblBtn: NSButton!
  52. // 标准版年订阅
  53. @IBOutlet @objc weak var standardPlanInfoView: NSView!
  54. @IBOutlet @objc weak var standardPlanInfoLabel: NSTextField!
  55. @IBOutlet @objc weak var standardPlanPurchaseLabel: NSTextField!
  56. @IBOutlet @objc weak var standardPlanPurchaseSubLabel: NSTextField!
  57. @IBOutlet @objc weak var standardPlanPurchaseButton: NSButton!
  58. @IBOutlet @objc weak var standardPlanPurchaseLbl: NSTextField!
  59. @IBOutlet @objc weak var standardPlanPurchaseLblBtn: NSButton!
  60. @IBOutlet @objc weak var standardPlanPurchaseSubLabel2: NSTextField!
  61. // 高级版年订阅
  62. @IBOutlet @objc weak var advancedPlanInfoView: NSView!
  63. @IBOutlet @objc weak var advancedPlanInfoLabel: NSTextField!
  64. @IBOutlet @objc weak var advancedPlanPurchaseLabel: NSTextField!
  65. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel: NSTextField!
  66. @IBOutlet @objc weak var advancedPlanPurchaseButton: NSButton!
  67. @IBOutlet @objc weak var advancedPlanPurchaseLbl: NSTextField!
  68. @IBOutlet @objc weak var advancedPlanPurchaseLblBtn: NSButton!
  69. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel2: NSTextField!
  70. @IBOutlet weak var backgroundImage3: NSImageView!
  71. @IBOutlet @objc weak var discountPermanent2: NSImageView!
  72. // 买断
  73. @IBOutlet @objc weak var permanentInfoView: NSView!
  74. @IBOutlet @objc weak var permanentInfoLabel: NSTextField!
  75. @IBOutlet @objc weak var permanentPurchaseLabel: NSTextField!
  76. @IBOutlet @objc weak var permanentPurchaseSubLabel: NSTextField!
  77. @IBOutlet @objc weak var permanentPurchaseButton: NSButton!
  78. @IBOutlet @objc weak var permanentPurchaseLbl: NSTextField!
  79. @IBOutlet @objc weak var permanentPurchaseLblBtn: NSButton!
  80. @IBOutlet @objc weak var permanentPurchaseSubLabel2: NSTextField!
  81. @IBOutlet @objc weak var discountPermanent4: NSImageView!
  82. @IBOutlet @objc weak var aboutButton: NSButton!
  83. @IBOutlet @objc weak var btnRestore: HyperLinkButton!
  84. @IBOutlet @objc weak var privacyPolicyBtn: HyperLinkButton!
  85. @IBOutlet @objc weak var termOfSerBtn: HyperLinkButton!
  86. @IBOutlet @objc weak var textView: NSTextView!
  87. @IBOutlet @objc weak var specialView: NSView!
  88. @IBOutlet @objc weak var specialImageView: NSImageView!
  89. @IBOutlet @objc weak var specialLabel: NSTextField!
  90. @IBOutlet @objc weak var specialView1: NSView!
  91. @IBOutlet @objc weak var specialImageView1: NSImageView!
  92. @IBOutlet @objc weak var specialLabel1: NSTextField!
  93. @IBOutlet @objc weak var box: NSBox!
  94. @IBOutlet @objc weak var labelbox: NSBox!
  95. // @IBOutlet @objc weak var topButtonOffset: NSLayoutConstraint!
  96. @objc var value1Layer: CALayer?
  97. @objc var discountToSaveWinC: KMDiscountToSaveWindowController?
  98. @IBOutlet @objc weak var billedTopConst: NSLayoutConstraint!
  99. @IBOutlet @objc weak var discountYearly: NSImageView!
  100. @IBOutlet @objc weak var discountPermanent: NSImageView!
  101. // @IBOutlet @objc weak var discountPremium: NSImageView!
  102. @IBOutlet @objc weak var platformsView1: NSView!
  103. @IBOutlet @objc weak var platformsView2: NSView!
  104. @IBOutlet @objc weak var platformsView3: NSView!
  105. @IBOutlet @objc weak var platformsView4: NSView!
  106. private var model = KMProductModel.shared
  107. private var cancellables = Set<AnyCancellable>()
  108. var orientation: Bool = false // 是否定向跳转
  109. var orientationType: KMCompareTableType = .trial // 定向跳转比较表
  110. static let shared: KMProductCompareWC = {
  111. let windowC = KMProductCompareWC(windowNibName: "KMProductCompareWC")
  112. return windowC
  113. }()
  114. override init(window: NSWindow?) {
  115. super.init(window: window)
  116. setupNotifications()
  117. }
  118. required init?(coder: NSCoder) {
  119. super.init(coder: coder)
  120. }
  121. // MARK: - Notification Setup
  122. private func setupNotifications() {
  123. NotificationCenter.default.addObserver(
  124. self,
  125. selector: #selector(IAPProductLoadedNotification(_:)),
  126. name: NSNotification.Name(rawValue: "KMIAPProductLoadedNotification"),
  127. object: nil
  128. )
  129. NotificationCenter.default.addObserver(
  130. self,
  131. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  132. name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
  133. object: nil
  134. )
  135. NotificationCenter.default.addObserver(
  136. self,
  137. selector: #selector(IAPProductPurchasedNotification(_:)),
  138. name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"),
  139. object: nil
  140. )
  141. NotificationCenter.default.addObserver(
  142. self,
  143. selector: #selector(IAPProductFailedNotification(_:)),
  144. name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
  145. object: nil
  146. )
  147. NotificationCenter.default.addObserver(
  148. self,
  149. selector: #selector(IAPProductRestoreFinishedNotification(_:)),
  150. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"),
  151. object: nil
  152. )
  153. NotificationCenter.default.addObserver(
  154. self,
  155. selector: #selector(IAPProductRestoreFailedNotification(_:)),
  156. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFailedNotification"),
  157. object: nil
  158. )
  159. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  160. }
  161. // MARK: - Deinitialization
  162. deinit {
  163. NotificationCenter.default.removeObserver(self)
  164. }
  165. // MARK: - Singleton
  166. @objc class func sharedInstance() -> NSWindowController {
  167. struct Singleton {
  168. static let instance: KMProductCompareWC = KMProductCompareWC()
  169. }
  170. return Singleton.instance
  171. }
  172. override func windowDidLoad() {
  173. super.windowDidLoad()
  174. window?.backgroundColor = KMAppearance.Upgrade.vipBGColor()
  175. window?.isMovableByWindowBackground = true
  176. #if VERSION_DMG
  177. btnRestore.isHidden = true
  178. #endif
  179. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  180. bindViewModel()
  181. if orientation {
  182. model.state = orientationType
  183. } else {
  184. model.getCurrentComparisonTableType()
  185. }
  186. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  187. value1InfoLabel.font = NSFont.UbuntuMediumFontWithSize(16)
  188. value1PurchaseButton.wantsLayer = true
  189. value1PurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  190. value1PurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  191. value1PurchaseBtnLblBtn.wantsLayer = true
  192. value1PurchaseButton.mouseMoveCallback = { [weak self] mouseEntered in
  193. guard let self = self else { return }
  194. if self.value1PurchaseBtnLblBtn.isEnabled == true {
  195. self.value1PurchaseBtnLblBtn.layer?.backgroundColor = mouseEntered ? NSColor.black.withAlphaComponent(0.15).cgColor : NSColor.clear.cgColor
  196. }
  197. }
  198. value1PurchaseBtnLblBtn.layer?.cornerRadius = value1PurchaseBtnLblBtn.frame.height / 2
  199. value1PurchaseBtnLblBtn.layer?.masksToBounds = true
  200. standardPlanPurchaseButton.wantsLayer = true
  201. standardPlanPurchaseButton.layer?.cornerRadius = standardPlanPurchaseButton.frame.height / 2
  202. self.standardPlanPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  203. switchLabel.stringValue = NSLocalizedString("Choose your favorite payment and enjoy flexible upgrades.", comment: "")
  204. switchLabel.textColor = KMAppearance.Interactive.m0Color()
  205. box.wantsLayer = true
  206. box.shadow = NSShadow()
  207. box.layer?.shadowOpacity = 0.3
  208. box.layer?.shadowColor = NSColor.black.withAlphaComponent(0.3).cgColor
  209. box.layer?.shadowOffset = NSMakeSize(0, 3)
  210. box.layer?.shadowRadius = 8
  211. box.layer?.masksToBounds = false
  212. permanentPurchaseButton.wantsLayer = true
  213. permanentPurchaseButton.layer?.cornerRadius = permanentPurchaseButton.frame.height / 2
  214. self.permanentPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  215. let txtColor = NSColor(red: 102/255, green: 102/255, blue: 102/255, alpha: 1)
  216. aboutButton.title = NSLocalizedString("About Subscriptions", comment: "")
  217. aboutButton.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  218. aboutButton.isHidden = true
  219. reloadData()
  220. reloadDataContent()
  221. #if !VERSION_DMG
  222. IAPProductsManager.default().loadProducts()
  223. #endif
  224. 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: ""))
  225. showDiscount()
  226. }
  227. func windowShouldClose(sender:Any) -> Bool {
  228. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn":"PUW_Btn_Upgrade_Cancel"])
  229. if model.isShowSale {
  230. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn":"PUW_7OffUpgrade_Cancel"], platform: .AppCenter)
  231. }
  232. endModal(sender)
  233. return true
  234. }
  235. override func close() {
  236. super.close()
  237. endModal("")
  238. }
  239. @objc func startModal(_ sender: Any) {
  240. NSApp.stopModal()
  241. modalSession = NSApp.beginModalSession(for: window!)
  242. while NSApp.runModalSession(modalSession!) == .continue {
  243. // Modal loop
  244. }
  245. }
  246. @objc func endModal(_ sender: Any) {
  247. if let session = modalSession {
  248. NSApp.stopModal()
  249. NSApp.endModalSession(session)
  250. window?.orderOut(self)
  251. modalSession = nil
  252. }
  253. }
  254. @objc func showWindowRestore(_ sender: Any) {
  255. showWindow(sender)
  256. buttonItemClicked_Restore(sender)
  257. }
  258. @objc override func showWindow(_ sender: Any?) {
  259. super.showWindow(sender)
  260. #if VERSION_DMG
  261. model.getDMGProductDatas { success, result in
  262. }
  263. #endif
  264. if orientation {
  265. model.state = orientationType
  266. } else {
  267. model.getCurrentComparisonTableType()
  268. }
  269. languageLocalized()
  270. initializeUI()
  271. reloadData()
  272. if model.isShowSale {
  273. showDiscountToSaveWindow()
  274. }
  275. reloadDataContent()
  276. showDiscount()
  277. }
  278. // MARK: - Private Methods
  279. private func languageLocalized() -> Void {
  280. titleLabel.stringValue = NSLocalizedString("Subscribe to All Access Pack to enjoy more expanded features.", comment: "")
  281. btnRestore.title = NSLocalizedString("Restore", comment: "")
  282. btnRestore.toolTip = NSLocalizedString("Restore", comment: "")
  283. privacyPolicyBtn.title = NSLocalizedString("Privacy Policy", comment: "")
  284. privacyPolicyBtn.toolTip = NSLocalizedString("Privacy Policy", comment: "")
  285. termOfSerBtn.title = NSLocalizedString("Terms of Service", comment: "")
  286. termOfSerBtn.toolTip = NSLocalizedString("Terms of Service", comment: "")
  287. sixMouthProLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  288. oneYearProLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  289. freeInfoLabel.stringValue = NSLocalizedString("Free", comment: "")
  290. standardPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  291. standardPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  292. standardPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  293. advancedPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Advanced - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  294. advancedPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  295. advancedPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  296. permanentInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Permanent", tableName: "MemberCenterLocalizable", comment: "")
  297. permanentPurchaseSubLabel.stringValue = NSLocalizedString("one-time purchase", comment: "")
  298. permanentPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  299. standardPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  300. if KMMemberInfo.shared.userScenarioType == .lite_type3 ||
  301. KMMemberInfo.shared.userScenarioType == .lite_type11 {
  302. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Renew now",tableName: "MemberCenterLocalizable", comment: "“")
  303. } else {
  304. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  305. }
  306. permanentPurchaseLbl.stringValue = NSLocalizedString("Purchase", comment: "")
  307. #if VERSION_FREE
  308. #if VERSION_DMG
  309. // DMG
  310. if KMMemberInfo.shared.canTrail && model.state == .trial {
  311. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  312. }
  313. if model.state == .dmg_Base {
  314. standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
  315. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  316. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
  317. } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
  318. guard let productModels = model.dmgProductDatas?.listingProducts else { return }
  319. for productModel in productModels {
  320. if productModel.code == "advanced-annual-subscription" {
  321. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  322. guard let self = self else { return }
  323. guard let results: KMMemberProductResult = result else { return }
  324. guard let productModels2 = results.listingProducts else { return }
  325. for productModel2 in productModels2 {
  326. if productModel2.code == "advanced-annual-subscription" {
  327. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  328. }
  329. }
  330. }
  331. } else if productModel.code == "advanced-permanent-blackFive" {
  332. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  333. guard let self = self else { return }
  334. guard let results: KMMemberProductResult = result else { return }
  335. guard let productModels2 = results.listingProducts else { return }
  336. for productModel2 in productModels2 {
  337. if productModel2.code == "advanced-annual-subscription-blackFive" {
  338. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  339. }
  340. }
  341. }
  342. }
  343. }
  344. } else {
  345. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  346. }
  347. #else
  348. var isTrialPeriod = false
  349. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == true {
  350. isTrialPeriod = true
  351. }
  352. if(!isTrialPeriod &&
  353. KMMemberInfo.shared.canTrail) {
  354. if(model.state == .trial) {
  355. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  356. }
  357. }
  358. // AppStore 免费版本
  359. if model.state == .lite_Base {
  360. permanentPurchaseLabel.stringValue = model.getProductPrice(.allAccessPackPermanent_lite)
  361. } else if model.state == .lite_MacWindows {
  362. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  363. let platforms = KMMemberInfo.shared.vip_platforms
  364. let platformsArray = platforms
  365. .components(separatedBy: ",")
  366. .map { $0.trimmingCharacters(in: .whitespaces) }
  367. if platformsArray.count == 1 {
  368. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  369. } else if platformsArray.count == 2 {
  370. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  371. } else {
  372. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  373. }
  374. } else {
  375. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  376. }
  377. } else {
  378. // model.state == .trial
  379. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPackNew12months_lite)
  380. }
  381. #endif
  382. #else
  383. // AppStore 付费版
  384. if model.state == .pro_Base {
  385. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  386. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.standardAddDevicesAllAccessPack12months_pro)
  387. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfToOfficePackPermanent_pro)
  388. }
  389. } else if model.state == .pro_Advanced {
  390. let platforms = KMMemberInfo.shared.vip_platforms
  391. let platformsArray = platforms
  392. .components(separatedBy: ",")
  393. .map { $0.trimmingCharacters(in: .whitespaces) }
  394. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  395. if platformsArray.count == 1 {
  396. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  397. } else if platformsArray.count == 2 {
  398. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  399. } else {
  400. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  401. }
  402. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  403. if platformsArray.count == 1 {
  404. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  405. } else if platformsArray.count == 2 {
  406. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  407. } else {
  408. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  409. }
  410. }
  411. } else {
  412. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPack12months_pro)
  413. }
  414. #endif
  415. }
  416. private func initializeUI() -> Void {
  417. btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  418. btnRestore.font = NSFont.SFProTextRegularFont(13)
  419. btnRestore.mouseMoveCallback = { [weak self] mouseEntered in
  420. guard let self = self else { return }
  421. if mouseEntered {
  422. self.btnRestore.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  423. } else {
  424. self.btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  425. }
  426. }
  427. privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  428. privacyPolicyBtn.font = NSFont.SFProTextRegularFont(13)
  429. privacyPolicyBtn.mouseMoveCallback = { [weak self] mouseEntered in
  430. guard let self = self else { return }
  431. if mouseEntered {
  432. self.privacyPolicyBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  433. } else {
  434. self.privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  435. }
  436. }
  437. termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  438. termOfSerBtn.font = NSFont.SFProTextRegularFont(13)
  439. termOfSerBtn.mouseMoveCallback = { [weak self] mouseEntered in
  440. guard let self = self else { return }
  441. if mouseEntered {
  442. self.termOfSerBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  443. } else {
  444. self.termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  445. }
  446. }
  447. value1InfoTypeBox.fillColor = NSColor.clear
  448. value1InfoTypeBox.borderWidth = 0
  449. sixMouthProLabel.textColor = .white
  450. sixMouthProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  451. sixMouthProLabel.lineBreakMode = .byTruncatingTail
  452. sixMouthProLabel.toolTip = sixMouthProLabel.stringValue
  453. sixMouthProLabel.alignment = .center
  454. oneYearProLabel.textColor = .white
  455. oneYearProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  456. oneYearProLabel.lineBreakMode = .byTruncatingTail
  457. oneYearProLabel.toolTip = oneYearProLabel.stringValue
  458. oneYearProLabel.alignment = .center
  459. switchBox.fillColor = NSColor(white: 1, alpha: 0.2)
  460. switchBox.cornerRadius = 12
  461. switchBox.borderWidth = 1
  462. switchBox.borderColor = NSColor(red: 235/255, green: 236/255, blue: 240/255, alpha: 1.0)
  463. switchCircleView.wantsLayer = true
  464. switchCircleView.layer?.cornerRadius = 8
  465. switchCircleView.layer?.backgroundColor = NSColor.white.cgColor
  466. switchBtn.title = ""
  467. switchBtn.target = self
  468. switchBtn.action = #selector(switchAction)
  469. saleLabel.isHidden = true
  470. saleLabel.superview?.isHidden = true
  471. saleBox.borderWidth = 0
  472. topMainBox.contentView = topMainView
  473. topsubBox1.isHidden = false
  474. topsubBox2.isHidden = false
  475. topsubBox3.isHidden = false
  476. topsubBox4.isHidden = false
  477. topSelectBox1.isHidden = true
  478. topSelectBox2.isHidden = true
  479. topSelectBox3.isHidden = true
  480. topSelectBox4.isHidden = true
  481. freeInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  482. standardPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  483. advancedPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  484. permanentInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  485. standardPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  486. standardPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  487. advancedPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  488. advancedPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  489. permanentPurchaseSubLabel.font = NSFont.UbuntuMediumFontWithSize(11)
  490. permanentPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  491. value1PurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  492. standardPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  493. standardPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  494. advancedPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  495. advancedPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  496. permanentPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  497. permanentPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  498. backgroundImage1.wantsLayer = true
  499. backgroundImage1.layer?.cornerRadius = 12
  500. backgroundImage1.layer?.masksToBounds = true
  501. backgroundImage3.wantsLayer = true
  502. backgroundImage3.layer?.cornerRadius = 12
  503. backgroundImage3.layer?.masksToBounds = true
  504. advancedPlanPurchaseButton.wantsLayer = true
  505. advancedPlanPurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  506. advancedPlanPurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  507. standardPlanPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  508. advancedPlanPurchaseLbl.textColor = NSColor(named: "FFFFFF") ?? .white
  509. permanentPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  510. var contentWidth = 970.0
  511. var contentHeight = 660.0
  512. if model.state == .dmg_Base {
  513. contentWidth = 970.0
  514. contentHeight = 660.0
  515. topsubBox1.contentView = freeInfoView
  516. topsubBox2.contentView = standardPlanInfoView
  517. topsubBox3.contentView = advancedPlanInfoView
  518. topsubBox4.contentView = permanentInfoView
  519. backgroundImage1.isHidden = true
  520. topSelectBox3.isHidden = false
  521. topsubBoxWidth1.constant = 149.5
  522. topsubBoxWidth2.constant = 149.5
  523. topsubBoxWidth3.constant = 149.5
  524. topsubBoxWidth3.constant = 149.5
  525. } else if model.state == .dmg_Upgrades1 {
  526. contentWidth = 689.0
  527. contentHeight = 660.0
  528. topsubBox2.isHidden = true
  529. topsubBox3.isHidden = true
  530. topsubBox4.isHidden = true
  531. topsubBox1.contentView = advancedPlanInfoView
  532. topSelectBox1.isHidden = false
  533. topsubBoxWidth1.constant = 320.0
  534. } else if model.state == .dmg_Upgrades2 {
  535. contentWidth = 689.0
  536. contentHeight = 660.0
  537. topsubBox2.isHidden = true
  538. topsubBox3.isHidden = true
  539. topsubBox4.isHidden = true
  540. topsubBox1.contentView = advancedPlanInfoView
  541. topSelectBox1.isHidden = false
  542. topsubBoxWidth1.constant = 320.0
  543. } else if model.state == .lite_Base {
  544. contentWidth = 970.0
  545. contentHeight = 660.0
  546. topsubBox4.isHidden = true
  547. topsubBox1.contentView = freeInfoView
  548. topsubBox2.contentView = value1InfoView
  549. topsubBox3.contentView = permanentInfoView
  550. topSelectBox2.isHidden = false
  551. topsubBoxWidth1.constant = 179.0
  552. topsubBoxWidth2.constant = 240.0
  553. topsubBoxWidth3.constant = 179.0
  554. } else if model.state == .lite_MacWindows {
  555. contentWidth = 689.0
  556. contentHeight = 660.0
  557. topsubBox2.isHidden = true
  558. topsubBox3.isHidden = true
  559. topsubBox4.isHidden = true
  560. topsubBox1.contentView = advancedPlanInfoView
  561. topSelectBox1.isHidden = false
  562. topsubBoxWidth1.constant = 320.0
  563. } else if model.state == .pro_Base {
  564. contentWidth = 970.0
  565. contentHeight = 660.0
  566. topsubBox3.isHidden = true
  567. topsubBox4.isHidden = true
  568. topsubBox1.contentView = advancedPlanInfoView
  569. topsubBox2.contentView = permanentInfoView
  570. backgroundImage1.isHidden = true
  571. topSelectBox1.isHidden = false
  572. topsubBoxWidth1.constant = 299.0
  573. topsubBoxWidth2.constant = 299.0
  574. } else if model.state == .pro_Advanced {
  575. contentWidth = 689.0
  576. contentHeight = 660.0
  577. topsubBox2.isHidden = true
  578. topsubBox3.isHidden = true
  579. topsubBox4.isHidden = true
  580. topsubBox1.contentView = advancedPlanInfoView
  581. topSelectBox1.isHidden = false
  582. topsubBoxWidth1.constant = 320.0
  583. } else {
  584. // model.state == .trial
  585. contentWidth = 785.0
  586. contentHeight = 660.0
  587. topsubBox3.isHidden = true
  588. topsubBox4.isHidden = true
  589. topsubBox1.contentView = freeInfoView
  590. topsubBox2.contentView = advancedPlanInfoView
  591. backgroundImage1.isHidden = true
  592. topSelectBox2.isHidden = false
  593. topsubBoxWidth1.constant = 179.0
  594. topsubBoxWidth2.constant = 240.0
  595. }
  596. self.window?.setContentSize(NSSize(width: contentWidth, height: contentHeight))
  597. self.window?.maxSize = NSSize(width: contentWidth, height: contentHeight)
  598. self.window?.minSize = NSSize(width: contentWidth, height: contentHeight)
  599. box.fillColor = KMAppearance.Layout.l1Color()
  600. labelbox.fillColor = .clear
  601. tableView.backgroundColor = KMAppearance.Layout.l0Color()
  602. textView.backgroundColor = .clear
  603. textView.textColor = NSColor.white.withAlphaComponent(0.5)
  604. value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  605. standardPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  606. standardPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  607. advancedPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  608. advancedPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  609. permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  610. permanentPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  611. #if VERSION_FREE
  612. #if VERSION_DMG
  613. // DMG
  614. #else
  615. // AppStore 免费版本
  616. refreshPurchaseSwitch()
  617. #endif
  618. #else
  619. // AppStore 付费版
  620. #endif
  621. }
  622. @objc func reloadData() {
  623. saleBox.isHidden = true
  624. saleIv.isHidden = true
  625. if model.isShowSale {
  626. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  627. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.saleImage, highlight: true)) {
  628. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  629. guard let self = self else { return }
  630. self.saleIv.image = image
  631. self.saleBox.isHidden = false
  632. self.saleIv.isHidden = false
  633. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_7OffUpgrade"], platform: .AppCenter)
  634. }
  635. }
  636. } else {
  637. saleBox.isHidden = true
  638. }
  639. // if KMMemberInfo.shared.isMemberAllFunction == true {
  640. // value1PurchaseButton.isEnabled = false
  641. // permanentPurchaseButton.isEnabled = false
  642. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 0.5)
  643. // } else {
  644. // value1PurchaseButton.isEnabled = true
  645. // permanentPurchaseButton.isEnabled = true
  646. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 1.0)
  647. // }
  648. permanentPurchaseLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  649. value1PurchaseOriPriceLbl.font = NSFont.SFProTextRegularFont(12)
  650. }
  651. func refreshPurchaseSwitch() -> Void {
  652. #if VERSION_FREE
  653. #if VERSION_DMG
  654. // DMG
  655. #else
  656. // AppStore 免费版本
  657. reloadData()
  658. if model.isPurchaseSwitch {
  659. discountYearly.isHidden = false
  660. sixMouthProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  661. oneYearProLabel.textColor = NSColor.white
  662. switchCircleLeftConst.constant = 22
  663. value1InfoLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  664. } else {
  665. discountYearly.isHidden = true
  666. sixMouthProLabel.textColor = NSColor.white
  667. oneYearProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  668. switchCircleLeftConst.constant = 4
  669. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  670. }
  671. value1PurchaseBtnLblBtn.isEnabled = value1PurchaseButton.isEnabled
  672. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  673. let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  674. let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  675. let isTrialPeriod_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isTrialPeriod ?? false
  676. let isSubscribed_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isSubscribed ?? false
  677. let isTrialPeriod_year = fourDevicesAllAccessPackNew12months_lite?.isTrialPeriod ?? false
  678. let isSubscribed_year = fourDevicesAllAccessPackNew12months_lite?.isSubscribed ?? false
  679. let introductoryPrice_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.product?.introductoryPrice
  680. let introductoryPrice_year = fourDevicesAllAccessPackNew12months_lite?.product?.introductoryPrice
  681. if(isSubscribed_newlyMonth || isSubscribed_year) {
  682. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  683. } else {
  684. if(model.isPurchaseSwitch == true) {
  685. if(!isTrialPeriod_year &&
  686. KMMemberInfo.shared.canTrail) {
  687. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  688. } else {
  689. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  690. }
  691. } else {
  692. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  693. }
  694. }
  695. value1PurchaseBtnLbl.textColor = value1PurchaseBtnLblBtn.isEnabled ? NSColor.white : NSColor.white.withAlphaComponent(0.5)
  696. permanentPurchaseLblBtn.isEnabled = permanentPurchaseButton.isEnabled
  697. standardPlanPurchaseLblBtn.isEnabled = standardPlanPurchaseButton.isEnabled
  698. advancedPlanPurchaseLblBtn.isEnabled = advancedPlanPurchaseButton.isEnabled
  699. let averageMonthPrice: String?
  700. let monthPrice: String?
  701. let averageMonthPriceDiscount: String?
  702. let monthPriceDiscount: String?
  703. var allPrice: String?
  704. let isOffers_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isOffers ?? false
  705. let isOffers_year = fourDevicesAllAccessPackNew12months_lite?.isOffers ?? false
  706. if isOffers_newlyMonth {
  707. specialView1.isHidden = false
  708. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersAveragePrice()
  709. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersPrice()
  710. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  711. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  712. } else if isOffers_year {
  713. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.offersAveragePrice()
  714. monthPrice = fourDevicesAllAccessPackNew12months_lite?.offersPrice()
  715. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  716. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  717. } else {
  718. specialView1.isHidden = true
  719. if !model.isPurchaseSwitch {
  720. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.averagePrice()
  721. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.price()
  722. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  723. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  724. } else {
  725. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.averagePrice()
  726. monthPrice = fourDevicesAllAccessPackNew12months_lite?.price()
  727. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  728. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  729. }
  730. }
  731. if let allAccessPackPermanent_lite = IAPProductsManager.default().allAccessPackPermanent_lite, allAccessPackPermanent_lite.isOffers {
  732. specialView.isHidden = false
  733. allPrice = allAccessPackPermanent_lite.offersPrice()
  734. } else {
  735. specialView.isHidden = true
  736. allPrice = IAPProductsManager.default().allAccessPackPermanent_lite?.price()
  737. }
  738. var off = 1 - (IAPProductsManager.default().allAccessPackPermanent_lite?.offers ?? 0)
  739. var offString = String(format: "%.f%%", off * 100)
  740. specialLabel.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  741. if model.isPurchaseSwitch {
  742. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.offers
  743. } else {
  744. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.offers
  745. }
  746. offString = String(format: "%.f%%", off * 100)
  747. specialLabel1.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  748. let image = NSImage(named: "KMImageNameCompareTagBG")
  749. specialImageView.image = image
  750. specialImageView1.image = image
  751. if KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice() {
  752. if model.isShowSale {
  753. value1PurchaseSubLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
  754. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  755. value1PurchaseOriPriceLbl.isHidden = false
  756. billedTopConst.constant = 16
  757. } else {
  758. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  759. value1PurchaseOriPriceLbl.isHidden = true
  760. billedTopConst.constant = 0
  761. }
  762. } else {
  763. if model.isPurchaseSwitch {
  764. if model.isShowSale {
  765. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("12 months", comment: ""))
  766. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  767. value1PurchaseOriPriceLbl.isHidden = false
  768. billedTopConst.constant = 16
  769. } else {
  770. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  771. value1PurchaseOriPriceLbl.isHidden = true
  772. billedTopConst.constant = 0
  773. }
  774. } else {
  775. if model.isShowSale {
  776. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("6mon", comment: ""))
  777. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  778. value1PurchaseOriPriceLbl.isHidden = false
  779. billedTopConst.constant = 16
  780. } else {
  781. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  782. value1PurchaseOriPriceLbl.isHidden = true
  783. billedTopConst.constant = 0
  784. }
  785. }
  786. }
  787. value1PurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  788. value1PurchaseOriPriceLbl.textColor = NSColor(white: 1.0, alpha: 0.7)
  789. value1PurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: value1PurchaseOriPriceLbl.stringValue, attributes: [
  790. .font : NSFont.SFProTextRegularFont(12),
  791. .foregroundColor: NSColor(white: 1, alpha: 0.7),
  792. .strikethroughStyle: NSUnderlineStyle.single.rawValue
  793. ])
  794. var tTips: String
  795. if model.isShowSale {
  796. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  797. } else {
  798. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  799. }
  800. if value1PurchaseBtnLbl.stringValue == NSLocalizedString("Free Trial", comment: "") {
  801. tTips = String(format: NSLocalizedString("Billed every 6 months at %@ after 7-day trial ends.", comment: ""), monthPrice ?? "")
  802. #if !VERSION_DMG
  803. if model.isPurchaseSwitch {
  804. if let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product {
  805. if #available(macOS 10.13.2, *) {
  806. let trialDays = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product.introductoryPrice?.subscriptionPeriod.numberOfUnits
  807. tTips = String(
  808. format: NSLocalizedString("Billed every 12 months at %@ after %@-day trial ends.", comment: ""),
  809. monthPrice ?? "",
  810. "\(trialDays ?? 0)"
  811. )
  812. }
  813. }
  814. } else {
  815. if let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product {
  816. if #available(macOS 10.13.2, *) {
  817. let trialDays = fourDevicesAllAccessPackNew6Months_lite.introductoryPrice?.subscriptionPeriod.numberOfUnits
  818. tTips = String(
  819. format: NSLocalizedString("Billed every 6 months at %@ after %@-day trial ends.", comment: ""),
  820. monthPrice ?? "",
  821. "\(trialDays ?? 0)"
  822. )
  823. }
  824. }
  825. }
  826. #endif
  827. }
  828. if #available(macOS 10.13.2, *) {
  829. #if !VERSION_DMG
  830. if model.isPurchaseSwitch {
  831. if (IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product?.introductoryPrice == nil) {
  832. if model.isShowSale {
  833. tTips = String(format: NSLocalizedString("%@ for the first year's subscription", comment: ""), monthPriceDiscount ?? "")
  834. } else {
  835. tTips = String(format: NSLocalizedString("Billed every 12 months at %@", comment: ""), monthPrice ?? "")
  836. }
  837. }
  838. } else {
  839. if (IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product.introductoryPrice == nil) {
  840. if model.isShowSale {
  841. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  842. } else {
  843. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  844. }
  845. }
  846. }
  847. #endif
  848. }
  849. value1PurchaseSubLabel.stringValue = String(format: NSLocalizedString("%@", comment: ""), tTips)
  850. value1PurchaseBtnLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  851. #endif
  852. #else
  853. // AppStore 付费版
  854. #endif
  855. }
  856. @objc func reloadDataContent() {
  857. tableView.reloadData()
  858. }
  859. func addWaitingView(to view: NSView) {
  860. removeWaitingView(from: view)
  861. let waitingView = WaitingView(frame: view.bounds)
  862. waitingView.autoresizingMask = [.width, .height]
  863. view.addSubview(waitingView)
  864. waitingView.startAnimation()
  865. }
  866. func removeWaitingView(from view: NSView) {
  867. for subview in view.subviews {
  868. if subview is WaitingView {
  869. subview.removeFromSuperview()
  870. break
  871. }
  872. }
  873. }
  874. func showDiscount() {
  875. discountYearly.isHidden = true
  876. discountPermanent.isHidden = true
  877. discountPermanent2.isHidden = true
  878. discountPermanent.isHidden = true
  879. #if VERSION_FREE
  880. #if VERSION_DMG
  881. // DMG
  882. if model.state != .dmg_Base { return }
  883. #else
  884. // AppStore 免费版本
  885. if model.state != .lite_Base { return }
  886. #endif
  887. #else
  888. // AppStore 付费版
  889. if model.state != .pro_Base { return }
  890. #endif
  891. let content = KMAdvertisementManager.manager.info.StoreUserRecovery?.content ?? []
  892. if content.count > 0 {
  893. for (index, item) in content.enumerated() {
  894. switch index {
  895. case 1:
  896. configureDiscountView(discountYearly, with: item)
  897. case 2:
  898. configureDiscountView(discountPermanent4, with: item)
  899. case 3:
  900. configureDiscountView(discountPermanent2, with: item)
  901. case 4:
  902. configureDiscountView(discountPermanent, with: item)
  903. default:
  904. break
  905. }
  906. }
  907. }
  908. }
  909. private func configureDiscountView(_ view: NSImageView, with itemInfo: KMAdvertisementItemInfo) {
  910. if KMAdvertisementManager.checkAdvertisementValid(itemInfo) {
  911. view.isHidden = false
  912. let urlString = KMAdvertisementModelTransition.transitionImagePath(image: itemInfo.image, highlight: false)
  913. if let url = URL(string: urlString) {
  914. view.image = KMAdvertisementImage.imageWithURL(url: url) { image in
  915. view.image = image
  916. }
  917. }
  918. } else {
  919. view.isHidden = true
  920. }
  921. }
  922. private func showAlert(message: String) {
  923. let alert = NSAlert()
  924. alert.alertStyle = .critical
  925. alert.messageText = message
  926. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  927. alert.runModal()
  928. }
  929. private func handleVerificationFailure(msg: KMMemberProductResult?) {
  930. var message = msg?.msg ?? ""
  931. if msg?.code == 344 {
  932. message = NSLocalizedString("The current ticket has created an order.", tableName: "MemberCenterLocalizable", comment: "")
  933. }
  934. if !message.isEmpty {
  935. showAlert(message: message)
  936. }
  937. }
  938. // MARK: Button Actions
  939. @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
  940. if KMMemberInfo.shared.validFlag == "5" {
  941. KMMemberPromptWC.shared.showWindow(nil)
  942. KMMemberPromptWC.shared.tipType = .signouting
  943. } else {
  944. if model.isPurchaseSwitch {
  945. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: model.isCancelAutoRenew)
  946. } else {
  947. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: model.isCancelAutoRenew)
  948. }
  949. addWaitingView(to: window?.contentView ?? NSView())
  950. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_6Mon"])
  951. if model.isShowSale {
  952. kEventTag = 1
  953. if model.isPurchaseSwitch {
  954. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12Mon"], platform: .AppCenter)
  955. } else {
  956. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6Mon"], platform: .AppCenter)
  957. }
  958. }
  959. }
  960. }
  961. func showDiscountToSaveWindow() {
  962. guard KMDiscountToSaveWindowController.needShow() else { return }
  963. guard let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  964. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.image, highlight: true)) else { return }
  965. addWaitingView(to: window?.contentView ?? NSView())
  966. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  967. guard let self = self else { return }
  968. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  969. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_PromotionalOffer"], platform: .AppCenter)
  970. let winC = KMDiscountToSaveWindowController(windowNibName: "KMDiscountToSaveWindowController")
  971. self.discountToSaveWinC = winC
  972. self.window?.beginSheet(winC.window!) { _ in }
  973. winC.imgIv.image = image
  974. winC.itemClick = { idx in
  975. self.window?.endSheet(self.discountToSaveWinC?.window ?? NSWindow())
  976. self.discountToSaveWinC = nil
  977. if idx == 2 {
  978. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Subscribe"], platform: .AppCenter)
  979. } else if idx == 1 {
  980. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Cancel"], platform: .AppCenter)
  981. }
  982. }
  983. }
  984. }
  985. @IBAction func buttonItemClicked_Restore(_ sender: Any) {
  986. model.productRestore()
  987. addWaitingView(to: window?.contentView ?? NSView())
  988. }
  989. @IBAction func buttonItemClicked_Upgrade(_ sender: Any) {
  990. NSWorkspace.shared.open(URL(string: "macappstore://apps.apple.com/app/id825459243?mt=12")!)
  991. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Premium"])
  992. }
  993. @IBAction func privacyPolicyAction(_ sender: NSButton) {
  994. model.privacyPolicyAction()
  995. }
  996. @IBAction func termOfSerAction(_ sender: NSButton) {
  997. model.termOfSerAction()
  998. }
  999. @IBAction func buttonItemClicked_LicenseUpgrade(_ sender: Any) {
  1000. IAPProductsManager.default().make(IAPProductsManager.default().allAccessPackPermanent_lite)
  1001. addWaitingView(to: window?.contentView ?? NSView())
  1002. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Permanent"])
  1003. }
  1004. @IBAction func buttonItemClicked_AboutSubscriptions(_ sender: Any) {
  1005. let tMessage = """
  1006. Subscription plans:
  1007. Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)
  1008. - Subscriptions will be charged through your iTunes account at the confirmation of purchase.
  1009. - Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.
  1010. - 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.
  1011. - You may manage your subscriptions in your iTunes Account Settings after purchase.
  1012. - No cancellation of the current subscription is allowed during an active subscription period.
  1013. - Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service
  1014. - Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy
  1015. """
  1016. let alert = NSAlert()
  1017. alert.alertStyle = .informational
  1018. alert.messageText = NSLocalizedString(tMessage, comment: "")
  1019. alert.runModal()
  1020. }
  1021. @IBAction func buttonItemClicked_CloseWindow(_ sender: Any) {
  1022. close()
  1023. }
  1024. @objc func switchAction(_ sender: NSButton) {
  1025. model.isPurchaseSwitch.toggle()
  1026. }
  1027. @IBAction func appstorePurchaseAction(_ sender: NSButton) {
  1028. if KMMemberInfo.shared.validFlag == "5" {
  1029. KMMemberPromptWC.shared.showWindow(nil)
  1030. KMMemberPromptWC.shared.tipType = .signouting
  1031. } else {
  1032. #if !VERSION_DMG
  1033. addWaitingView(to: window?.contentView ?? NSView())
  1034. #endif
  1035. model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
  1036. guard let self = self else { return }
  1037. }
  1038. #if VERSION_DMG
  1039. close()
  1040. #endif
  1041. }
  1042. }
  1043. // MARK: - InAppPurchaseManager Notification
  1044. @objc func IAPProductFailedNotification(_ notification: Notification) {
  1045. removeWaitingView(from: window?.contentView ?? NSView())
  1046. }
  1047. @objc func IAPProductPurchasedNotification(_ notification: Notification) {
  1048. removeWaitingView(from: window?.contentView ?? NSView())
  1049. reloadData()
  1050. #if VERSION_FREE
  1051. #if VERSION_DMG
  1052. // DMG
  1053. #else
  1054. // AppStore 免费版本
  1055. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  1056. if kEventTag == 1 {
  1057. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6MonthPaid"], platform: .AppCenter)
  1058. }
  1059. } else if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  1060. if kEventTag == 1 {
  1061. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12MonthPaid"], platform: .AppCenter)
  1062. }
  1063. }
  1064. #endif
  1065. #else
  1066. // AppStore 付费版
  1067. #endif
  1068. }
  1069. @objc func IAPProductLoadedNotification(_ notification: Notification) {
  1070. reloadData()
  1071. }
  1072. @objc func IAPProductRestoreFinishedNotification(_ notification: Notification) {
  1073. removeWaitingView(from: window?.contentView ?? NSView())
  1074. reloadData()
  1075. }
  1076. @objc func IAPProductRestoreFailedNotification(_ notification: Notification) {
  1077. removeWaitingView(from: window?.contentView ?? NSView())
  1078. }
  1079. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  1080. removeWaitingView(from: window?.contentView ?? NSView())
  1081. reloadData()
  1082. DispatchQueue.global().async { [weak self] in
  1083. guard let self = self else { return }
  1084. if KMMemberInfo.shared.isLogin {
  1085. self.model.appStoreEquityVerification(notification) { success, msg in
  1086. DispatchQueue.main.async {
  1087. if success {
  1088. // self.showAlert(message: NSLocalizedString("Binding Interest Success!", comment: ""))
  1089. KMUserInfoVCModel().refreshUserInfo { success, msg,dic in
  1090. }
  1091. self.window?.close()
  1092. } else {
  1093. self.handleVerificationFailure(msg: msg)
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. }
  1100. @objc func themeChanged(_ notification: Notification) {
  1101. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1102. self.box.fillColor = KMAppearance.Layout.l1Color()
  1103. self.labelbox.fillColor = .clear
  1104. self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
  1105. self.textView.backgroundColor = .clear
  1106. self.textView.textColor = NSColor.white.withAlphaComponent(0.5)
  1107. self.value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1108. self.permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1109. }
  1110. }
  1111. // MARK: Bind Method
  1112. func bindViewModel() -> Void {
  1113. model.$state
  1114. .receive(on: RunLoop.main)
  1115. .sink { [weak self] newValue in
  1116. }
  1117. .store(in: &cancellables)
  1118. model.$isPurchaseSwitch
  1119. .receive(on: RunLoop.main)
  1120. .sink { [weak self] newValue in
  1121. self?.reloadDataContent()
  1122. #if VERSION_FREE
  1123. #if VERSION_DMG
  1124. // DMG
  1125. #else
  1126. // AppStore 免费版本
  1127. self?.refreshPurchaseSwitch()
  1128. #endif
  1129. #else
  1130. // AppStore 付费版
  1131. #endif
  1132. }
  1133. .store(in: &cancellables)
  1134. }
  1135. }
  1136. extension KMProductCompareWC: NSTableViewDelegate, NSTableViewDataSource {
  1137. // MARK: NSTableViewDataSource Methods
  1138. func numberOfRows(in tableView: NSTableView) -> Int {
  1139. return model.dataSource.count
  1140. }
  1141. // tableView:viewForTableColumn:row
  1142. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1143. let object = model.dataSource[row]
  1144. if let stringObject = object as? String {
  1145. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1146. cellView.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1147. if model.state == .dmg_Base {
  1148. cellView.selectBoxLeft.constant = 352.0 + 149.5 + 149.5
  1149. cellView.selectBoxWidth.constant = 149.5
  1150. } else if model.state == .dmg_Upgrades1 {
  1151. cellView.selectBoxLeft.constant = 352.0
  1152. cellView.selectBoxWidth.constant = 320.0
  1153. } else if model.state == .dmg_Upgrades2 {
  1154. cellView.selectBoxLeft.constant = 352.0
  1155. cellView.selectBoxWidth.constant = 320.0
  1156. } else if model.state == .lite_Base {
  1157. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1158. cellView.selectBoxWidth.constant = 240.0
  1159. } else if model.state == .lite_MacWindows {
  1160. cellView.selectBoxLeft.constant = 352.0
  1161. cellView.selectBoxWidth.constant = 320.0
  1162. } else if model.state == .pro_Base {
  1163. cellView.selectBoxLeft.constant = 352.0
  1164. cellView.selectBoxWidth.constant = 299.0
  1165. } else if model.state == .pro_Advanced {
  1166. cellView.selectBoxLeft.constant = 352.0
  1167. cellView.selectBoxWidth.constant = 320.0
  1168. } else {
  1169. // model.state == .trial
  1170. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1171. cellView.selectBoxWidth.constant = 240.0
  1172. }
  1173. return cellView
  1174. }
  1175. } else if let arrayObject = object as? [String] {
  1176. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1177. let value1 = arrayObject.indices.contains(0) ? arrayObject[0] : ""
  1178. let value2 = arrayObject.indices.contains(1) ? arrayObject[1] : ""
  1179. let value3 = arrayObject.indices.contains(2) ? arrayObject[2] : ""
  1180. let value4 = arrayObject.indices.contains(3) ? arrayObject[3] : ""
  1181. let value5 = arrayObject.indices.contains(4) ? arrayObject[4] : ""
  1182. let value6 = arrayObject.indices.contains(5) ? arrayObject[5] : ""
  1183. cellView.textField?.stringValue = NSLocalizedString(value1, comment: "")
  1184. cellView.lineBox?.isHidden = false
  1185. if row + 1 == model.dataSource.count || model.dataSource[row + 1] is String {
  1186. cellView.lineBox?.isHidden = true
  1187. }
  1188. checkOrNot(cellView)
  1189. cellView.boxBottomConst?.constant = (row + 2 == model.dataSource.count) ? 0 : -4
  1190. updateCellView(cellView, value1: value2, value2: value3, value3: value4, value4: value5, value5: value6)
  1191. return cellView
  1192. }
  1193. } else if object is [String: Any] {
  1194. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableEmptyCell"), owner: self) as? KMProductCompareTableEmptyCell {
  1195. return cellView
  1196. }
  1197. }
  1198. return nil
  1199. }
  1200. // tableView:heightOfRow
  1201. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1202. let object = model.dataSource[row]
  1203. var cellView: NSTableCellView?
  1204. if let stringObject = object as? String {
  1205. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1206. cell.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1207. cellView = cell
  1208. }
  1209. } else if let arrayObject = object as? [String] {
  1210. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1211. cell.textField?.stringValue = NSLocalizedString(arrayObject[0], comment: "")
  1212. cellView = cell
  1213. }
  1214. } else if object is [String: Any] {
  1215. return 40
  1216. }
  1217. if let view = cellView {
  1218. view.layoutSubtreeIfNeeded()
  1219. return view.frame.size.height
  1220. } else {
  1221. return 44
  1222. }
  1223. }
  1224. // Helper function to update cell view for multiple values
  1225. private func updateCellView(_ cellView: KMProductCompareTableCell, value1: String, value2: String, value3: String, value4: String, value5: String) {
  1226. if model.state == .dmg_Base {
  1227. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1228. configureCellView(cellView, value: value2, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1229. configureCellView(cellView, value: value3, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1230. configureCellView(cellView, value: value4, label: cellView.value4Label, imageView: cellView.value4ImageView, platformsBox: cellView.platformsBox4)
  1231. } else if model.state == .dmg_Upgrades1 {
  1232. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1233. } else if model.state == .dmg_Upgrades2 {
  1234. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1235. } else if model.state == .lite_Base {
  1236. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1237. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1238. configureCellView(cellView, value: value4, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1239. } else if model.state == .lite_MacWindows {
  1240. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1241. } else if model.state == .pro_Base {
  1242. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1243. configureCellView(cellView, value: value5, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1244. } else if model.state == .pro_Advanced {
  1245. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1246. } else {
  1247. // model.state == .trial
  1248. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1249. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1250. }
  1251. }
  1252. // Helper function to configure each individual value
  1253. private func configureCellView(_ cellView: KMProductCompareTableCell, value: String, label: NSTextField?, imageView: NSImageView?, platformsBox: NSBox?) {
  1254. platformsBox?.isHidden = true
  1255. label?.isHidden = false
  1256. imageView?.isHidden = false
  1257. switch value {
  1258. case "X":
  1259. label?.stringValue = ""
  1260. imageView?.image = NSImage(named: "compare_nosupport")
  1261. case "✓":
  1262. label?.stringValue = ""
  1263. imageView?.image = NSImage(named: "compare_support")
  1264. case "∞":
  1265. label?.stringValue = ""
  1266. imageView?.image = NSImage(named: "compare_00")
  1267. default:
  1268. if value == "mac, windows, ios, android" ||
  1269. value == "mac, windows" ||
  1270. value == "mac" {
  1271. platformsBox?.isHidden = false
  1272. label?.isHidden = true
  1273. imageView?.isHidden = true
  1274. if value == "mac, windows, ios, android" {
  1275. // platformsBox?.contentView = platformsView4
  1276. } else if value == "mac, windows" {
  1277. platformsBox?.contentView = platformsView2
  1278. } else if value == "mac" {
  1279. platformsBox?.contentView = platformsView1
  1280. }
  1281. } else {
  1282. label?.stringValue = NSLocalizedString(value, comment: "")
  1283. imageView?.image = nil
  1284. }
  1285. }
  1286. }
  1287. private func checkOrNot(_ cellView: KMProductCompareTableCell) {
  1288. cellView.selectBox1.isHidden = true
  1289. cellView.selectBox2.isHidden = true
  1290. cellView.selectBox3.isHidden = true
  1291. cellView.selectBox4.isHidden = true
  1292. cellView.cellView1.isHidden = true
  1293. cellView.cellView2.isHidden = true
  1294. cellView.cellView3.isHidden = true
  1295. cellView.cellView4.isHidden = true
  1296. if model.state == .dmg_Base {
  1297. cellView.selectBox3.isHidden = false
  1298. cellView.cellView1.isHidden = false
  1299. cellView.cellView2.isHidden = false
  1300. cellView.cellView3.isHidden = false
  1301. cellView.cellView4.isHidden = false
  1302. cellView.viewWidth1.constant = 149.5
  1303. cellView.viewWidth2.constant = 149.5
  1304. cellView.viewWidth3.constant = 149.5
  1305. cellView.viewWidth4.constant = 149.5
  1306. } else if model.state == .dmg_Upgrades1 {
  1307. cellView.selectBox1.isHidden = false
  1308. cellView.cellView1.isHidden = false
  1309. cellView.viewWidth1.constant = 320.0
  1310. } else if model.state == .dmg_Upgrades2 {
  1311. cellView.selectBox1.isHidden = false
  1312. cellView.cellView1.isHidden = false
  1313. cellView.viewWidth1.constant = 320.0
  1314. } else if model.state == .lite_Base {
  1315. cellView.selectBox2.isHidden = false
  1316. cellView.cellView1.isHidden = false
  1317. cellView.cellView2.isHidden = false
  1318. cellView.cellView3.isHidden = false
  1319. cellView.viewWidth1.constant = 179.0
  1320. cellView.viewWidth2.constant = 240.0
  1321. cellView.viewWidth3.constant = 240.0
  1322. } else if model.state == .lite_MacWindows {
  1323. cellView.selectBox1.isHidden = false
  1324. cellView.viewWidth1.constant = 320.0
  1325. cellView.cellView1.isHidden = false
  1326. } else if model.state == .pro_Base {
  1327. cellView.selectBox1.isHidden = false
  1328. cellView.viewWidth1.constant = 299.0
  1329. cellView.cellView1.isHidden = false
  1330. } else if model.state == .pro_Advanced {
  1331. cellView.selectBox1.isHidden = false
  1332. cellView.viewWidth1.constant = 320.0
  1333. cellView.cellView1.isHidden = false
  1334. } else {
  1335. // model.state == .trial
  1336. cellView.cellView1.isHidden = false
  1337. cellView.cellView2.isHidden = false
  1338. cellView.selectBox2.isHidden = false
  1339. cellView.viewWidth1.constant = 179.0
  1340. cellView.viewWidth2.constant = 240.0
  1341. }
  1342. }
  1343. }
  1344. class KMProductCompareTableCell: NSTableCellView {
  1345. @IBOutlet weak var bgColorView: NSView!
  1346. @IBOutlet @objc weak var cellView1: NSView!
  1347. @IBOutlet @objc weak var cellView2: NSView!
  1348. @IBOutlet @objc weak var cellView3: NSView!
  1349. @IBOutlet @objc weak var cellView4: NSView!
  1350. @IBOutlet weak var value1Label: NSTextField!
  1351. @IBOutlet weak var value2Label: NSTextField!
  1352. @IBOutlet weak var value3Label: NSTextField!
  1353. @IBOutlet weak var value4Label: NSTextField!
  1354. @IBOutlet weak var value1ImageView: NSImageView!
  1355. @IBOutlet weak var value2ImageView: NSImageView!
  1356. @IBOutlet weak var value3ImageView: NSImageView!
  1357. @IBOutlet weak var value4ImageView: NSImageView!
  1358. @IBOutlet weak var lineBox: NSBox!
  1359. @IBOutlet weak var boxBottomConst: NSLayoutConstraint!
  1360. @IBOutlet @objc weak var platformsBox1: NSBox!
  1361. @IBOutlet @objc weak var platformsBox2: NSBox!
  1362. @IBOutlet @objc weak var platformsBox3: NSBox!
  1363. @IBOutlet @objc weak var platformsBox4: NSBox!
  1364. @IBOutlet @objc weak var selectBox1: NSBox!
  1365. @IBOutlet @objc weak var selectBox2: NSBox!
  1366. @IBOutlet @objc weak var selectBox3: NSBox!
  1367. @IBOutlet @objc weak var selectBox4: NSBox!
  1368. @IBOutlet weak var viewWidth1: NSLayoutConstraint!
  1369. @IBOutlet weak var viewWidth2: NSLayoutConstraint!
  1370. @IBOutlet weak var viewWidth3: NSLayoutConstraint!
  1371. @IBOutlet weak var viewWidth4: NSLayoutConstraint!
  1372. override func awakeFromNib() {
  1373. super.awakeFromNib()
  1374. bgColorView.wantsLayer = true
  1375. updateViewColor()
  1376. NotificationCenter.default.addObserver(
  1377. self,
  1378. selector: #selector(themeChanged(_:)),
  1379. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1380. object: nil
  1381. )
  1382. }
  1383. deinit {
  1384. NotificationCenter.default.removeObserver(self)
  1385. }
  1386. @objc func themeChanged(_ notification: Notification) {
  1387. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1388. self.updateViewColor()
  1389. }
  1390. }
  1391. private func updateViewColor() {
  1392. var textColor = NSColor(red: 68.0 / 255.0, green: 68.0 / 255.0, blue: 68.0 / 255.0, alpha: 1.0)
  1393. var subtextColor = NSColor(red: 141.0 / 255.0, green: 141.0 / 255.0, blue: 141.0 / 255.0, alpha: 1.0)
  1394. var lineColor = NSColor(red: 204.0 / 255.0, green: 204.0 / 255.0, blue: 204.0 / 255.0, alpha: 0.4)
  1395. if let layer = bgColorView.layer {
  1396. if KMAppearance.isDarkMode() {
  1397. layer.backgroundColor = NSColor(red: 24.0 / 255.0, green: 22.0 / 255.0, blue: 31.0 / 255.0, alpha: 1.0).cgColor
  1398. textColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.8)
  1399. subtextColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.6)
  1400. lineColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.15)
  1401. } else {
  1402. layer.backgroundColor = NSColor(red: 247.0 / 255.0, green: 245.0 / 255.0, blue: 1.0, alpha: 1.0).cgColor
  1403. }
  1404. }
  1405. value1Label.textColor = subtextColor
  1406. value2Label.textColor = subtextColor
  1407. value3Label.textColor = subtextColor
  1408. value4Label.textColor = subtextColor
  1409. lineBox.fillColor = lineColor
  1410. textField?.textColor = textColor
  1411. }
  1412. }
  1413. class KMProductCompareTableHeaderCell: NSTableCellView {
  1414. @IBOutlet weak var contentView: NSView?
  1415. @IBOutlet weak var selectBoxLeft: NSLayoutConstraint!
  1416. @IBOutlet weak var selectBoxWidth: NSLayoutConstraint!
  1417. deinit {
  1418. NotificationCenter.default.removeObserver(self)
  1419. }
  1420. override func awakeFromNib() {
  1421. super.awakeFromNib()
  1422. contentView?.wantsLayer = true
  1423. updateViewColor()
  1424. NotificationCenter.default.addObserver(
  1425. self,
  1426. selector: #selector(themeChanged(_:)),
  1427. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1428. object: nil
  1429. )
  1430. }
  1431. @objc private func themeChanged(_ notification: Notification) {
  1432. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1433. self.updateViewColor()
  1434. }
  1435. }
  1436. private func updateViewColor() {
  1437. if KMAppearance.isDarkMode() {
  1438. contentView?.layer?.backgroundColor = NSColor(red: 40/255, green: 38/255, blue: 47/255, alpha: 1).cgColor
  1439. } else {
  1440. contentView?.layer?.backgroundColor = NSColor(red: 237/255, green: 231/255, blue: 255/255, alpha: 1).cgColor
  1441. }
  1442. textField?.textColor = KMAppearance.Layout.h0Color()
  1443. textField?.font = NSFont.boldSystemFont(ofSize: 14.0)
  1444. }
  1445. }
  1446. class KMProductCompareTableEmptyCell: NSTableCellView {
  1447. override func awakeFromNib() {
  1448. super.awakeFromNib()
  1449. self.wantsLayer = true
  1450. updateViewColor()
  1451. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  1452. }
  1453. deinit {
  1454. DistributedNotificationCenter.default.removeObserver(self)
  1455. }
  1456. @objc private func themeChanged(_ notification: Notification) {
  1457. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1458. self.updateViewColor()
  1459. }
  1460. }
  1461. private func updateViewColor() {
  1462. if KMAppearance.isDarkMode() {
  1463. self.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1.0).cgColor
  1464. } else {
  1465. self.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1.0, alpha: 1.0).cgColor
  1466. }
  1467. }
  1468. }