KMProductCompareWC.swift 71 KB

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