KMProductCompareWC.swift 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  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: NSButton!
  58. @IBOutlet @objc weak var standardPlanPurchaseLbl: NSTextField!
  59. @IBOutlet @objc weak var standardPlanPurchaseLblBtn: NSButton!
  60. @IBOutlet @objc weak var standardPlanPurchaseSubLabel2: NSTextField!
  61. @IBOutlet @objc weak var standardPurchaseOriPriceLbl: NSTextField!
  62. // 高级版年订阅
  63. @IBOutlet @objc weak var advancedPlanInfoView: NSView!
  64. @IBOutlet @objc weak var advancedPlanInfoLabel: NSTextField!
  65. @IBOutlet @objc weak var advancedPlanPurchaseLabel: NSTextField!
  66. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel: NSTextField!
  67. @IBOutlet @objc weak var advancedPlanPurchaseButton: NSButton!
  68. @IBOutlet @objc weak var advancedPlanPurchaseLbl: NSTextField!
  69. @IBOutlet @objc weak var advancedPlanPurchaseLblBtn: NSButton!
  70. @IBOutlet @objc weak var advancedPlanPurchaseSubLabel2: NSTextField!
  71. @IBOutlet weak var backgroundImage3: NSImageView!
  72. @IBOutlet @objc weak var discountPermanent2: NSImageView!
  73. @IBOutlet @objc weak var advancedPurchaseOriPriceLbl: NSTextField!
  74. // 买断
  75. @IBOutlet @objc weak var permanentInfoView: NSView!
  76. @IBOutlet @objc weak var permanentInfoLabel: NSTextField!
  77. @IBOutlet @objc weak var permanentPurchaseLabel: NSTextField!
  78. @IBOutlet @objc weak var permanentPurchaseSubLabel: NSTextField!
  79. @IBOutlet @objc weak var permanentPurchaseButton: NSButton!
  80. @IBOutlet @objc weak var permanentPurchaseLbl: NSTextField!
  81. @IBOutlet @objc weak var permanentPurchaseLblBtn: NSButton!
  82. @IBOutlet @objc weak var permanentPurchaseSubLabel2: NSTextField!
  83. @IBOutlet @objc weak var discountPermanent4: NSImageView!
  84. @IBOutlet @objc weak var permanentPurchaseOriPriceLbl: NSTextField!
  85. @IBOutlet @objc weak var aboutButton: NSButton!
  86. @IBOutlet @objc weak var btnRestore: HyperLinkButton!
  87. @IBOutlet @objc weak var privacyPolicyBtn: HyperLinkButton!
  88. @IBOutlet @objc weak var termOfSerBtn: HyperLinkButton!
  89. @IBOutlet @objc weak var textView: NSTextView!
  90. @IBOutlet @objc weak var specialView: NSView!
  91. @IBOutlet @objc weak var specialImageView: NSImageView!
  92. @IBOutlet @objc weak var specialLabel: NSTextField!
  93. @IBOutlet @objc weak var specialView1: NSView!
  94. @IBOutlet @objc weak var specialImageView1: NSImageView!
  95. @IBOutlet @objc weak var specialLabel1: NSTextField!
  96. @IBOutlet @objc weak var box: NSBox!
  97. @IBOutlet @objc weak var labelbox: NSBox!
  98. // @IBOutlet @objc weak var topButtonOffset: NSLayoutConstraint!
  99. @objc var value1Layer: CALayer?
  100. @objc var discountToSaveWinC: KMDiscountToSaveWindowController?
  101. @IBOutlet @objc weak var billedTopConst: NSLayoutConstraint!
  102. @IBOutlet @objc weak var discountYearly: NSImageView!
  103. @IBOutlet @objc weak var discountPermanent: NSImageView!
  104. // @IBOutlet @objc weak var discountPremium: NSImageView!
  105. @IBOutlet @objc weak var platformsView1: NSView!
  106. @IBOutlet @objc weak var platformsView2: NSView!
  107. @IBOutlet @objc weak var platformsView3: NSView!
  108. @IBOutlet @objc weak var platformsView4: NSView!
  109. @IBOutlet @objc weak var giftAIImage1: NSImageView!
  110. @IBOutlet @objc weak var giftAILabel1: NSTextField!
  111. @IBOutlet @objc weak var giftAIImage2: NSImageView!
  112. @IBOutlet @objc weak var giftAILabel2: NSTextField!
  113. @IBOutlet @objc weak var giftAIImage3: NSImageView!
  114. @IBOutlet @objc weak var giftAILabel3: NSTextField!
  115. @IBOutlet @objc weak var giftAIImage4: NSImageView!
  116. @IBOutlet @objc weak var giftAILabel4: NSTextField!
  117. private var model = KMProductModel.shared
  118. private var cancellables = Set<AnyCancellable>()
  119. private var subscribeType_: KMSubscribeWaterMarkType?
  120. var subscribeType: KMSubscribeWaterMarkType? {
  121. get {
  122. return subscribeType_
  123. }
  124. }
  125. var orientation: Bool = false // 是否定向跳转
  126. var orientationType: KMCompareTableType = .trial // 定向跳转比较表
  127. static let shared: KMProductCompareWC = {
  128. let windowC = KMProductCompareWC(windowNibName: "KMProductCompareWC")
  129. return windowC
  130. }()
  131. override init(window: NSWindow?) {
  132. super.init(window: window)
  133. setupNotifications()
  134. }
  135. required init?(coder: NSCoder) {
  136. super.init(coder: coder)
  137. }
  138. // MARK: - Notification Setup
  139. private func setupNotifications() {
  140. NotificationCenter.default.addObserver(
  141. self,
  142. selector: #selector(IAPProductLoadedNotification(_:)),
  143. name: NSNotification.Name(rawValue: "KMIAPProductLoadedNotification"),
  144. object: nil
  145. )
  146. NotificationCenter.default.addObserver(
  147. self,
  148. selector: #selector(IAPSubscriptionLoadedNotification(_:)),
  149. name: NSNotification.Name(rawValue: "KMIAPSubscriptionLoadedNotification"),
  150. object: nil
  151. )
  152. NotificationCenter.default.addObserver(
  153. self,
  154. selector: #selector(IAPProductPurchasedNotification(_:)),
  155. name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"),
  156. object: nil
  157. )
  158. NotificationCenter.default.addObserver(
  159. self,
  160. selector: #selector(IAPProductFailedNotification(_:)),
  161. name: NSNotification.Name(rawValue: "KMIAPProductFailedNotification"),
  162. object: nil
  163. )
  164. NotificationCenter.default.addObserver(
  165. self,
  166. selector: #selector(IAPProductRestoreFinishedNotification(_:)),
  167. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFinishedNotification"),
  168. object: nil
  169. )
  170. NotificationCenter.default.addObserver(
  171. self,
  172. selector: #selector(IAPProductRestoreFailedNotification(_:)),
  173. name: NSNotification.Name(rawValue: "KMIAPProductRestoreFailedNotification"),
  174. object: nil
  175. )
  176. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  177. }
  178. // MARK: - Deinitialization
  179. deinit {
  180. NotificationCenter.default.removeObserver(self)
  181. }
  182. // MARK: - Singleton
  183. @objc class func sharedInstance() -> NSWindowController {
  184. struct Singleton {
  185. static let instance: KMProductCompareWC = KMProductCompareWC()
  186. }
  187. return Singleton.instance
  188. }
  189. override func windowDidLoad() {
  190. super.windowDidLoad()
  191. window?.backgroundColor = KMAppearance.Upgrade.vipBGColor()
  192. window?.isMovableByWindowBackground = true
  193. #if VERSION_DMG
  194. btnRestore.isHidden = true
  195. #endif
  196. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  197. bindViewModel()
  198. if orientation {
  199. model.state = orientationType
  200. } else {
  201. model.getCurrentComparisonTableType()
  202. }
  203. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  204. value1InfoLabel.font = NSFont.UbuntuMediumFontWithSize(16)
  205. value1PurchaseButton.wantsLayer = true
  206. value1PurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  207. value1PurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  208. value1PurchaseBtnLblBtn.wantsLayer = true
  209. value1PurchaseButton.mouseMoveCallback = { [weak self] mouseEntered in
  210. guard let self = self else { return }
  211. if self.value1PurchaseBtnLblBtn.isEnabled == true {
  212. self.value1PurchaseBtnLblBtn.layer?.backgroundColor = mouseEntered ? NSColor.black.withAlphaComponent(0.15).cgColor : NSColor.clear.cgColor
  213. }
  214. }
  215. value1PurchaseBtnLblBtn.layer?.cornerRadius = value1PurchaseBtnLblBtn.frame.height / 2
  216. value1PurchaseBtnLblBtn.layer?.masksToBounds = true
  217. standardPlanPurchaseButton.wantsLayer = true
  218. standardPlanPurchaseButton.layer?.cornerRadius = standardPlanPurchaseButton.frame.height / 2
  219. self.standardPlanPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  220. switchLabel.stringValue = NSLocalizedString("Choose your favorite payment and enjoy flexible upgrades.", comment: "")
  221. switchLabel.textColor = KMAppearance.Interactive.m0Color()
  222. box.wantsLayer = true
  223. box.shadow = NSShadow()
  224. box.layer?.shadowOpacity = 0.3
  225. box.layer?.shadowColor = NSColor.black.withAlphaComponent(0.3).cgColor
  226. box.layer?.shadowOffset = NSMakeSize(0, 3)
  227. box.layer?.shadowRadius = 8
  228. box.layer?.masksToBounds = false
  229. permanentPurchaseButton.wantsLayer = true
  230. permanentPurchaseButton.layer?.cornerRadius = permanentPurchaseButton.frame.height / 2
  231. self.permanentPurchaseButton.layer?.backgroundColor = NSColor.white.cgColor
  232. let txtColor = NSColor(red: 102/255, green: 102/255, blue: 102/255, alpha: 1)
  233. aboutButton.title = NSLocalizedString("About Subscriptions", comment: "")
  234. aboutButton.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  235. aboutButton.isHidden = true
  236. reloadData()
  237. reloadDataContent()
  238. #if !VERSION_DMG
  239. IAPProductsManager.default().loadProducts()
  240. #endif
  241. #if VERSION_DMG
  242. textView.string = String(format: "Subscription plans:\nPDF Reader Pro Standard - Annual Plan: $79.99/year\nPDF Reader Pro Advanced - Annual Plan: $99.99/year\nPDF Reader Pro Permanent: $119.99\n\nSubscriptions: %@\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", "", NSLocalizedString("USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", comment: ""))
  243. #else
  244. textView.string = String(format: "Subscription plans:\nPDF Reader Pro Advanced - 6-Month Plan: $49.99/year\nPDF Reader Pro Advanced - Annual Plan: $99.99/year\nPDF Reader Pro Permanent: $119.99\n\nSubscriptions: %@\n- Subscriptions will be charged through your iTunes account at the confirmation of purchase.\n- Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.\n- Your iTunes account will be charged for renewal within 24-hours prior to the end of the current period, for the same duration and at the current subscription price.\n- You may manage your subscriptions in your iTunes Account Settings after purchase.\n- No cancellation of the current subscription is allowed during an active subscription period.\n\n- Terms of service:\nhttps://www.pdfreaderpro.com/terms_of_service\n- Privacy Policy:\nhttps://www.pdfreaderpro.com/privacy-policy", "", NSLocalizedString("USD $39.99/(6 months), USD$59.99/(12 months), USD $59.99/(one-time purchase)", comment: ""))
  245. #endif
  246. showDiscount()
  247. comparativeStatementHead()
  248. let closeButton = window?.standardWindowButton(.closeButton)
  249. closeButton?.target = self
  250. closeButton?.action = #selector(closeAction)
  251. }
  252. func windowShouldClose(sender:Any) -> Bool {
  253. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn":"PUW_Btn_Upgrade_Cancel"])
  254. if model.isShowSale {
  255. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn":"PUW_7OffUpgrade_Cancel"], platform: .AppCenter)
  256. }
  257. endModal(sender)
  258. return true
  259. }
  260. override func close() {
  261. super.close()
  262. endModal("")
  263. }
  264. @objc func startModal(_ sender: Any) {
  265. NSApp.stopModal()
  266. modalSession = NSApp.beginModalSession(for: window!)
  267. while NSApp.runModalSession(modalSession!) == .continue {
  268. // Modal loop
  269. }
  270. }
  271. @objc func endModal(_ sender: Any) {
  272. if let session = modalSession {
  273. NSApp.stopModal()
  274. NSApp.endModalSession(session)
  275. window?.orderOut(self)
  276. modalSession = nil
  277. }
  278. }
  279. @objc func showWindowRestore(_ sender: Any) {
  280. showWindow(sender)
  281. buttonItemClicked_Restore(sender)
  282. }
  283. @objc override func showWindow(_ sender: Any?) {
  284. super.showWindow(sender)
  285. subscribeType_ = nil
  286. _trackComparisonEvent(params: ["Exposure" : "ComparisonTable_Exposure"])
  287. alertingCodeForRefreshUserInfo_ = nil
  288. alertingForRefreshUserInfo_ = false
  289. #if VERSION_DMG
  290. model.getDMGProductDatas { success, result in
  291. }
  292. #endif
  293. if orientation {
  294. model.state = orientationType
  295. } else {
  296. model.getCurrentComparisonTableType()
  297. }
  298. languageLocalized()
  299. initializeUI()
  300. reloadData()
  301. if model.isShowSale {
  302. showDiscountToSaveWindow()
  303. }
  304. reloadDataContent()
  305. showDiscount()
  306. comparativeStatementHead()
  307. }
  308. func openWindow(type: KMSubscribeWaterMarkType) {
  309. showWindow(nil)
  310. subscribeType_ = type
  311. }
  312. public func closeWindow() {
  313. window?.close()
  314. }
  315. // MARK: - Private Methods
  316. private func languageLocalized() -> Void {
  317. titleLabel.stringValue = NSLocalizedString("Subscribe to All Access Pack to enjoy more expanded features.", comment: "")
  318. btnRestore.title = NSLocalizedString("Restore", comment: "")
  319. btnRestore.toolTip = NSLocalizedString("Restore", comment: "")
  320. privacyPolicyBtn.title = NSLocalizedString("Privacy Policy", comment: "")
  321. privacyPolicyBtn.toolTip = NSLocalizedString("Privacy Policy", comment: "")
  322. termOfSerBtn.title = NSLocalizedString("Terms of Service", comment: "")
  323. termOfSerBtn.toolTip = NSLocalizedString("Terms of Service", comment: "")
  324. sixMouthProLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  325. oneYearProLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  326. freeInfoLabel.stringValue = NSLocalizedString("Free", comment: "")
  327. standardPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Standard - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  328. standardPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  329. standardPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  330. advancedPlanInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Advanced - Annual Plan", tableName: "MemberCenterLocalizable", comment: "")
  331. advancedPlanPurchaseSubLabel.stringValue = NSLocalizedString("Auto-renewal | Billed yearly", tableName: "MemberCenterLocalizable", comment: "")
  332. advancedPlanPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  333. permanentInfoLabel.stringValue = NSLocalizedString("PDF Reader Pro Permanent", tableName: "MemberCenterLocalizable", comment: "")
  334. permanentPurchaseSubLabel.stringValue = NSLocalizedString("one-time purchase", comment: "")
  335. permanentPurchaseSubLabel2.stringValue = NSLocalizedString("(Tax Incl.)",tableName: "MemberCenterLocalizable", comment: "")
  336. standardPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  337. if KMMemberInfo.shared.userScenarioType == .lite_type3 ||
  338. KMMemberInfo.shared.userScenarioType == .lite_type11 {
  339. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Renew now",tableName: "MemberCenterLocalizable", comment: "")
  340. } else {
  341. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  342. }
  343. permanentPurchaseLbl.stringValue = NSLocalizedString("Purchase", comment: "")
  344. giftAILabel1.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  345. giftAILabel2.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  346. giftAILabel3.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  347. giftAILabel4.stringValue = NSLocalizedString("1-Year AI Tools Giveaway",tableName: "MemberCenterLocalizable", comment: "")
  348. #if VERSION_FREE
  349. #if VERSION_DMG
  350. // DMG
  351. if KMMemberInfo.shared.canTrail && model.state == .trial {
  352. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  353. }
  354. if model.state == .dmg_Base {
  355. standardPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProStandard_dmg)
  356. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  357. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProPermanent_dmg)
  358. } else if model.state == .dmg_Upgrades1 || model.state == .dmg_Upgrades2 {
  359. guard let productModels = model.dmgProductDatas?.listingProducts else { return }
  360. for productModel in productModels {
  361. if productModel.code == "advanced-annual-subscription" {
  362. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  363. guard let self = self else { return }
  364. guard let results: KMMemberProductResult = result else { return }
  365. guard let productModels2 = results.listingProducts else { return }
  366. for productModel2 in productModels2 {
  367. if productModel2.code == "advanced-annual-subscription" {
  368. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  369. }
  370. }
  371. }
  372. } else if productModel.code == "advanced-permanent-blackFive" {
  373. model.getDMGProductPriceInfosForMember(productId: productModel.id, isEducation: 0) { [weak self] success, result in
  374. guard let self = self else { return }
  375. guard let results: KMMemberProductResult = result else { return }
  376. guard let productModels2 = results.listingProducts else { return }
  377. for productModel2 in productModels2 {
  378. if productModel2.code == "advanced-annual-subscription-blackFive" {
  379. self.advancedPlanPurchaseLabel.stringValue = String(format: "USD $%.2f", Float(productModel2.upgradePriceString ?? "") ?? 0)
  380. }
  381. }
  382. }
  383. }
  384. }
  385. } else {
  386. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.pdfReaderProAdvanced_dmg)
  387. }
  388. #else
  389. var isTrialPeriod = false
  390. if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isTrialPeriod == true {
  391. isTrialPeriod = true
  392. }
  393. if(!isTrialPeriod &&
  394. KMMemberInfo.shared.canTrail &&
  395. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  396. advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  397. }
  398. // AppStore 免费版本
  399. if model.state == .lite_Base {
  400. permanentPurchaseLabel.stringValue = model.getProductPrice(.allAccessPackPermanent_lite)
  401. } else if model.state == .lite_MacWindows {
  402. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  403. let platforms = KMMemberInfo.shared.vip_platforms
  404. let platformsArray = platforms
  405. .components(separatedBy: ",")
  406. .map { $0.trimmingCharacters(in: .whitespaces) }
  407. if platformsArray.count == 1 {
  408. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  409. } else if platformsArray.count == 2 {
  410. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  411. } else {
  412. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_lite)
  413. }
  414. } else {
  415. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_lite)
  416. }
  417. } else {
  418. // model.state == .trial
  419. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPackNew12months_lite)
  420. }
  421. #endif
  422. #else
  423. // if IAPProductsManager.default().fourDevicesAllAccessPack12months_pro.isTrialPeriod == false && KMMemberInfo.shared.canTrail {
  424. // advancedPlanPurchaseLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  425. // }
  426. // AppStore 付费版
  427. if model.state == .pro_Base {
  428. if KMMemberInfo.shared.userScenarioType == .pro_type3 {
  429. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.standardAddDevicesAllAccessPack12months_pro)
  430. permanentPurchaseLabel.stringValue = model.getProductPrice(.pdfToOfficePackPermanent_pro)
  431. }
  432. } else if model.state == .pro_Advanced {
  433. let platforms = KMMemberInfo.shared.vip_platforms
  434. let platformsArray = platforms
  435. .components(separatedBy: ",")
  436. .map { $0.trimmingCharacters(in: .whitespaces) }
  437. if KMMemberInfo.shared.userScenarioType == .pro_type1 {
  438. if platformsArray.count == 1 {
  439. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  440. } else if platformsArray.count == 2 {
  441. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  442. } else if KMMemberInfo.shared.vip_levels == "1" {
  443. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  444. } else {
  445. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  446. }
  447. } else if KMMemberInfo.shared.userScenarioType == .pro_type4 {
  448. if platformsArray.count == 1 {
  449. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAddDevicesAllAccessPack12months_pro)
  450. } else if platformsArray.count == 2 {
  451. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  452. } else {
  453. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.advancedAdd2DevicesAllAccessPack12months_pro)
  454. }
  455. }
  456. } else {
  457. advancedPlanPurchaseLabel.stringValue = model.getProductPrice(.fourDevicesAllAccessPack12months_pro)
  458. }
  459. #endif
  460. }
  461. private func initializeUI() -> Void {
  462. btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  463. btnRestore.font = NSFont.SFProTextRegularFont(13)
  464. btnRestore.mouseMoveCallback = { [weak self] mouseEntered in
  465. guard let self = self else { return }
  466. if mouseEntered {
  467. self.btnRestore.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  468. } else {
  469. self.btnRestore.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  470. }
  471. }
  472. privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  473. privacyPolicyBtn.font = NSFont.SFProTextRegularFont(13)
  474. privacyPolicyBtn.mouseMoveCallback = { [weak self] mouseEntered in
  475. guard let self = self else { return }
  476. if mouseEntered {
  477. self.privacyPolicyBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  478. } else {
  479. self.privacyPolicyBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  480. }
  481. }
  482. termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  483. termOfSerBtn.font = NSFont.SFProTextRegularFont(13)
  484. termOfSerBtn.mouseMoveCallback = { [weak self] mouseEntered in
  485. guard let self = self else { return }
  486. if mouseEntered {
  487. self.termOfSerBtn.setTitleColor(NSColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.7))
  488. } else {
  489. self.termOfSerBtn.setTitleColor(NSColor(named: "FFFFFF") ?? NSColor.white)
  490. }
  491. }
  492. giftAILabel1.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  493. giftAILabel1.font = NSFont.SFProTextRegularFont(12)
  494. giftAILabel2.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  495. giftAILabel2.font = NSFont.SFProTextRegularFont(12)
  496. giftAILabel3.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  497. giftAILabel3.font = NSFont.SFProTextRegularFont(12)
  498. giftAILabel4.textColor = NSColor(named: "FFFFFF") ?? NSColor.white
  499. giftAILabel4.font = NSFont.SFProTextRegularFont(12)
  500. value1InfoTypeBox.fillColor = NSColor.clear
  501. value1InfoTypeBox.borderWidth = 0
  502. sixMouthProLabel.textColor = .white
  503. sixMouthProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  504. sixMouthProLabel.lineBreakMode = .byTruncatingTail
  505. sixMouthProLabel.toolTip = sixMouthProLabel.stringValue
  506. sixMouthProLabel.alignment = .center
  507. oneYearProLabel.textColor = .white
  508. oneYearProLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  509. oneYearProLabel.lineBreakMode = .byTruncatingTail
  510. oneYearProLabel.toolTip = oneYearProLabel.stringValue
  511. oneYearProLabel.alignment = .center
  512. switchBox.fillColor = NSColor(white: 1, alpha: 0.2)
  513. switchBox.cornerRadius = 12
  514. switchBox.borderWidth = 1
  515. switchBox.borderColor = NSColor(red: 235/255, green: 236/255, blue: 240/255, alpha: 1.0)
  516. switchCircleView.wantsLayer = true
  517. switchCircleView.layer?.cornerRadius = 8
  518. switchCircleView.layer?.backgroundColor = NSColor.white.cgColor
  519. switchBtn.title = ""
  520. switchBtn.target = self
  521. switchBtn.action = #selector(switchAction)
  522. saleLabel.isHidden = true
  523. saleLabel.superview?.isHidden = true
  524. saleBox.borderWidth = 0
  525. topMainBox.contentView = topMainView
  526. if let contentView = topMainBox.contentView {
  527. contentView.wantsLayer = true
  528. contentView.layer?.masksToBounds = false
  529. }
  530. if let contentView = topMainView {
  531. contentView.wantsLayer = true
  532. contentView.layer?.masksToBounds = false
  533. }
  534. topsubBox1.isHidden = false
  535. topsubBox2.isHidden = false
  536. topsubBox3.isHidden = false
  537. topsubBox4.isHidden = false
  538. topSelectBox1.isHidden = true
  539. topSelectBox2.isHidden = true
  540. topSelectBox3.isHidden = true
  541. topSelectBox4.isHidden = true
  542. giftAIImage1.isHidden = true
  543. giftAILabel1.isHidden = true
  544. giftAIImage2.isHidden = true
  545. giftAILabel2.isHidden = true
  546. giftAIImage3.isHidden = true
  547. giftAILabel3.isHidden = true
  548. giftAIImage4.isHidden = true
  549. giftAILabel4.isHidden = true
  550. freeInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  551. standardPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  552. advancedPlanInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  553. permanentInfoLabel.font = NSFont.UbuntuMediumFontWithSize(14)
  554. standardPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  555. standardPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  556. advancedPlanPurchaseSubLabel.font = NSFont.SFProTextRegularFont(11)
  557. advancedPlanPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  558. permanentPurchaseSubLabel.font = NSFont.UbuntuMediumFontWithSize(11)
  559. permanentPurchaseSubLabel2.font = NSFont.SFProTextRegularFont(11)
  560. value1PurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  561. standardPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  562. standardPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  563. advancedPlanPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  564. advancedPlanPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  565. permanentPurchaseLabel.font = NSFont.UbuntuBoldFontWithSize(20)
  566. permanentPurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  567. backgroundImage1.wantsLayer = true
  568. backgroundImage1.layer?.cornerRadius = 12
  569. backgroundImage1.layer?.masksToBounds = true
  570. backgroundImage3.wantsLayer = true
  571. backgroundImage3.layer?.cornerRadius = 12
  572. backgroundImage3.layer?.masksToBounds = true
  573. advancedPlanPurchaseButton.wantsLayer = true
  574. advancedPlanPurchaseButton.layer?.backgroundColor = NSColor(red: 1, green: 94/255, blue: 44/255, alpha: 1).cgColor
  575. advancedPlanPurchaseButton.layer?.cornerRadius = value1PurchaseButton.frame.height / 2
  576. standardPlanPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  577. advancedPlanPurchaseLbl.textColor = NSColor(named: "FFFFFF") ?? .white
  578. permanentPurchaseLbl.textColor = NSColor(named: "5528FF") ?? .blue
  579. var contentWidth = 970.0
  580. var contentHeight = 660.0
  581. if model.state == .dmg_Base {
  582. contentWidth = 970.0
  583. contentHeight = 660.0
  584. topsubBox1.contentView = freeInfoView
  585. topsubBox2.contentView = standardPlanInfoView
  586. topsubBox3.contentView = advancedPlanInfoView
  587. topsubBox4.contentView = permanentInfoView
  588. backgroundImage1.isHidden = true
  589. topSelectBox3.isHidden = false
  590. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  591. // giftAIImage3.isHidden = false
  592. // giftAILabel3.isHidden = false
  593. // }
  594. topsubBoxWidth1.constant = 149.5
  595. topsubBoxWidth2.constant = 149.5
  596. topsubBoxWidth3.constant = 149.5
  597. topsubBoxWidth3.constant = 149.5
  598. } else if model.state == .dmg_Upgrades1 {
  599. contentWidth = 689.0
  600. contentHeight = 660.0
  601. topsubBox2.isHidden = true
  602. topsubBox3.isHidden = true
  603. topsubBox4.isHidden = true
  604. topsubBox1.contentView = advancedPlanInfoView
  605. topSelectBox1.isHidden = false
  606. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  607. // giftAIImage1.isHidden = false
  608. // giftAILabel1.isHidden = false
  609. // }
  610. topsubBoxWidth1.constant = 320.0
  611. } else if model.state == .dmg_Upgrades2 {
  612. contentWidth = 689.0
  613. contentHeight = 660.0
  614. topsubBox2.isHidden = true
  615. topsubBox3.isHidden = true
  616. topsubBox4.isHidden = true
  617. topsubBox1.contentView = advancedPlanInfoView
  618. topSelectBox1.isHidden = false
  619. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  620. // giftAIImage1.isHidden = false
  621. // giftAILabel1.isHidden = false
  622. // }
  623. topsubBoxWidth1.constant = 320.0
  624. } else if model.state == .lite_Base {
  625. contentWidth = 970.0
  626. contentHeight = 660.0
  627. topsubBox4.isHidden = true
  628. topsubBox1.contentView = freeInfoView
  629. topsubBox2.contentView = value1InfoView
  630. topsubBox3.contentView = permanentInfoView
  631. topSelectBox2.isHidden = false
  632. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  633. // giftAIImage2.isHidden = false
  634. // giftAILabel2.isHidden = false
  635. // }
  636. topsubBoxWidth1.constant = 179.0
  637. topsubBoxWidth2.constant = 240.0
  638. topsubBoxWidth3.constant = 179.0
  639. } else if model.state == .lite_MacWindows {
  640. contentWidth = 689.0
  641. contentHeight = 660.0
  642. topsubBox2.isHidden = true
  643. topsubBox3.isHidden = true
  644. topsubBox4.isHidden = true
  645. topsubBox1.contentView = advancedPlanInfoView
  646. topSelectBox1.isHidden = false
  647. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  648. // giftAIImage1.isHidden = false
  649. // giftAILabel1.isHidden = false
  650. // }
  651. topsubBoxWidth1.constant = 320.0
  652. } else if model.state == .pro_Base {
  653. contentWidth = 970.0
  654. contentHeight = 660.0
  655. topsubBox3.isHidden = true
  656. topsubBox4.isHidden = true
  657. topsubBox1.contentView = advancedPlanInfoView
  658. topsubBox2.contentView = permanentInfoView
  659. backgroundImage1.isHidden = true
  660. topSelectBox1.isHidden = false
  661. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  662. // giftAIImage1.isHidden = false
  663. // giftAILabel1.isHidden = false
  664. // }
  665. topsubBoxWidth1.constant = 299.0
  666. topsubBoxWidth2.constant = 299.0
  667. } else if model.state == .pro_Advanced {
  668. contentWidth = 689.0
  669. contentHeight = 660.0
  670. topsubBox2.isHidden = true
  671. topsubBox3.isHidden = true
  672. topsubBox4.isHidden = true
  673. topsubBox1.contentView = advancedPlanInfoView
  674. topSelectBox1.isHidden = false
  675. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  676. // giftAIImage1.isHidden = false
  677. // giftAILabel1.isHidden = false
  678. // }
  679. topsubBoxWidth1.constant = 320.0
  680. } else {
  681. // model.state == .trial
  682. contentWidth = 785.0
  683. contentHeight = 660.0
  684. topsubBox3.isHidden = true
  685. topsubBox4.isHidden = true
  686. topsubBox1.contentView = freeInfoView
  687. topsubBox2.contentView = advancedPlanInfoView
  688. backgroundImage1.isHidden = true
  689. topSelectBox2.isHidden = false
  690. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  691. // giftAIImage2.isHidden = false
  692. // giftAILabel2.isHidden = false
  693. // }
  694. topsubBoxWidth1.constant = 179.0
  695. topsubBoxWidth2.constant = 240.0
  696. }
  697. self.window?.setContentSize(NSSize(width: contentWidth, height: contentHeight))
  698. self.window?.maxSize = NSSize(width: contentWidth, height: contentHeight)
  699. self.window?.minSize = NSSize(width: contentWidth, height: contentHeight)
  700. box.fillColor = KMAppearance.Layout.l1Color()
  701. labelbox.fillColor = .clear
  702. tableView.backgroundColor = KMAppearance.Layout.l0Color()
  703. textView.backgroundColor = .clear
  704. textView.textColor = NSColor.white.withAlphaComponent(0.5)
  705. value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  706. standardPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  707. standardPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  708. advancedPlanPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  709. advancedPlanPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  710. permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  711. permanentPurchaseSubLabel2.textColor = KMAppearance.Layout.w0Color()
  712. #if VERSION_FREE
  713. #if VERSION_DMG
  714. // DMG
  715. #else
  716. // AppStore 免费版本
  717. refreshPurchaseSwitch()
  718. #endif
  719. #else
  720. // AppStore 付费版
  721. #endif
  722. }
  723. @objc func reloadData() {
  724. saleBox.isHidden = true
  725. saleIv.isHidden = true
  726. if model.isShowSale {
  727. if let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  728. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.saleImage, highlight: true)) {
  729. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  730. guard let self = self else { return }
  731. self.saleIv.image = image
  732. self.saleBox.isHidden = false
  733. self.saleIv.isHidden = false
  734. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_7OffUpgrade"], platform: .AppCenter)
  735. }
  736. }
  737. } else {
  738. saleBox.isHidden = true
  739. }
  740. // if KMMemberInfo.shared.isMemberAllFunction == true {
  741. // value1PurchaseButton.isEnabled = false
  742. // permanentPurchaseButton.isEnabled = false
  743. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 0.5)
  744. // } else {
  745. // value1PurchaseButton.isEnabled = true
  746. // permanentPurchaseButton.isEnabled = true
  747. // permanentPurchaseLbl.textColor = NSColor(red: 85/255.0, green: 40/255.0, blue: 255/255.0, alpha: 1.0)
  748. // }
  749. permanentPurchaseLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  750. value1PurchaseOriPriceLbl.font = NSFont.SFProTextRegularFont(12)
  751. }
  752. func refreshPurchaseSwitch() -> Void {
  753. #if VERSION_FREE
  754. #if VERSION_DMG
  755. // DMG
  756. #else
  757. // AppStore 免费版本
  758. reloadData()
  759. if model.isPurchaseSwitch {
  760. // if KMMemberInfo.shared.vip_levels == "1" && KMMemberInfo.shared.vip_status != 2 {
  761. // giftAIImage2.isHidden = false
  762. // giftAILabel2.isHidden = false
  763. // }
  764. discountYearly.isHidden = false
  765. sixMouthProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  766. oneYearProLabel.textColor = NSColor.white
  767. switchCircleLeftConst.constant = 22
  768. value1InfoLabel.stringValue = NSLocalizedString("1-year Plan", comment: "")
  769. } else {
  770. giftAIImage2.isHidden = true
  771. giftAILabel2.isHidden = true
  772. discountYearly.isHidden = true
  773. sixMouthProLabel.textColor = NSColor.white
  774. oneYearProLabel.textColor = NSColor(red: 117/255.0, green: 119/255.0, blue: 128/255.0, alpha: 1.0)
  775. switchCircleLeftConst.constant = 4
  776. value1InfoLabel.stringValue = NSLocalizedString("6-Month Plan", comment: "")
  777. }
  778. value1PurchaseBtnLblBtn.isEnabled = value1PurchaseButton.isEnabled
  779. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  780. let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  781. let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  782. let isTrialPeriod_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isTrialPeriod ?? false
  783. let isSubscribed_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isSubscribed ?? false
  784. let isTrialPeriod_year = fourDevicesAllAccessPackNew12months_lite?.isTrialPeriod ?? false
  785. let isSubscribed_year = fourDevicesAllAccessPackNew12months_lite?.isSubscribed ?? false
  786. let introductoryPrice_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.product?.introductoryPrice
  787. let introductoryPrice_year = fourDevicesAllAccessPackNew12months_lite?.product?.introductoryPrice
  788. if(isSubscribed_year) {
  789. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribed", comment: "")
  790. } else {
  791. if(model.isPurchaseSwitch == true) {
  792. if(!isTrialPeriod_year &&
  793. KMMemberInfo.shared.canTrail &&
  794. model.checkSubscriptionOffer(for: IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product) == .freeTrial) {
  795. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Free Trial", comment: "")
  796. } else {
  797. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  798. }
  799. } else {
  800. value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  801. }
  802. }
  803. value1PurchaseBtnLbl.textColor = value1PurchaseBtnLblBtn.isEnabled ? NSColor.white : NSColor.white.withAlphaComponent(0.5)
  804. permanentPurchaseLblBtn.isEnabled = permanentPurchaseButton.isEnabled
  805. standardPlanPurchaseLblBtn.isEnabled = standardPlanPurchaseButton.isEnabled
  806. advancedPlanPurchaseLblBtn.isEnabled = advancedPlanPurchaseButton.isEnabled
  807. let averageMonthPrice: String?
  808. let monthPrice: String?
  809. let averageMonthPriceDiscount: String?
  810. let monthPriceDiscount: String?
  811. var allPrice: String?
  812. let isOffers_newlyMonth = fourDevicesAllAccessPackNew6Months_lite?.isOffers ?? false
  813. let isOffers_year = fourDevicesAllAccessPackNew12months_lite?.isOffers ?? false
  814. if isOffers_newlyMonth {
  815. specialView1.isHidden = false
  816. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersAveragePrice()
  817. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.offersPrice()
  818. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  819. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  820. } else if isOffers_year {
  821. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.offersAveragePrice()
  822. monthPrice = fourDevicesAllAccessPackNew12months_lite?.offersPrice()
  823. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  824. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  825. } else {
  826. specialView1.isHidden = true
  827. if !model.isPurchaseSwitch {
  828. averageMonthPrice = fourDevicesAllAccessPackNew6Months_lite?.averagePrice()
  829. monthPrice = fourDevicesAllAccessPackNew6Months_lite?.price()
  830. averageMonthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountAveragePrice()
  831. monthPriceDiscount = fourDevicesAllAccessPackNew6Months_lite?.discountPrice()
  832. } else {
  833. averageMonthPrice = fourDevicesAllAccessPackNew12months_lite?.averagePrice()
  834. monthPrice = fourDevicesAllAccessPackNew12months_lite?.price()
  835. averageMonthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountAveragePrice()
  836. monthPriceDiscount = fourDevicesAllAccessPackNew12months_lite?.discountPrice()
  837. }
  838. }
  839. if let allAccessPackPermanent_lite = IAPProductsManager.default().allAccessPackPermanent_lite, allAccessPackPermanent_lite.isOffers {
  840. specialView.isHidden = false
  841. allPrice = allAccessPackPermanent_lite.offersPrice()
  842. } else {
  843. specialView.isHidden = true
  844. allPrice = IAPProductsManager.default().allAccessPackPermanent_lite?.price()
  845. }
  846. var off = 1 - (IAPProductsManager.default().allAccessPackPermanent_lite?.offers ?? 0)
  847. var offString = String(format: "%.f%%", off * 100)
  848. specialLabel.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  849. if model.isPurchaseSwitch {
  850. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.offers
  851. } else {
  852. off = 1 - IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.offers
  853. }
  854. offString = String(format: "%.f%%", off * 100)
  855. specialLabel1.stringValue = String(format: NSLocalizedString("%@ off", comment: ""), offString)
  856. let image = NSImage(named: "KMImageNameCompareTagBG")
  857. specialImageView.image = image
  858. specialImageView1.image = image
  859. if KMKdanRemoteConfig.remoteConfig.showAPP_AveragePrice() {
  860. if model.isShowSale {
  861. value1PurchaseSubLabel.stringValue = String(format: "%@/%@", averageMonthPriceDiscount ?? "", NSLocalizedString("mon", comment: ""))
  862. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  863. value1PurchaseOriPriceLbl.isHidden = false
  864. billedTopConst.constant = 16
  865. } else {
  866. value1PurchaseLabel.stringValue = String(format: "%@/%@", averageMonthPrice ?? "", NSLocalizedString("mon", comment: ""))
  867. value1PurchaseOriPriceLbl.isHidden = true
  868. billedTopConst.constant = 0
  869. }
  870. } else {
  871. if model.isPurchaseSwitch {
  872. if model.isShowSale {
  873. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("12 months", comment: ""))
  874. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  875. value1PurchaseOriPriceLbl.isHidden = false
  876. billedTopConst.constant = 16
  877. } else {
  878. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("12 months", comment: ""))
  879. value1PurchaseOriPriceLbl.isHidden = true
  880. billedTopConst.constant = 0
  881. }
  882. } else {
  883. if model.isShowSale {
  884. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPriceDiscount ?? "", NSLocalizedString("6mon", comment: ""))
  885. value1PurchaseOriPriceLbl.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  886. value1PurchaseOriPriceLbl.isHidden = false
  887. billedTopConst.constant = 16
  888. } else {
  889. value1PurchaseLabel.stringValue = String(format: "%@/%@", monthPrice ?? "", NSLocalizedString("6mon", comment: ""))
  890. value1PurchaseOriPriceLbl.isHidden = true
  891. billedTopConst.constant = 0
  892. }
  893. }
  894. }
  895. value1PurchaseLabel.textColor = NSColor(red: 1.0, green: 231.0/255.0, blue: 106.0/255.0, alpha: 1.0)
  896. value1PurchaseOriPriceLbl.textColor = NSColor(white: 1.0, alpha: 0.7)
  897. value1PurchaseOriPriceLbl.attributedStringValue = NSAttributedString(string: value1PurchaseOriPriceLbl.stringValue, attributes: [
  898. .font : NSFont.SFProTextRegularFont(12),
  899. .foregroundColor: NSColor(white: 1, alpha: 0.7),
  900. .strikethroughStyle: NSUnderlineStyle.single.rawValue
  901. ])
  902. var tTips: String
  903. if model.isShowSale {
  904. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  905. } else {
  906. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  907. }
  908. if value1PurchaseBtnLbl.stringValue == NSLocalizedString("Free Trial", comment: "") {
  909. tTips = String(format: NSLocalizedString("Billed every 6 months at %@ after 7-day trial ends.", comment: ""), monthPrice ?? "")
  910. #if !VERSION_DMG
  911. if model.isPurchaseSwitch {
  912. if let fourDevicesAllAccessPackNew12months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product {
  913. if #available(macOS 10.13.2, *) {
  914. let trialDays = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product.introductoryPrice?.subscriptionPeriod.numberOfUnits
  915. tTips = String(
  916. format: NSLocalizedString("Billed every 12 months at %@ after %@-day trial ends.", comment: ""),
  917. monthPrice ?? "",
  918. "\(trialDays ?? 0)"
  919. )
  920. }
  921. }
  922. } else {
  923. if let fourDevicesAllAccessPackNew6Months_lite = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.product {
  924. if #available(macOS 10.13.2, *) {
  925. let trialDays = fourDevicesAllAccessPackNew6Months_lite.introductoryPrice?.subscriptionPeriod.numberOfUnits
  926. tTips = String(
  927. format: NSLocalizedString("Billed every 6 months at %@ after %@-day trial ends.", comment: ""),
  928. monthPrice ?? "",
  929. "\(trialDays ?? 0)"
  930. )
  931. }
  932. }
  933. }
  934. #endif
  935. }
  936. if #available(macOS 10.13.2, *) {
  937. #if !VERSION_DMG
  938. if model.isPurchaseSwitch {
  939. if model.isShowSale {
  940. tTips = String(format: NSLocalizedString("%@ for the first year's subscription", comment: ""), monthPriceDiscount ?? "")
  941. } else {
  942. tTips = String(format: NSLocalizedString("Billed every 12 months at %@", comment: ""), monthPrice ?? "")
  943. }
  944. } else {
  945. if model.isShowSale {
  946. tTips = String(format: NSLocalizedString("%@ for the first 6-month subscription", comment: ""), monthPriceDiscount ?? "")
  947. } else {
  948. tTips = String(format: NSLocalizedString("Billed every 6 months at %@", comment: ""), monthPrice ?? "")
  949. }
  950. }
  951. #endif
  952. }
  953. value1PurchaseSubLabel.stringValue = String(format: NSLocalizedString("%@", comment: ""), tTips)
  954. value1PurchaseBtnLbl.font = NSFont.UbuntuBoldFontWithSize(16)
  955. #endif
  956. #else
  957. // AppStore 付费版
  958. // value1PurchaseBtnLbl.stringValue = NSLocalizedString("Subscribe", comment: "")
  959. let fourDevicesAllAccessPack12months_pro = IAPProductsManager.default().fourDevicesAllAccessPack12months_pro
  960. let standardAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().standardAddDevicesAllAccessPack12months_pro
  961. let advancedAddDevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_pro
  962. let advancedAdd2DevicesAllAccessPack12months_pro = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_pro
  963. // let pdfToOfficePackPermanent_pro = IAPProductsManager.default().pdfToOfficePackPermanent_pro
  964. let isTrialPeriod_year = fourDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  965. let isTrialPeriod_standard = standardAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  966. let isTrialPeriod_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  967. let isTrialPeriod_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isTrialPeriod ?? false
  968. let isSubscribed_year = fourDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  969. let isSubscribed_standard = standardAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  970. let isSubscribed_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.isSubscribed ?? false
  971. let isSubscribed_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.isSubscribed ?? false
  972. let introductoryPrice_year = fourDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  973. let introductoryPrice_standard = standardAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  974. let introductoryPrice_advanced1 = advancedAddDevicesAllAccessPack12months_pro?.product?.introductoryPrice
  975. let introductoryPrice_advanced2 = advancedAdd2DevicesAllAccessPack12months_pro?.product?.introductoryPrice
  976. #endif
  977. }
  978. @objc func reloadDataContent() {
  979. tableView.reloadData()
  980. }
  981. func addWaitingView(to view: NSView) {
  982. removeWaitingView(from: view)
  983. let waitingView = WaitingView(frame: view.bounds)
  984. waitingView.autoresizingMask = [.width, .height]
  985. view.addSubview(waitingView)
  986. waitingView.startAnimation()
  987. }
  988. func removeWaitingView(from view: NSView) {
  989. KMMainThreadExecute {
  990. for subview in view.subviews {
  991. if subview is WaitingView {
  992. subview.removeFromSuperview()
  993. break
  994. }
  995. }
  996. }
  997. }
  998. func showDiscount() {
  999. discountYearly.isHidden = true
  1000. discountPermanent.isHidden = true
  1001. discountPermanent2.isHidden = true
  1002. discountPermanent.isHidden = true
  1003. #if VERSION_FREE
  1004. #if VERSION_DMG
  1005. // DMG
  1006. if model.state != .dmg_Base { return }
  1007. #else
  1008. // AppStore 免费版本
  1009. if model.state != .lite_Base { return }
  1010. #endif
  1011. #else
  1012. // AppStore 付费版
  1013. if model.state != .pro_Base { return }
  1014. #endif
  1015. let content = KMAdvertisementManager.manager.info.StoreUserRecovery?.content ?? []
  1016. if content.count > 0 {
  1017. for (index, item) in content.enumerated() {
  1018. switch index {
  1019. case 1:
  1020. configureDiscountView(discountYearly, with: item)
  1021. case 2:
  1022. configureDiscountView(discountPermanent4, with: item)
  1023. case 3:
  1024. configureDiscountView(discountPermanent2, with: item)
  1025. case 4:
  1026. configureDiscountView(discountPermanent, with: item)
  1027. default:
  1028. break
  1029. }
  1030. }
  1031. }
  1032. }
  1033. private func configureDiscountView(_ view: NSImageView, with itemInfo: KMAdvertisementItemInfo) {
  1034. if KMAdvertisementManager.checkAdvertisementValid(itemInfo) {
  1035. view.isHidden = false
  1036. let urlString = KMAdvertisementModelTransition.transitionImagePath(image: itemInfo.image, highlight: false)
  1037. if let url = URL(string: urlString) {
  1038. view.image = KMAdvertisementImage.imageWithURL(url: url) { image in
  1039. view.image = image
  1040. }
  1041. }
  1042. } else {
  1043. view.isHidden = true
  1044. }
  1045. }
  1046. private func showAlert(message: String) {
  1047. let alert = NSAlert()
  1048. alert.alertStyle = .critical
  1049. alert.messageText = message
  1050. alert.addButton(withTitle: NSLocalizedString("OK", comment: ""))
  1051. alert.runModal()
  1052. }
  1053. private var alertingForRefreshUserInfo_ = false
  1054. private var alertingCodeForRefreshUserInfo_: Int?
  1055. private func handleVerificationFailure(msg: KMMemberProductResult?) {
  1056. if self.alertingForRefreshUserInfo_ {
  1057. KMPrint("刷新用户信息-Alert中。。。")
  1058. return
  1059. }
  1060. if msg?.code == 500 {
  1061. KMPrint("错误信息: One record is expected, but the query result is multiple records。。。")
  1062. return
  1063. }
  1064. if msg?.code == alertingCodeForRefreshUserInfo_ {
  1065. KMPrint("刷新用户信息-Alert中 重复Code 。。。")
  1066. return
  1067. }
  1068. var message = msg?.msg ?? ""
  1069. if !message.isEmpty {
  1070. alertingForRefreshUserInfo_ = true
  1071. alertingCodeForRefreshUserInfo_ = msg?.code
  1072. KMMemberCenterManager.showAlert(code: .init(rawValue: msg?.code ?? 0), message: msg?.msg) { [weak self] resp, _ in
  1073. DispatchQueue.main.async {
  1074. self?.alertingForRefreshUserInfo_ = false
  1075. // self?.alertingCodeForRefreshUserInfo_ = nil
  1076. }
  1077. }
  1078. }
  1079. }
  1080. private func comparativeStatementHead() -> Void {
  1081. value1PurchaseOriPriceLbl.isHidden = true
  1082. standardPurchaseOriPriceLbl.isHidden = true
  1083. advancedPurchaseOriPriceLbl.isHidden = true
  1084. permanentPurchaseOriPriceLbl.isHidden = true
  1085. #if VERSION_FREE
  1086. #if VERSION_DMG
  1087. // DMG
  1088. #else
  1089. // AppStore 免费版本
  1090. if let product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.product, model.checkSubscriptionOffer(for: product) == .freeTrial {
  1091. }
  1092. #endif
  1093. #else
  1094. // AppStore 付费版
  1095. #endif
  1096. }
  1097. private func _trackComparisonEvent(params: [String : String]) {
  1098. #if VERSION_FREE
  1099. #if VERSION_DMG
  1100. #else
  1101. FMTrackEventManager.defaultManager.trackEvent(event: "ComparisonTableNew", withProperties: params)
  1102. #endif
  1103. #endif
  1104. }
  1105. private func _loginAfterAction(type: KMSubscribeWaterMarkType?) {
  1106. let info = KMMemberInfo.shared
  1107. var expired = info.vip_status == 2 || info.vip_status == 4
  1108. let state = info.userScenarioType
  1109. let platforms = info.userPlatforms()
  1110. let vip_levels = info.vip_levels
  1111. let vip_paymentModel = info.vip_paymentModel
  1112. if platforms.contains("mac") == false && vip_paymentModel == "1" {
  1113. let alert = NSAlert()
  1114. alert.alertStyle = .critical
  1115. alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
  1116. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1117. alert.runModal()
  1118. window?.close()
  1119. } else if platforms.count == 1 && platforms.first == "ios" && info.vip_levels == "3" && vip_paymentModel == "2" { // ios单平台高级版永久账户
  1120. KMMemberInfo.shared.productCompareShow()
  1121. return
  1122. } else if platforms.count == 1 && platforms.first == "mac" && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac 单平台高级版永久账户
  1123. // 关闭比较表,可以直接使用高级功能
  1124. window?.close()
  1125. return
  1126. } else if platforms.count == 2 && platforms.contains("windows") && platforms.contains("mac") && info.vip_levels == "3" && vip_paymentModel == "2" { // Mac & Windows 双平台高级永久账户
  1127. // 关闭比较表,可以直接使用高级功能
  1128. window?.close()
  1129. return
  1130. } else if platforms.count == 1 && platforms.first == "android" && info.vip_levels == "3" && vip_paymentModel == "1" && info.vip_cycle == 1 { // Android单平台高级版月订阅账户
  1131. // 关闭比较表,可以直接使用高级功能
  1132. let alert = NSAlert()
  1133. alert.alertStyle = .critical
  1134. alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
  1135. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1136. alert.runModal()
  1137. window?.close()
  1138. return
  1139. } else if platforms.count == 4 && vip_levels == "2" && vip_paymentModel == "1" && info.vip_cycle == 4 { // 全平台标准版年订阅账户 不支持升级,关闭比较表,可以直接使用非转档的高级功能
  1140. if type?.isConvertType() == false {
  1141. self.closeWindow()
  1142. return
  1143. }
  1144. let alert = NSAlert()
  1145. alert.alertStyle = .critical
  1146. alert.informativeText = NSLocalizedString("Sorry, you do not have the rights to this paid feature and cannot use it. If you have any questions, please contact customer service at support@pdfreaderpro.com", comment: "")
  1147. alert.addButton(withTitle: NSLocalizedString("Got it", comment: ""))
  1148. alert.runModal()
  1149. self.closeWindow()
  1150. return
  1151. } else {
  1152. self.closeWindow()
  1153. return
  1154. }
  1155. }
  1156. // MARK: Button Actions
  1157. @IBAction func buttonItemClicked_Subscribe(_ sender: Any) {
  1158. if model.isPurchaseSwitch {
  1159. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
  1160. } else {
  1161. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
  1162. }
  1163. if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
  1164. var product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  1165. if model.isPurchaseSwitch {
  1166. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1167. }
  1168. let type = subscribeType
  1169. KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
  1170. if KMMemberInfo.shared.isLogin == false {
  1171. return
  1172. }
  1173. let info = KMMemberInfo.shared
  1174. let expired = info.vip_status == 2 || info.vip_status == 4
  1175. if info.vip_levels == "1" || expired {
  1176. if self.model.isPurchaseSwitch { // 免费账户/订阅过期账户
  1177. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: self.model.isCancelAutoRenew)
  1178. } else {
  1179. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: self.model.isCancelAutoRenew)
  1180. }
  1181. return
  1182. } else {
  1183. self._loginAfterAction(type: type)
  1184. }
  1185. }
  1186. return
  1187. }
  1188. if KMMemberInfo.shared.validFlag == "5" {
  1189. KMMemberPromptWC.shared.showWindow(nil)
  1190. KMMemberPromptWC.shared.tipType = .signouting
  1191. } else {
  1192. if model.isPurchaseSwitch {
  1193. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite, discount: model.isCancelAutoRenew)
  1194. } else {
  1195. IAPProductsManager.default().makeSubProduct(IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite, discount: model.isCancelAutoRenew)
  1196. }
  1197. addWaitingView(to: window?.contentView ?? NSView())
  1198. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_6Mon"])
  1199. if model.isShowSale {
  1200. kEventTag = 1
  1201. if model.isPurchaseSwitch {
  1202. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12Mon"], platform: .AppCenter)
  1203. } else {
  1204. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6Mon"], platform: .AppCenter)
  1205. }
  1206. }
  1207. }
  1208. }
  1209. func showDiscountToSaveWindow() {
  1210. guard KMDiscountToSaveWindowController.needShow() else { return }
  1211. guard let info = KMAdvertisementManager.manager.info.StoreUserRecovery?.content?.first,
  1212. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: info.image, highlight: true)) else { return }
  1213. addWaitingView(to: window?.contentView ?? NSView())
  1214. KMAdvertisementImage.imageWithURL(url: url) { [weak self] image in
  1215. guard let self = self else { return }
  1216. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1217. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Exposure": "PUW_PromotionalOffer"], platform: .AppCenter)
  1218. let winC = KMDiscountToSaveWindowController(windowNibName: "KMDiscountToSaveWindowController")
  1219. self.discountToSaveWinC = winC
  1220. self.window?.beginSheet(winC.window!) { _ in }
  1221. winC.imgIv.image = image
  1222. winC.itemClick = { idx in
  1223. self.window?.endSheet(self.discountToSaveWinC?.window ?? NSWindow())
  1224. self.discountToSaveWinC = nil
  1225. if idx == 2 {
  1226. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Subscribe"], platform: .AppCenter)
  1227. } else if idx == 1 {
  1228. self.trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_PromotionalOffer_Cancel"], platform: .AppCenter)
  1229. }
  1230. }
  1231. }
  1232. }
  1233. @IBAction func buttonItemClicked_Restore(_ sender: Any) {
  1234. model.productRestore()
  1235. addWaitingView(to: window?.contentView ?? NSView())
  1236. }
  1237. @IBAction func buttonItemClicked_Upgrade(_ sender: Any) {
  1238. NSWorkspace.shared.open(URL(string: "macappstore://apps.apple.com/app/id825459243?mt=12")!)
  1239. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Premium"])
  1240. }
  1241. @IBAction func privacyPolicyAction(_ sender: NSButton) {
  1242. model.privacyPolicyAction()
  1243. }
  1244. @IBAction func termOfSerAction(_ sender: NSButton) {
  1245. model.termOfSerAction()
  1246. }
  1247. @IBAction func buttonItemClicked_LicenseUpgrade(_ sender: Any) {
  1248. IAPProductsManager.default().make(IAPProductsManager.default().allAccessPackPermanent_lite)
  1249. addWaitingView(to: window?.contentView ?? NSView())
  1250. FMTrackEventManager.defaultManager.trackEvent(event: "PUW", withProperties: ["PUW_Btn": "PUW_Btn_Upgrade_Permanent"])
  1251. trackEvent_free(eventName: "ComparisonTableNew", params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"], platform: .AppCenter)
  1252. }
  1253. @IBAction func buttonItemClicked_AboutSubscriptions(_ sender: Any) {
  1254. let tMessage = """
  1255. Subscription plans:
  1256. Subscriptions: USD $39.99/(6 months), USD $79.99/(one-time purchase)
  1257. - Subscriptions will be charged through your iTunes account at the confirmation of purchase.
  1258. - Your subscriptions will automatically renew unless cancelled at least 24 hours before the end of current subscription period.
  1259. - 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.
  1260. - You may manage your subscriptions in your iTunes Account Settings after purchase.
  1261. - No cancellation of the current subscription is allowed during an active subscription period.
  1262. - Terms of service: \nhttps://www.pdfreaderpro.com/terms_of_service
  1263. - Privacy Policy: \nhttps://www.pdfreaderpro.com/privacy-policy
  1264. """
  1265. let alert = NSAlert()
  1266. alert.alertStyle = .informational
  1267. alert.messageText = NSLocalizedString(tMessage, comment: "")
  1268. alert.runModal()
  1269. }
  1270. @IBAction func buttonItemClicked_CloseWindow(_ sender: Any) {
  1271. close()
  1272. }
  1273. @objc func switchAction(_ sender: NSButton) {
  1274. model.isPurchaseSwitch.toggle()
  1275. }
  1276. @IBAction func appstorePurchaseAction(_ sender: NSButton) {
  1277. if KMMemberInfo.shared.validFlag == "5" {
  1278. KMMemberPromptWC.shared.showWindow(nil)
  1279. KMMemberPromptWC.shared.tipType = .signouting
  1280. } else {
  1281. #if !VERSION_DMG
  1282. // addWaitingView(to: window?.contentView ?? NSView())
  1283. #endif
  1284. let state = model.state
  1285. let tag = sender.tag
  1286. var product: IAPProduct?
  1287. let isPurchaseSwitch = model.isPurchaseSwitch
  1288. if state == .lite_Base {
  1289. if tag == 0 {
  1290. if isPurchaseSwitch {
  1291. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1292. } else {
  1293. product = IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite
  1294. }
  1295. } else if tag == 3 {
  1296. product = IAPProductsManager.default().allAccessPackPermanent_lite
  1297. } else {
  1298. product = IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite
  1299. }
  1300. } else if state == .lite_MacWindows {
  1301. if tag == 2 {
  1302. let platforms = KMMemberInfo.shared.vip_platforms
  1303. let platformsArray = platforms
  1304. .components(separatedBy: ",")
  1305. .map { $0.trimmingCharacters(in: .whitespaces) }
  1306. if KMMemberInfo.shared.userScenarioType == .lite_type5 {
  1307. if platformsArray.count == 1 {
  1308. product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
  1309. } else if platformsArray.count == 2 {
  1310. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1311. }
  1312. } else {
  1313. if platformsArray.count == 1 {
  1314. product = IAPProductsManager.default().advancedAddDevicesAllAccessPack12months_lite
  1315. } else if platformsArray.count == 2 {
  1316. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1317. } else {
  1318. product = IAPProductsManager.default().advancedAdd2DevicesAllAccessPack12months_lite
  1319. }
  1320. }
  1321. }
  1322. }
  1323. if product == IAPProductsManager.default().allAccessPackPermanent_lite {
  1324. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyPermanent"])
  1325. } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite {
  1326. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvancedAnnual"])
  1327. } else if product == IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite {
  1328. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_BuyAdvanced6Mon"])
  1329. }
  1330. let type = subscribeType
  1331. if KMIsAppStoreFreeVersion() && subscribeType != nil && KMMemberInfo.shared.isLogin == false { // AppStore 免费版 + 付费功能进入 + 未登陆,跳转登陆
  1332. KMLoginWindowsController.shared.newOpenWindow(type: subscribeType, product: product, needDiscount: model.isCancelAutoRenew) { success in
  1333. if KMMemberInfo.shared.isLogin == false {
  1334. return
  1335. }
  1336. let info = KMMemberInfo.shared
  1337. let expired = info.vip_status == 2 || info.vip_status == 4
  1338. if info.vip_levels == "1" || expired {
  1339. self.model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
  1340. }
  1341. return
  1342. } else {
  1343. self._loginAfterAction(type: type)
  1344. return
  1345. }
  1346. }
  1347. return
  1348. }
  1349. addWaitingView(to: window?.contentView ?? NSView())
  1350. model.appstorePurchaseAction(sender.tag) { [weak self] success, msg in
  1351. guard let self = self else { return }
  1352. }
  1353. #if VERSION_DMG
  1354. close()
  1355. #endif
  1356. }
  1357. }
  1358. @objc func closeAction() {
  1359. _trackComparisonEvent(params: ["Btn" : "Btn_ComparisonTable_Cancel"])
  1360. self.window?.close()
  1361. }
  1362. // MARK: - InAppPurchaseManager Notification
  1363. @objc func IAPProductFailedNotification(_ notification: Notification) {
  1364. removeWaitingView(from: window?.contentView ?? NSView())
  1365. }
  1366. @objc func IAPProductPurchasedNotification(_ notification: Notification) {
  1367. KMMainThreadExecute {
  1368. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1369. self.reloadData()
  1370. if KMMemberInfo.shared.isLogin {
  1371. } else {
  1372. if let _ = KMLoginWindowsController.shared.subscribeType { // 付费->比较表->购买回来后 需要关闭登陆窗口
  1373. KMLoginWindowsController.shared.closeWindow()
  1374. }
  1375. }
  1376. }
  1377. #if VERSION_FREE
  1378. #if VERSION_DMG
  1379. // DMG
  1380. #else
  1381. // AppStore 免费版本
  1382. if IAPProductsManager.default().fourDevicesAllAccessPackNew6Months_lite.isSubscribed {
  1383. if kEventTag == 1 {
  1384. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_6MonthPaid"], platform: .AppCenter)
  1385. }
  1386. } else if IAPProductsManager.default().fourDevicesAllAccessPackNew12months_lite.isSubscribed {
  1387. if kEventTag == 1 {
  1388. trackEvent_free(eventName: "PromotionalOffer", params: ["PUW_Btn": "PUW_7OffUpgrade_12MonthPaid"], platform: .AppCenter)
  1389. }
  1390. }
  1391. #endif
  1392. #else
  1393. // AppStore 付费版
  1394. #endif
  1395. }
  1396. @objc func IAPProductLoadedNotification(_ notification: Notification) {
  1397. KMMainThreadExecute {
  1398. self.reloadData()
  1399. }
  1400. }
  1401. @objc func IAPProductRestoreFinishedNotification(_ notification: Notification) {
  1402. KMMainThreadExecute {
  1403. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1404. self.reloadData()
  1405. }
  1406. }
  1407. @objc func IAPProductRestoreFailedNotification(_ notification: Notification) {
  1408. removeWaitingView(from: window?.contentView ?? NSView())
  1409. }
  1410. @objc func IAPSubscriptionLoadedNotification(_ notification: Notification) {
  1411. KMMainThreadExecute {
  1412. self.removeWaitingView(from: self.window?.contentView ?? NSView())
  1413. self.reloadData()
  1414. DispatchQueue.global().async { [weak self] in
  1415. guard let self = self else { return }
  1416. if KMMemberInfo.shared.isLogin {
  1417. self.model.appStoreEquityVerification(notification) { success, msg in
  1418. DispatchQueue.main.async {
  1419. if success {
  1420. // self.showAlert(message: NSLocalizedString("Binding Interest Success!", comment: ""))
  1421. KMUserInfoVCModel().refreshUserInfo { success, msg,dic in
  1422. if(success) {
  1423. NotificationCenter.default.post(name: NSNotification.Name.KMMemberInfoChange, object: self)
  1424. }
  1425. }
  1426. self.window?.close()
  1427. } else {
  1428. self.handleVerificationFailure(msg: msg)
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. @objc func themeChanged(_ notification: Notification) {
  1437. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1438. self.box.fillColor = KMAppearance.Layout.l1Color()
  1439. self.labelbox.fillColor = .clear
  1440. self.tableView.backgroundColor = KMAppearance.Layout.l0Color()
  1441. self.textView.backgroundColor = .clear
  1442. self.textView.textColor = NSColor.white.withAlphaComponent(0.5)
  1443. self.value1PurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1444. self.permanentPurchaseSubLabel.textColor = KMAppearance.Layout.w0Color()
  1445. }
  1446. }
  1447. // MARK: Bind Method
  1448. func bindViewModel() -> Void {
  1449. model.$state
  1450. .receive(on: RunLoop.main)
  1451. .sink { [weak self] newValue in
  1452. }
  1453. .store(in: &cancellables)
  1454. model.$isPurchaseSwitch
  1455. .receive(on: RunLoop.main)
  1456. .sink { [weak self] newValue in
  1457. self?.reloadDataContent()
  1458. #if VERSION_FREE
  1459. #if VERSION_DMG
  1460. // DMG
  1461. #else
  1462. // AppStore 免费版本
  1463. self?.refreshPurchaseSwitch()
  1464. #endif
  1465. #else
  1466. // AppStore 付费版
  1467. #endif
  1468. }
  1469. .store(in: &cancellables)
  1470. }
  1471. }
  1472. extension KMProductCompareWC: NSTableViewDelegate, NSTableViewDataSource {
  1473. // MARK: NSTableViewDataSource Methods
  1474. func numberOfRows(in tableView: NSTableView) -> Int {
  1475. return model.dataSource.count
  1476. }
  1477. // tableView:viewForTableColumn:row
  1478. func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
  1479. let object = model.dataSource[row]
  1480. if let stringObject = object as? String {
  1481. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1482. cellView.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1483. if stringObject == "Membership Benefits" {
  1484. cellView.leftImageView?.isHidden = false
  1485. cellView.textField?.textColor = NSColor(named: "6D4D09") ?? .gray
  1486. } else {
  1487. cellView.leftImageView?.isHidden = true
  1488. cellView.textField?.textColor = NSColor(named: "0E1114") ?? .white
  1489. }
  1490. cellView.textfieldLeft.constant = cellView.leftImageView!.isHidden ? 32.0 : 62.0
  1491. if model.state == .dmg_Base {
  1492. cellView.selectBoxLeft.constant = 352.0 + 149.5 + 149.5
  1493. cellView.selectBoxWidth.constant = 149.5
  1494. } else if model.state == .dmg_Upgrades1 {
  1495. cellView.selectBoxLeft.constant = 352.0
  1496. cellView.selectBoxWidth.constant = 320.0
  1497. } else if model.state == .dmg_Upgrades2 {
  1498. cellView.selectBoxLeft.constant = 352.0
  1499. cellView.selectBoxWidth.constant = 320.0
  1500. } else if model.state == .lite_Base {
  1501. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1502. cellView.selectBoxWidth.constant = 240.0
  1503. } else if model.state == .lite_MacWindows {
  1504. cellView.selectBoxLeft.constant = 352.0
  1505. cellView.selectBoxWidth.constant = 320.0
  1506. } else if model.state == .pro_Base {
  1507. cellView.selectBoxLeft.constant = 352.0
  1508. cellView.selectBoxWidth.constant = 299.0
  1509. } else if model.state == .pro_Advanced {
  1510. cellView.selectBoxLeft.constant = 352.0
  1511. cellView.selectBoxWidth.constant = 320.0
  1512. } else {
  1513. // model.state == .trial
  1514. cellView.selectBoxLeft.constant = 352.0 + 179.0
  1515. cellView.selectBoxWidth.constant = 240.0
  1516. }
  1517. return cellView
  1518. }
  1519. } else if let arrayObject = object as? [String] {
  1520. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1521. let value1 = arrayObject.indices.contains(0) ? arrayObject[0] : ""
  1522. let value2 = arrayObject.indices.contains(1) ? arrayObject[1] : ""
  1523. let value3 = arrayObject.indices.contains(2) ? arrayObject[2] : ""
  1524. let value4 = arrayObject.indices.contains(3) ? arrayObject[3] : ""
  1525. let value5 = arrayObject.indices.contains(4) ? arrayObject[4] : ""
  1526. let value6 = arrayObject.indices.contains(5) ? arrayObject[5] : ""
  1527. cellView.textField?.stringValue = NSLocalizedString(value1, comment: "")
  1528. cellView.lineBox?.isHidden = false
  1529. if row + 1 == model.dataSource.count || model.dataSource[row + 1] is String {
  1530. cellView.lineBox?.isHidden = true
  1531. }
  1532. checkOrNot(cellView)
  1533. cellView.boxBottomConst?.constant = (row + 2 == model.dataSource.count) ? 0 : -4
  1534. updateCellView(cellView, value1: value2, value2: value3, value3: value4, value4: value5, value5: value6)
  1535. return cellView
  1536. }
  1537. } else if object is [String: Any] {
  1538. if let cellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableEmptyCell"), owner: self) as? KMProductCompareTableEmptyCell {
  1539. return cellView
  1540. }
  1541. }
  1542. return nil
  1543. }
  1544. // tableView:heightOfRow
  1545. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
  1546. let object = model.dataSource[row]
  1547. var cellView: NSTableCellView?
  1548. if let stringObject = object as? String {
  1549. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableHeaderCell"), owner: self) as? KMProductCompareTableHeaderCell {
  1550. cell.textField?.stringValue = NSLocalizedString(stringObject, comment: "")
  1551. cellView = cell
  1552. }
  1553. } else if let arrayObject = object as? [String] {
  1554. if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier("KMProductCompareTableCell"), owner: self) as? KMProductCompareTableCell {
  1555. cell.textField?.stringValue = NSLocalizedString(arrayObject[0], comment: "")
  1556. cellView = cell
  1557. }
  1558. } else if object is [String: Any] {
  1559. return 40
  1560. }
  1561. if let view = cellView {
  1562. view.layoutSubtreeIfNeeded()
  1563. return view.frame.size.height
  1564. } else {
  1565. return 44
  1566. }
  1567. }
  1568. // Helper function to update cell view for multiple values
  1569. private func updateCellView(_ cellView: KMProductCompareTableCell, value1: String, value2: String, value3: String, value4: String, value5: String) {
  1570. if model.state == .dmg_Base {
  1571. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1572. configureCellView(cellView, value: value2, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1573. configureCellView(cellView, value: value3, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1574. configureCellView(cellView, value: value4, label: cellView.value4Label, imageView: cellView.value4ImageView, platformsBox: cellView.platformsBox4)
  1575. } else if model.state == .dmg_Upgrades1 {
  1576. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1577. } else if model.state == .dmg_Upgrades2 {
  1578. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1579. } else if model.state == .lite_Base {
  1580. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1581. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1582. configureCellView(cellView, value: value4, label: cellView.value3Label, imageView: cellView.value3ImageView, platformsBox: cellView.platformsBox3)
  1583. } else if model.state == .lite_MacWindows {
  1584. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1585. } else if model.state == .pro_Base {
  1586. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1587. configureCellView(cellView, value: value5, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1588. } else if model.state == .pro_Advanced {
  1589. configureCellView(cellView, value: value3, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1590. } else {
  1591. // model.state == .trial
  1592. configureCellView(cellView, value: value1, label: cellView.value1Label, imageView: cellView.value1ImageView, platformsBox: cellView.platformsBox1)
  1593. configureCellView(cellView, value: value3, label: cellView.value2Label, imageView: cellView.value2ImageView, platformsBox: cellView.platformsBox2)
  1594. }
  1595. }
  1596. // Helper function to configure each individual value
  1597. private func configureCellView(_ cellView: KMProductCompareTableCell, value: String, label: NSTextField?, imageView: NSImageView?, platformsBox: NSBox?) {
  1598. platformsBox?.isHidden = true
  1599. label?.isHidden = false
  1600. imageView?.isHidden = false
  1601. switch value {
  1602. case "X":
  1603. label?.stringValue = ""
  1604. imageView?.image = NSImage(named: "compare_nosupport")
  1605. case "✓":
  1606. label?.stringValue = ""
  1607. imageView?.image = NSImage(named: "compare_support")
  1608. case "∞":
  1609. label?.stringValue = ""
  1610. imageView?.image = NSImage(named: "compare_00")
  1611. default:
  1612. if value == "mac, windows, ios, android" ||
  1613. value == "mac, windows" ||
  1614. value == "mac" {
  1615. platformsBox?.isHidden = false
  1616. label?.isHidden = true
  1617. imageView?.isHidden = true
  1618. if value == "mac, windows, ios, android" {
  1619. // platformsBox?.contentView = platformsView4
  1620. } else if value == "mac, windows" {
  1621. platformsBox?.contentView = platformsView2
  1622. } else if value == "mac" {
  1623. platformsBox?.contentView = platformsView1
  1624. }
  1625. } else {
  1626. label?.stringValue = NSLocalizedString(value, comment: "")
  1627. imageView?.image = nil
  1628. }
  1629. }
  1630. }
  1631. private func checkOrNot(_ cellView: KMProductCompareTableCell) {
  1632. cellView.selectBox1.isHidden = true
  1633. cellView.selectBox2.isHidden = true
  1634. cellView.selectBox3.isHidden = true
  1635. cellView.selectBox4.isHidden = true
  1636. cellView.cellView1.isHidden = true
  1637. cellView.cellView2.isHidden = true
  1638. cellView.cellView3.isHidden = true
  1639. cellView.cellView4.isHidden = true
  1640. if model.state == .dmg_Base {
  1641. cellView.selectBox3.isHidden = false
  1642. cellView.cellView1.isHidden = false
  1643. cellView.cellView2.isHidden = false
  1644. cellView.cellView3.isHidden = false
  1645. cellView.cellView4.isHidden = false
  1646. cellView.viewWidth1.constant = 149.5
  1647. cellView.viewWidth2.constant = 149.5
  1648. cellView.viewWidth3.constant = 149.5
  1649. cellView.viewWidth4.constant = 149.5
  1650. } else if model.state == .dmg_Upgrades1 {
  1651. cellView.selectBox1.isHidden = false
  1652. cellView.cellView1.isHidden = false
  1653. cellView.viewWidth1.constant = 320.0
  1654. } else if model.state == .dmg_Upgrades2 {
  1655. cellView.selectBox1.isHidden = false
  1656. cellView.cellView1.isHidden = false
  1657. cellView.viewWidth1.constant = 320.0
  1658. } else if model.state == .lite_Base {
  1659. cellView.selectBox2.isHidden = false
  1660. cellView.cellView1.isHidden = false
  1661. cellView.cellView2.isHidden = false
  1662. cellView.cellView3.isHidden = false
  1663. cellView.viewWidth1.constant = 179.0
  1664. cellView.viewWidth2.constant = 240.0
  1665. cellView.viewWidth3.constant = 240.0
  1666. } else if model.state == .lite_MacWindows {
  1667. cellView.selectBox1.isHidden = false
  1668. cellView.viewWidth1.constant = 320.0
  1669. cellView.cellView1.isHidden = false
  1670. } else if model.state == .pro_Base {
  1671. cellView.selectBox1.isHidden = false
  1672. cellView.viewWidth1.constant = 299.0
  1673. cellView.cellView1.isHidden = false
  1674. cellView.cellView2.isHidden = false
  1675. cellView.viewWidth2.constant = 299.0
  1676. } else if model.state == .pro_Advanced {
  1677. cellView.selectBox1.isHidden = false
  1678. cellView.viewWidth1.constant = 320.0
  1679. cellView.cellView1.isHidden = false
  1680. } else {
  1681. // model.state == .trial
  1682. cellView.cellView1.isHidden = false
  1683. cellView.cellView2.isHidden = false
  1684. cellView.selectBox2.isHidden = false
  1685. cellView.viewWidth1.constant = 179.0
  1686. cellView.viewWidth2.constant = 240.0
  1687. }
  1688. }
  1689. }
  1690. class KMProductCompareTableCell: NSTableCellView {
  1691. @IBOutlet weak var bgColorView: NSView!
  1692. @IBOutlet @objc weak var cellView1: NSView!
  1693. @IBOutlet @objc weak var cellView2: NSView!
  1694. @IBOutlet @objc weak var cellView3: NSView!
  1695. @IBOutlet @objc weak var cellView4: NSView!
  1696. @IBOutlet weak var value1Label: NSTextField!
  1697. @IBOutlet weak var value2Label: NSTextField!
  1698. @IBOutlet weak var value3Label: NSTextField!
  1699. @IBOutlet weak var value4Label: NSTextField!
  1700. @IBOutlet weak var value1ImageView: NSImageView!
  1701. @IBOutlet weak var value2ImageView: NSImageView!
  1702. @IBOutlet weak var value3ImageView: NSImageView!
  1703. @IBOutlet weak var value4ImageView: NSImageView!
  1704. @IBOutlet weak var lineBox: NSBox!
  1705. @IBOutlet weak var boxBottomConst: NSLayoutConstraint!
  1706. @IBOutlet @objc weak var platformsBox1: NSBox!
  1707. @IBOutlet @objc weak var platformsBox2: NSBox!
  1708. @IBOutlet @objc weak var platformsBox3: NSBox!
  1709. @IBOutlet @objc weak var platformsBox4: NSBox!
  1710. @IBOutlet @objc weak var selectBox1: NSBox!
  1711. @IBOutlet @objc weak var selectBox2: NSBox!
  1712. @IBOutlet @objc weak var selectBox3: NSBox!
  1713. @IBOutlet @objc weak var selectBox4: NSBox!
  1714. @IBOutlet weak var viewWidth1: NSLayoutConstraint!
  1715. @IBOutlet weak var viewWidth2: NSLayoutConstraint!
  1716. @IBOutlet weak var viewWidth3: NSLayoutConstraint!
  1717. @IBOutlet weak var viewWidth4: NSLayoutConstraint!
  1718. override func awakeFromNib() {
  1719. super.awakeFromNib()
  1720. bgColorView.wantsLayer = true
  1721. updateViewColor()
  1722. NotificationCenter.default.addObserver(
  1723. self,
  1724. selector: #selector(themeChanged(_:)),
  1725. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1726. object: nil
  1727. )
  1728. }
  1729. deinit {
  1730. NotificationCenter.default.removeObserver(self)
  1731. }
  1732. @objc func themeChanged(_ notification: Notification) {
  1733. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1734. self.updateViewColor()
  1735. }
  1736. }
  1737. private func updateViewColor() {
  1738. var textColor = NSColor(red: 68.0 / 255.0, green: 68.0 / 255.0, blue: 68.0 / 255.0, alpha: 1.0)
  1739. var subtextColor = NSColor(red: 141.0 / 255.0, green: 141.0 / 255.0, blue: 141.0 / 255.0, alpha: 1.0)
  1740. var lineColor = NSColor(red: 204.0 / 255.0, green: 204.0 / 255.0, blue: 204.0 / 255.0, alpha: 0.4)
  1741. if let layer = bgColorView.layer {
  1742. if KMAppearance.isDarkMode() {
  1743. layer.backgroundColor = NSColor(red: 24.0 / 255.0, green: 22.0 / 255.0, blue: 31.0 / 255.0, alpha: 1.0).cgColor
  1744. textColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.8)
  1745. subtextColor = NSColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.6)
  1746. lineColor = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.15)
  1747. } else {
  1748. layer.backgroundColor = NSColor(red: 247.0 / 255.0, green: 245.0 / 255.0, blue: 1.0, alpha: 1.0).cgColor
  1749. }
  1750. }
  1751. value1Label.textColor = subtextColor
  1752. value2Label.textColor = subtextColor
  1753. value3Label.textColor = subtextColor
  1754. value4Label.textColor = subtextColor
  1755. lineBox.fillColor = lineColor
  1756. textField?.textColor = textColor
  1757. }
  1758. }
  1759. class KMProductCompareTableHeaderCell: NSTableCellView {
  1760. @IBOutlet weak var contentView: NSView?
  1761. @IBOutlet weak var leftImageView: NSImageView?
  1762. @IBOutlet weak var textfieldLeft: NSLayoutConstraint!
  1763. @IBOutlet weak var selectBoxLeft: NSLayoutConstraint!
  1764. @IBOutlet weak var selectBoxWidth: NSLayoutConstraint!
  1765. deinit {
  1766. NotificationCenter.default.removeObserver(self)
  1767. }
  1768. override func awakeFromNib() {
  1769. super.awakeFromNib()
  1770. contentView?.wantsLayer = true
  1771. updateViewColor()
  1772. NotificationCenter.default.addObserver(
  1773. self,
  1774. selector: #selector(themeChanged(_:)),
  1775. name: NSNotification.Name("AppleInterfaceThemeChangedNotification"),
  1776. object: nil
  1777. )
  1778. }
  1779. @objc private func themeChanged(_ notification: Notification) {
  1780. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1781. self.updateViewColor()
  1782. }
  1783. }
  1784. private func updateViewColor() {
  1785. if KMAppearance.isDarkMode() {
  1786. contentView?.layer?.backgroundColor = NSColor(red: 40/255, green: 38/255, blue: 47/255, alpha: 1).cgColor
  1787. } else {
  1788. contentView?.layer?.backgroundColor = NSColor(red: 237/255, green: 231/255, blue: 255/255, alpha: 1).cgColor
  1789. }
  1790. textField?.textColor = KMAppearance.Layout.h0Color()
  1791. textField?.font = NSFont.boldSystemFont(ofSize: 14.0)
  1792. }
  1793. }
  1794. class KMProductCompareTableEmptyCell: NSTableCellView {
  1795. override func awakeFromNib() {
  1796. super.awakeFromNib()
  1797. self.wantsLayer = true
  1798. updateViewColor()
  1799. DistributedNotificationCenter.default.addObserver(self, selector: #selector(themeChanged(_:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  1800. }
  1801. deinit {
  1802. DistributedNotificationCenter.default.removeObserver(self)
  1803. }
  1804. @objc private func themeChanged(_ notification: Notification) {
  1805. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  1806. self.updateViewColor()
  1807. }
  1808. }
  1809. private func updateViewColor() {
  1810. if KMAppearance.isDarkMode() {
  1811. self.layer?.backgroundColor = NSColor(red: 24/255.0, green: 22/255.0, blue: 31/255.0, alpha: 1.0).cgColor
  1812. } else {
  1813. self.layer?.backgroundColor = NSColor(red: 247/255.0, green: 245/255.0, blue: 1.0, alpha: 1.0).cgColor
  1814. }
  1815. }
  1816. }