KMProductCompareWC.swift 68 KB

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