KMProductCompareWC.swift 82 KB

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