KMProductCompareWC.swift 75 KB

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