KMProductCompareWC.swift 77 KB

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