KMProductCompareWC.swift 68 KB

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