KMProductCompareWC.swift 70 KB

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