KMProductCompareWC.swift 72 KB

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