KMProductCompareWC.swift 68 KB

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