KMProductCompareWC.swift 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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. #if VERSION_FREE
  548. #if VERSION_DMG
  549. // DMG
  550. #else
  551. // AppStore 免费版本
  552. reloadData()
  553. if model.isPurchaseSwitch {
  554. sixMouthProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  555. oneYearProLabel.textColor = NSColor.white
  556. switchCircleLeftConst.constant = 22
  557. value1InfoLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  558. } else {
  559. sixMouthProLabel.textColor = NSColor.white
  560. oneYearProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  561. switchCircleLeftConst.constant = 4
  562. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  563. }
  564. value1PurchaseBtnLblBtn.isEnabled = value1PurchaseButton.isEnabled
  565. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  566. let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  567. let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  568. let isTrialPeriod_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isTrialPeriod ?? false
  569. let isSubscribed_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isSubscribed ?? false
  570. let isTrialPeriod_year = fourDevicesAllAccessPackNew12months_lite?.isTrialPeriod ?? false
  571. let isSubscribed_year = fourDevicesAllAccessPackNew12months_lite?.isSubscribed ?? false
  572. let introductoryPrice_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.product?.introductoryPrice
  573. let introductoryPrice_year = fourDevicesAllAccessPackNew12months_lite?.product?.introductoryPrice
  574. if isTrialPeriod_newlyMonth {
  575. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  576. if isSubscribed_newlyMonth {
  577. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  578. }
  579. } else if isTrialPeriod_year {
  580. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  581. if isSubscribed_year {
  582. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  583. }
  584. } else {
  585. if isSubscribed_newlyMonth || isSubscribed_year {
  586. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  587. } else {
  588. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  589. if #available(macOS 10.13.2, *) {
  590. #if !VERSION_DMG
  591. if introductoryPrice_newlyMonth == nil {
  592. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  593. } else if introductoryPrice_year == nil {
  594. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  595. }
  596. #endif
  597. }
  598. }
  599. }
  600. value1PurchaseBtnLbl.textColor = value1PurchaseBtnLblBtn.isEnabled ? NSColor.white : NSColor.white.withAlphaComponent(0.5)
  601. permanentPurchaseLblBtn.isEnabled = permanentPurchaseButton.isEnabled
  602. let averageMonthPrice: String?
  603. let monthPrice: String?
  604. let averageMonthPriceDiscount: String?
  605. let monthPriceDiscount: String?
  606. var allPrice: String?
  607. let isOffers_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isOffers ?? false
  608. let isOffers_year = fourDevicesAllAccessPackNew12months_lite?.isOffers ?? false
  609. if isOffers_newlyMonth {
  610. specialView1.isHidden = false
  611. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersAveragePrice()
  612. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersPrice()
  613. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  614. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  615. } else if isOffers_year {
  616. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.offersAveragePrice()
  617. monthPrice = fourDevicesAllAccessPackNew12months_lite?.offersPrice()
  618. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  619. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  620. } else {
  621. specialView1.isHidden = true
  622. if !model.isPurchaseSwitch {
  623. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.averagePrice()
  624. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.price()
  625. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  626. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  627. } else {
  628. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.averagePrice()
  629. monthPrice = fourDevicesAllAccessPackNew12months_lite?.price()
  630. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  631. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  632. }
  633. }
  634. if let allAccessPackPermanent_lite = IAPProductsManager.default().allAccessPackPermanent_lite, allAccessPackPermanent_lite.isOffers {
  635. specialView.isHidden = false
  636. allPrice = allAccessPackPermanent_lite.offersPrice()
  637. } else {
  638. specialView.isHidden = true
  639. allPrice = IAPProductsManager.default().allAccessPackPermanent_lite?.price()
  640. }
  641. var off = 1 - (IAPProductsManager.default().allAccessPackPermanent_lite?.offers ?? 0)
  642. var offString = String(format: "%.f%%", off * 100)
  643. specialLabel.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  644. if model.isPurchaseSwitch {
  645. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.offers
  646. } else {
  647. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.offers
  648. }
  649. offString = String(format: "%.f%%", off * 100)
  650. specialLabel1.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  651. let image = NSImage(named: "KMImageNameCompareTagBG")
  652. specialImageView.image = image
  653. specialImageView1.image = image
  654. if KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice() {
  655. if model.isShowSale {
  656. value1PurchaseSubLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
  657. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  658. value1PurchaseOriPriceLbl.isHidden = false
  659. billedTopConst.constant = 16
  660. } else {
  661. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  662. value1PurchaseOriPriceLbl.isHidden = true
  663. billedTopConst.constant = 0
  664. }
  665. } else {
  666. if model.isPurchaseSwitch {
  667. if model.isShowSale {
  668. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("12 months", comment: ""))
  669. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  670. value1PurchaseOriPriceLbl.isHidden = false
  671. billedTopConst.constant = 16
  672. } else {
  673. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  674. value1PurchaseOriPriceLbl.isHidden = true
  675. billedTopConst.constant = 0
  676. }
  677. } else {
  678. if model.isShowSale {
  679. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("6mon", comment: ""))
  680. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  681. value1PurchaseOriPriceLbl.isHidden = false
  682. billedTopConst.constant = 16
  683. } else {
  684. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  685. value1PurchaseOriPriceLbl.isHidden = true
  686. billedTopConst.constant = 0
  687. }
  688. }
  689. }
  690. value1PurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  691. value1PurchaseOriPriceLbl.textColor = NSColor(white: 1.0, alpha: 0.7)
  692. value1PurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: value1PurchaseOriPriceLbl.stringValue, attributes: [
  693. .font : NSFont.SFProTextRegularFont(12),
  694. .foregroundColor: NSColor(white: 1, alpha: 0.7),
  695. .strikethroughStyle: NSUnderlineStyle.single.rawValue
  696. ])
  697. var tTips: String
  698. if model.isShowSale {
  699. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  700. } else {
  701. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  702. }
  703. if value1PurchaseBtnLbl.stringValue == NSLocalizedString("Free Trial", comment: "") {
  704. tTips = String(format: NSLocalizedString("Billed every 6 months at %@ after 7-day trial ends.", comment: ""), monthPrice ?? "")
  705. #if !VERSION_DMG
  706. if model.isPurchaseSwitch {
  707. if let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product {
  708. if #available(macOS 10.13.2, *) {
  709. let trialDays = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product.introductoryPrice?.subscriptionPeriod.numberOfUnits
  710. tTips = String(
  711. format: NSLocalizedString("Billed every 12 months at %@ after %@-day trial ends.", comment: ""),
  712. monthPrice ?? "",
  713. "\(trialDays ?? 0)"
  714. )
  715. }
  716. }
  717. } else {
  718. if let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product {
  719. if #available(macOS 10.13.2, *) {
  720. let trialDays = fourDevicesAllAccessPackNew6Months_lite.introductoryPrice?.subscriptionPeriod.numberOfUnits
  721. tTips = String(
  722. format: NSLocalizedString("Billed every 6 months at %@ after %@-day trial ends.", comment: ""),
  723. monthPrice ?? "",
  724. "\(trialDays ?? 0)"
  725. )
  726. }
  727. }
  728. }
  729. #endif
  730. }
  731. if #available(macOS 10.13.2, *) {
  732. #if !VERSION_DMG
  733. if model.isPurchaseSwitch {
  734. if (IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product?.introductoryPrice == nil) {
  735. if model.isShowSale {
  736. tTips = String(format: NSLocalizedString("%@ for the first year's subscription", comment: ""), monthPriceDiscount ?? "")
  737. } else {
  738. tTips = String(format: NSLocalizedString("Billed every 12 months at %@", comment: ""), monthPrice ?? "")
  739. }
  740. }
  741. } else {
  742. if (IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product.introductoryPrice == nil) {
  743. if model.isShowSale {
  744. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  745. } else {
  746. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  747. }
  748. }
  749. }
  750. #endif
  751. }
  752. value1PurchaseSubLabel.stringValue = String(format: NSLocalizedString("%@", comment: ""), tTips)
  753. value1PurchaseBtnLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  754. #endif
  755. #else
  756. // AppStore 付费版
  757. #endif
  758. }
  759. @objc func reloadDataContent() {
  760. tableView.reloadData()
  761. }
  762. func addWaitingView(to view: NSView) {
  763. removeWaitingView(from: view)
  764. let waitingView = WaitingView(frame: view.bounds)
  765. waitingView.autoresizingMask = [.width, .height]
  766. view.addSubview(waitingView)
  767. waitingView.startAnimation()
  768. }
  769. func removeWaitingView(from view: NSView) {
  770. for subview in view.subviews {
  771. if subview is WaitingView {
  772. subview.removeFromSuperview()
  773. break
  774. }
  775. }
  776. }
  777. func showDiscount() {
  778. discountYearly.isHidden = true
  779. discountPermanent.isHidden = true
  780. let content = KMAdvertisementManager.manager.info.StoreUserRecovery?.content ?? []
  781. if content.count > 0 {
  782. for (index, item) in content.enumerated() {
  783. switch index {
  784. case 1:
  785. configureDiscountView(discountYearly, with: item)
  786. case 2:
  787. configureDiscountView(discountPermanent, with: item)
  788. default:
  789. break
  790. }
  791. }
  792. }
  793. }
  794. private func configureDiscountView(_ view: NSImageView, with itemInfo: KMAdvertisementItemInfo) {
  795. if KMAdvertisementManager.checkAdvertisementValid(itemInfo) {
  796. view.isHidden = false
  797. let urlString = KMAdvertisementModelTransition.transitionImagePath(image: itemInfo.image, highlight: false)
  798. if let url = URL(string: urlString) {
  799. view.image = KMAdvertisementImage.imageWithURL(url: url) { image in
  800. view.image = image
  801. }
  802. }
  803. } else {
  804. view.isHidden = true
  805. }
  806. }
  807. // MARK: Button Actions
  808. @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
  809. if KMMemberInfo.shared.validFlag == "5" {
  810. KMMemberPromptWC.shared.showWindow(nil)
  811. KMMemberPromptWC.shared.tipType = .signouting
  812. } else {
  813. if model.isPurchaseSwitch {
  814. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: model.isCancelAutoRenew)
  815. } else {
  816. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: model.isCancelAutoRenew)
  817. }
  818. addWaitingView(to: window?.contentView ?? NSView())
  819. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_6Mon"])
  820. if model.isShowSale {
  821. kEventTag = 1
  822. if model.isPurchaseSwitch {
  823. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12Mon"], platform: .AppCenter)
  824. } else {
  825. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6Mon"], platform: .AppCenter)
  826. }
  827. }
  828. }
  829. }
  830. func showDiscountToSaveWindow() {
  831. guard KMDiscountToSaveWindowController.needShow() else { return }
  832. guard let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  833. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.image, highlight: true)) else { return }
  834. addWaitingView(to: window?.contentView ?? NSView())
  835. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  836. guard let self = self else { return }
  837. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  838. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_PromotionalOffer"], platform: .AppCenter)
  839. let winC = KMDiscountToSaveWindowController(windowNibName: "KMDiscountToSaveWindowController")
  840. self.discountToSaveWinC = winC
  841. self.window?.beginSheet(winC.window!) { _ in }
  842. winC.imgIv.image = image
  843. winC.itemClick = { idx in
  844. self.window?.endSheet(self.discountToSaveWinC?.window ?? NSWindow())
  845. self.discountToSaveWinC = nil
  846. if idx == 2 {
  847. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Subscribe"], platform: .AppCenter)
  848. } else if idx == 1 {
  849. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Cancel"], platform: .AppCenter)
  850. }
  851. }
  852. }
  853. }
  854. @IBAction func buttonItemClicked_Restore(_ sender: Any) {
  855. model.productRestore()
  856. addWaitingView(to: window?.contentView ?? NSView())
  857. }
  858. @IBAction func buttonItemClicked_Upgrade(_ sender: Any) {
  859. NSWorkspace.shared.open(URL(string: "macappstore://apps.apple.com/app/id825459243?mt=12")!)
  860. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Premium"])
  861. }
  862. @IBAction func privacyPolicyAction(_ sender: NSButton) {
  863. model.privacyPolicyAction()
  864. }
  865. @IBAction func termOfSerAction(_ sender: NSButton) {
  866. model.termOfSerAction()
  867. }
  868. @IBAction func buttonItemClicked_LicenseUpgrade(_ sender: Any) {
  869. IAPProductsManager.default().make(IAPProductsManager.default().allAccessPackPermanent_lite)
  870. addWaitingView(to: window?.contentView ?? NSView())
  871. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Permanent"])
  872. }
  873. @IBAction func buttonItemClicked_AboutSubscriptions(_ sender: Any) {
  874. let tMessage = """
  875. Subscription plans:
  876. Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)
  877. - Subscriptions will be charged through your iTunes account at the confirmation of purchase.
  878. - Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.
  879. - 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.
  880. - You may manage your subscriptions in your iTunes Account Settings after purchase.
  881. - No cancellation of the current subscription is allowed during an active subscription period.
  882. - Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service
  883. - Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy
  884. """
  885. let alert = NSAlert()
  886. alert.alertStyle = .informational
  887. alert.messageText = NSLocalizedString(tMessage, comment: "")
  888. alert.runModal()
  889. }
  890. @IBAction func buttonItemClicked_CloseWindow(_ sender: Any) {
  891. close()
  892. }
  893. @objc func switchAction(_ sender: NSButton) {
  894. model.isPurchaseSwitch.toggle()
  895. }
  896. @IBAction func appstorePurchaseAction(_ sender: NSButton) {
  897. model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
  898. guard let self = self else { return }
  899. }
  900. }
  901. // MARK: - InAppPurchaseManager Notification
  902. @objc func IAPProductFailedNotification(_ notification: Notification) {
  903. removeWaitingView(from: window?.contentView ?? NSView())
  904. }
  905. @objc func IAPProductPurchasedNotification(_ notification: Notification) {
  906. removeWaitingView(from: window?.contentView ?? NSView())
  907. reloadData()
  908. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  909. if kEventTag == 1 {
  910. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6MonthPaid"], platform: .AppCenter)
  911. }
  912. } else if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  913. if kEventTag == 1 {
  914. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12MonthPaid"], platform: .AppCenter)
  915. }
  916. }
  917. }
  918. @objc func IAPProductLoadedNotification(_ notification: Notification) {
  919. reloadData()
  920. }
  921. @objc func IAPProductRestoreFinishedNotification(_ notification: Notification) {
  922. removeWaitingView(from: window?.contentView ?? NSView())
  923. reloadData()
  924. }
  925. @objc func IAPProductRestoreFailedNotification(_ notification: Notification) {
  926. removeWaitingView(from: window?.contentView ?? NSView())
  927. }
  928. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  929. removeWaitingView(from: window?.contentView ?? NSView())
  930. reloadData()
  931. }
  932. @objc func themeChanged(_ notification: Notification) {
  933. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  934. self.box.fillColor = KMAppearance.Layout.l1Color()
  935. self.labelbox.fillColor = .clear
  936. self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
  937. self.textView.backgroundColor = .clear
  938. self.textView.textColor = NSColor.white.withAlphaComponent(0.5)
  939. self.value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  940. self.permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  941. }
  942. }
  943. // MARK: Bind Method
  944. func bindViewModel() -> Void {
  945. model.$state
  946. .receive(on: RunLoop.main)
  947. .sink { [weak self] newValue in
  948. }
  949. .store(in: &cancellables)
  950. model.$isPurchaseSwitch
  951. .receive(on: RunLoop.main)
  952. .sink { [weak self] newValue in
  953. self?.reloadDataContent()
  954. #if VERSION_FREE
  955. #if VERSION_DMG
  956. // DMG
  957. #else
  958. // AppStore 免费版本
  959. self?.refreshPurchaseSwitch()
  960. #endif
  961. #else
  962. // AppStore 付费版
  963. #endif
  964. }
  965. .store(in: &cancellables)
  966. }
  967. }
  968. extension KMProductCompareWC: NSTableViewDelegate, NSTableViewDataSource {
  969. // MARK: NSTableViewDataSource Methods
  970. func numberOfRows(in tableView: NSTableView) -> Int {
  971. return model.dataSource.count
  972. }
  973. // tableView:viewForTableColumn:row
  974. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  975. let object = model.dataSource[row]
  976. if let stringObject = object as? String {
  977. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  978. cellView.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  979. if model.state == .dmg_Base {
  980. cellView.selectBoxLeft.constant = 352.0 + 149.5 + 149.5
  981. cellView.selectBoxWidth.constant = 149.5
  982. } else if model.state == .dmg_MacWindows {
  983. cellView.selectBoxLeft.constant = 352.0
  984. cellView.selectBoxWidth.constant = 320.0
  985. } else if model.state == .lite_Base {
  986. cellView.selectBoxLeft.constant = 352.0 + 179.0
  987. cellView.selectBoxWidth.constant = 240.0
  988. } else if model.state == .lite_MacWindows {
  989. cellView.selectBoxLeft.constant = 352.0
  990. cellView.selectBoxWidth.constant = 320.0
  991. } else if model.state == .pro_Base {
  992. cellView.selectBoxLeft.constant = 352.0
  993. cellView.selectBoxWidth.constant = 299.0
  994. } else if model.state == .pro_Advanced {
  995. cellView.selectBoxLeft.constant = 352.0
  996. cellView.selectBoxWidth.constant = 320.0
  997. } else {
  998. // model.state == .trial
  999. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1000. cellView.selectBoxWidth.constant = 240.0
  1001. }
  1002. return cellView
  1003. }
  1004. } else if let arrayObject = object as? [String] {
  1005. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1006. let value1 = arrayObject.indices.contains(0) ? arrayObject[0] : ""
  1007. let value2 = arrayObject.indices.contains(1) ? arrayObject[1] : ""
  1008. let value3 = arrayObject.indices.contains(2) ? arrayObject[2] : ""
  1009. let value4 = arrayObject.indices.contains(3) ? arrayObject[3] : ""
  1010. let value5 = arrayObject.indices.contains(4) ? arrayObject[4] : ""
  1011. let value6 = arrayObject.indices.contains(5) ? arrayObject[5] : ""
  1012. cellView.textField?.stringValue = NSLocalizedString(value1, comment: "")
  1013. cellView.lineBox?.isHidden = false
  1014. if row + 1 == model.dataSource.count || model.dataSource[row + 1] is String {
  1015. cellView.lineBox?.isHidden = true
  1016. }
  1017. checkOrNot(cellView)
  1018. cellView.boxBottomConst?.constant = (row + 2 == model.dataSource.count) ? 0 : -4
  1019. updateCellView(cellView, value1: value2, value2: value3, value3: value4, value4: value5, value5: value6)
  1020. return cellView
  1021. }
  1022. } else if object is [String: Any] {
  1023. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableEmptyCell"), owner: self) as? KMProductCompareTableEmptyCell {
  1024. return cellView
  1025. }
  1026. }
  1027. return nil
  1028. }
  1029. // tableView:heightOfRow
  1030. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1031. let object = model.dataSource[row]
  1032. var cellView: NSTableCellView?
  1033. if let stringObject = object as? String {
  1034. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1035. cell.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1036. cellView = cell
  1037. }
  1038. } else if let arrayObject = object as? [String] {
  1039. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1040. cell.textField?.stringValue = NSLocalizedString(arrayObject[0], comment: "")
  1041. cellView = cell
  1042. }
  1043. } else if object is [String: Any] {
  1044. return 40
  1045. }
  1046. if let view = cellView {
  1047. view.layoutSubtreeIfNeeded()
  1048. return view.frame.size.height
  1049. } else {
  1050. return 44
  1051. }
  1052. }
  1053. // Helper function to update cell view for multiple values
  1054. private func updateCellView(_ cellView: KMProductCompareTableCell, value1: String, value2: String, value3: String, value4: String, value5: String) {
  1055. if model.state == .dmg_Base {
  1056. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1057. configureCellView(cellView, value: value2, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1058. configureCellView(cellView, value: value3, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1059. configureCellView(cellView, value: value4, label: cellView.value4Label, imageView: cellView.value4ImageView, platformsBox: cellView.platformsBox4)
  1060. } else if model.state == .dmg_MacWindows {
  1061. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1062. } else if model.state == .lite_Base {
  1063. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1064. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1065. configureCellView(cellView, value: value4, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1066. } else if model.state == .lite_MacWindows {
  1067. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1068. } else if model.state == .pro_Base {
  1069. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1070. configureCellView(cellView, value: value5, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1071. } else if model.state == .pro_Advanced {
  1072. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1073. } else {
  1074. // model.state == .trial
  1075. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1076. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1077. }
  1078. }
  1079. // Helper function to configure each individual value
  1080. private func configureCellView(_ cellView: KMProductCompareTableCell, value: String, label: NSTextField?, imageView: NSImageView?, platformsBox: NSBox?) {
  1081. platformsBox?.isHidden = true
  1082. switch value {
  1083. case "X":
  1084. label?.stringValue = ""
  1085. imageView?.image = NSImage(named: "compare_nosupport")
  1086. case "✓":
  1087. label?.stringValue = ""
  1088. imageView?.image = NSImage(named: "compare_support")
  1089. case "∞":
  1090. label?.stringValue = ""
  1091. imageView?.image = NSImage(named: "compare_00")
  1092. default:
  1093. if value == "mac, windows, ios, android" ||
  1094. value == "mac, windows" ||
  1095. value == "mac" {
  1096. platformsBox?.isHidden = false
  1097. label?.isHidden = true
  1098. imageView?.isHidden = true
  1099. if value == "mac, windows, ios, android" {
  1100. // platformsBox?.contentView = platformsView4
  1101. } else if value == "mac, windows" {
  1102. platformsBox?.contentView = platformsView2
  1103. } else if value == "mac" {
  1104. platformsBox?.contentView = platformsView1
  1105. }
  1106. } else {
  1107. label?.stringValue = NSLocalizedString(value, comment: "")
  1108. imageView?.image = nil
  1109. }
  1110. }
  1111. }
  1112. private func checkOrNot(_ cellView: KMProductCompareTableCell) {
  1113. if model.state == .dmg_Base {
  1114. cellView.selectBox3.isHidden = false
  1115. cellView.viewWidth1.constant = 149.5
  1116. cellView.viewWidth2.constant = 149.5
  1117. cellView.viewWidth3.constant = 149.5
  1118. cellView.viewWidth4.constant = 149.5
  1119. } else if model.state == .dmg_MacWindows {
  1120. cellView.selectBox1.isHidden = false
  1121. cellView.viewWidth1.constant = 320.0
  1122. } else if model.state == .lite_Base {
  1123. cellView.cellView4.isHidden = true
  1124. cellView.selectBox2.isHidden = false
  1125. cellView.viewWidth1.constant = 179.0
  1126. cellView.viewWidth2.constant = 240.0
  1127. cellView.viewWidth3.constant = 240.0
  1128. } else if model.state == .lite_MacWindows {
  1129. cellView.selectBox1.isHidden = false
  1130. cellView.viewWidth1.constant = 320.0
  1131. } else if model.state == .pro_Base {
  1132. cellView.cellView3.isHidden = true
  1133. cellView.selectBox1.isHidden = false
  1134. cellView.viewWidth1.constant = 299.0
  1135. } else if model.state == .pro_Advanced {
  1136. cellView.selectBox1.isHidden = false
  1137. cellView.viewWidth1.constant = 320.0
  1138. } else {
  1139. // model.state == .trial
  1140. cellView.cellView3.isHidden = true
  1141. cellView.cellView4.isHidden = true
  1142. cellView.selectBox2.isHidden = false
  1143. cellView.viewWidth1.constant = 179.0
  1144. cellView.viewWidth2.constant = 240.0
  1145. }
  1146. }
  1147. }
  1148. class KMProductCompareTableCell: NSTableCellView {
  1149. @IBOutlet weak var bgColorView: NSView!
  1150. @IBOutlet @objc weak var cellView1: NSView!
  1151. @IBOutlet @objc weak var cellView2: NSView!
  1152. @IBOutlet @objc weak var cellView3: NSView!
  1153. @IBOutlet @objc weak var cellView4: NSView!
  1154. @IBOutlet weak var value1Label: NSTextField!
  1155. @IBOutlet weak var value2Label: NSTextField!
  1156. @IBOutlet weak var value3Label: NSTextField!
  1157. @IBOutlet weak var value4Label: NSTextField!
  1158. @IBOutlet weak var value1ImageView: NSImageView!
  1159. @IBOutlet weak var value2ImageView: NSImageView!
  1160. @IBOutlet weak var value3ImageView: NSImageView!
  1161. @IBOutlet weak var value4ImageView: NSImageView!
  1162. @IBOutlet weak var lineBox: NSBox!
  1163. @IBOutlet weak var boxBottomConst: NSLayoutConstraint!
  1164. @IBOutlet @objc weak var platformsBox1: NSBox!
  1165. @IBOutlet @objc weak var platformsBox2: NSBox!
  1166. @IBOutlet @objc weak var platformsBox3: NSBox!
  1167. @IBOutlet @objc weak var platformsBox4: NSBox!
  1168. @IBOutlet @objc weak var selectBox1: NSBox!
  1169. @IBOutlet @objc weak var selectBox2: NSBox!
  1170. @IBOutlet @objc weak var selectBox3: NSBox!
  1171. @IBOutlet @objc weak var selectBox4: NSBox!
  1172. @IBOutlet weak var viewWidth1: NSLayoutConstraint!
  1173. @IBOutlet weak var viewWidth2: NSLayoutConstraint!
  1174. @IBOutlet weak var viewWidth3: NSLayoutConstraint!
  1175. @IBOutlet weak var viewWidth4: NSLayoutConstraint!
  1176. override func awakeFromNib() {
  1177. super.awakeFromNib()
  1178. bgColorView.wantsLayer = true
  1179. updateViewColor()
  1180. NotificationCenter.default.addObserver(
  1181. self,
  1182. selector: #selector(themeChanged(_:)),
  1183. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1184. object: nil
  1185. )
  1186. }
  1187. deinit {
  1188. NotificationCenter.default.removeObserver(self)
  1189. }
  1190. @objc func themeChanged(_ notification: Notification) {
  1191. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1192. self.updateViewColor()
  1193. }
  1194. }
  1195. private func updateViewColor() {
  1196. var textColor = NSColor(red: 68.0 / 255.0, green: 68.0 / 255.0, blue: 68.0 / 255.0, alpha: 1.0)
  1197. var subtextColor = NSColor(red: 141.0 / 255.0, green: 141.0 / 255.0, blue: 141.0 / 255.0, alpha: 1.0)
  1198. var lineColor = NSColor(red: 204.0 / 255.0, green: 204.0 / 255.0, blue: 204.0 / 255.0, alpha: 0.4)
  1199. if let layer = bgColorView.layer {
  1200. if KMAppearance.isDarkMode() {
  1201. layer.backgroundColor = NSColor(red: 24.0 / 255.0, green: 22.0 / 255.0, blue: 31.0 / 255.0, alpha: 1.0).cgColor
  1202. textColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.8)
  1203. subtextColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.6)
  1204. lineColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.15)
  1205. } else {
  1206. layer.backgroundColor = NSColor(red: 247.0 / 255.0, green: 245.0 / 255.0, blue: 1.0, alpha: 1.0).cgColor
  1207. }
  1208. }
  1209. value1Label.textColor = subtextColor
  1210. value2Label.textColor = subtextColor
  1211. value3Label.textColor = subtextColor
  1212. value4Label.textColor = subtextColor
  1213. lineBox.fillColor = lineColor
  1214. textField?.textColor = textColor
  1215. }
  1216. }
  1217. class KMProductCompareTableHeaderCell: NSTableCellView {
  1218. @IBOutlet weak var contentView: NSView?
  1219. @IBOutlet weak var selectBoxLeft: NSLayoutConstraint!
  1220. @IBOutlet weak var selectBoxWidth: NSLayoutConstraint!
  1221. deinit {
  1222. NotificationCenter.default.removeObserver(self)
  1223. }
  1224. override func awakeFromNib() {
  1225. super.awakeFromNib()
  1226. contentView?.wantsLayer = true
  1227. updateViewColor()
  1228. NotificationCenter.default.addObserver(
  1229. self,
  1230. selector: #selector(themeChanged(_:)),
  1231. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1232. object: nil
  1233. )
  1234. }
  1235. @objc private func themeChanged(_ notification: Notification) {
  1236. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1237. self.updateViewColor()
  1238. }
  1239. }
  1240. private func updateViewColor() {
  1241. if KMAppearance.isDarkMode() {
  1242. contentView?.layer?.backgroundColor = NSColor(red: 40/255, green: 38/255, blue: 47/255, alpha: 1).cgColor
  1243. } else {
  1244. contentView?.layer?.backgroundColor = NSColor(red: 237/255, green: 231/255, blue: 255/255, alpha: 1).cgColor
  1245. }
  1246. textField?.textColor = KMAppearance.Layout.h0Color()
  1247. textField?.font = NSFont.boldSystemFont(ofSize: 14.0)
  1248. }
  1249. }
  1250. class KMProductCompareTableEmptyCell: NSTableCellView {
  1251. override func awakeFromNib() {
  1252. super.awakeFromNib()
  1253. self.wantsLayer = true
  1254. updateViewColor()
  1255. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  1256. }
  1257. deinit {
  1258. DistributedNotificationCenter.default.removeObserver(self)
  1259. }
  1260. @objc private func themeChanged(_ notification: Notification) {
  1261. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1262. self.updateViewColor()
  1263. }
  1264. }
  1265. private func updateViewColor() {
  1266. if KMAppearance.isDarkMode() {
  1267. self.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1.0).cgColor
  1268. } else {
  1269. self.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1.0, alpha: 1.0).cgColor
  1270. }
  1271. }
  1272. }