KMProductCompareWC.swift 75 KB

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