KMProductCompareWC.swift 84 KB

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