KMProductCompareWC.swift 74 KB

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