KMProductCompareWC.swift 124 KB

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