KMProductCompareWC.swift 70 KB

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