KMProductCompareWC.swift 76 KB

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