KMProductCompareWC.swift 102 KB

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