KMProductCompareWC.swift 70 KB

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