KMProductCompareWC.swift 72 KB

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