KMProductCompareWC.swift 74 KB

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