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