KMProductCompareWC.swift 68 KB

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