KMProductCompareWC.swift 124 KB

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