KMNHomeViewController.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // KMNHomeViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/10/8.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNHomeViewController: NSViewController {
  10. @IBOutlet var leftContendBox: NSBox!
  11. @IBOutlet var homeOpenView: KMHomeOpenView!
  12. @IBOutlet var homeRecommondView: KMHomeRecommondView!
  13. @IBOutlet var rightInfoView: KMHomeRightView!
  14. var demoVC: WCCompWindowController = WCCompWindowController(windowNibName: "WCCompWindowController")
  15. override func viewDidLoad() {
  16. super.viewDidLoad()
  17. // Do view setup here.
  18. self.configLeftContendView()
  19. self.configRightContendView()
  20. self.initAdvertisementData()
  21. }
  22. override func viewDidAppear() {
  23. super.viewDidAppear()
  24. rightInfoView.resetScrollerStyle()
  25. rightInfoView.reloadData()
  26. }
  27. func configLeftContendView() {
  28. leftContendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
  29. homeOpenView.delegate = self
  30. self.homeRecommondView.reloadData()
  31. }
  32. func configRightContendView() {
  33. rightInfoView.delegate = self
  34. rightInfoView.reloadData()
  35. }
  36. func initAdvertisementData() {
  37. KMAdvertisementManager.manager.fetchDataWithResponseObject { [weak self] data, responseObject, error in
  38. KMPrint("获取广告数据成功")
  39. if data != nil {
  40. let content = data!.recommondContent
  41. let item = content?.recommondContentPDFPro
  42. var infos: [KMAdvertisementItemInfo] = []
  43. for info in item?.content ?? [] {
  44. if info.version == "recommondPDF-PDFtoOfficePack" {
  45. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
  46. infos.append(info)
  47. }
  48. } else {
  49. infos.append(info)
  50. }
  51. }
  52. item?.content = infos
  53. if KMAdvertisementManager.manager.infoDict.allKeys.count > 0 {
  54. if let adsInfo = KMAdvertisementManager.manager.infoDict["adsInfo"] {
  55. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["adsInfo"] as! NSDictionary
  56. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  57. let arrM = NSMutableArray.init()
  58. for dict in array {
  59. let adsInfo = KMAdsInfo.init()
  60. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  61. adsInfo.infoDict = mutableDictionary
  62. arrM.add(adsInfo)
  63. }
  64. KMAdsInfoManager.shareInstance.adsInfoArrM = arrM
  65. }
  66. if let couponInfo = KMAdvertisementManager.manager.infoDict["couponContent"] {
  67. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["couponContent"] as! NSDictionary
  68. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  69. if array.isEmpty == false {
  70. let dict = array[0]
  71. let adsInfo = KMCouponInfo.init()
  72. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  73. adsInfo.infoDict = mutableDictionary
  74. KMAdsInfoManager.shareInstance.couponInfo = adsInfo
  75. }
  76. }
  77. }
  78. }
  79. DispatchQueue.main.async {
  80. self?.homeRecommondView.reloadData()
  81. }
  82. }
  83. }
  84. @IBAction func showDemo(_ sender: Any) {
  85. demoVC.window?.center()
  86. demoVC.showWindow(nil)
  87. }
  88. }
  89. //MARK: - KMHomeOpenViewDelegate
  90. extension KMNHomeViewController: KMHomeOpenViewDelegate {
  91. func homeOpenViewDidChooseFileURLs(_ view: KMHomeOpenView?, _ urls: [URL]) {
  92. if let url = urls.first {
  93. }
  94. }
  95. }
  96. //MARK: - KMHomeRightViewDelegate
  97. extension KMNHomeViewController: KMHomeRightViewDelegate {
  98. //点击管理快捷工具按钮
  99. func homeRightViewDidManageQuickTools(_ view: KMHomeRightView) {
  100. let quickToolWindowController: KMNQuickToolWindowController = KMNQuickToolWindowController.init(windowNibName: "KMNQuickToolWindowController")
  101. quickToolWindowController.own_beginSheetModal(for: self.view.window) { string in
  102. }
  103. }
  104. //点击快捷工具列表中的某一项
  105. func homeRightViewDidQuickToolsItemClicked(_ view: KMHomeRightView, _ toolType: HomeQuickToolType) {
  106. print("HomeQuickToolType = %d", toolType.rawValue)
  107. }
  108. //最近文件列表删除更新结束后回调
  109. func homeRightViewDidRecentFilesUpdated(_ view: KMHomeRightView) {
  110. }
  111. //选择打开文件
  112. func homeRightViewDidChooseFileToOpen(_ view: KMHomeRightView, _ fileURL: URL) {
  113. }
  114. }
  115. //MARK: - KMNQuickToolWindowDelegate
  116. extension KMNHomeViewController: KMNQuickToolWindowDelegate {
  117. func quickToolWindowControllerUpdate() {
  118. // KMNHomeQuickToolManager.defaultManager.quickToolsItemMutableArray
  119. }
  120. }