KMHomeViewController.swift 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. //
  2. // KMHomeViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/10/13.
  6. //
  7. import Cocoa
  8. @objc enum KMHomeToolState : Int {
  9. case OpenPDF = 0
  10. case CreatePDF
  11. case Home
  12. case PDFTools
  13. case FavoriteDocuments
  14. case CloudDocuments
  15. }
  16. @objc enum KMAIHomeToolState : Int {
  17. case Home = 0
  18. case AITranslation
  19. case AIRewriting
  20. case AIErrorCorrection
  21. }
  22. @objcMembers class KMHomeViewController: NSViewController {
  23. @IBOutlet weak var leftBox: NSBox!
  24. @IBOutlet weak var rightBox: NSBox!
  25. @IBOutlet weak var homeSplitView: NSSplitView!
  26. @IBOutlet weak var homeRightScrollViewView: NSScrollView!
  27. @IBOutlet weak var rightTopBox: NSBox!
  28. @IBOutlet weak var rightBottomBox: NSBox!
  29. @IBOutlet weak var rightFullBox: NSBox!
  30. @IBOutlet weak var rightTopBoxHeightConstraint: NSLayoutConstraint!
  31. @IBOutlet var fastToolViewController: KMHomeFastToolViewController!
  32. @IBOutlet var historyFileViewController: KMHomeHistoryFileViewController!
  33. @IBOutlet var pdfToolsViewController: KMPDFToolsViewController!
  34. @IBOutlet var cloudDocumentsViewController: KMCloudDocumentsViewController!
  35. @IBOutlet weak var dragView: KMHomeDragView!
  36. // AI 临时UI
  37. @IBOutlet weak var aiHomeBox: KMBox!
  38. @IBOutlet weak var aiHomeImageView: NSImageView!
  39. @IBOutlet weak var aiHomeLabel: NSTextField!
  40. @IBOutlet weak var aiTranslationBox: KMBox!
  41. @IBOutlet weak var aiTranslationImageView: NSImageView!
  42. @IBOutlet weak var aiTranslationLabel: NSTextField!
  43. @IBOutlet weak var aiRewritingBox: KMBox!
  44. @IBOutlet weak var aiRewritingImageView: NSImageView!
  45. @IBOutlet weak var aiRewritingLabel: NSTextField!
  46. @IBOutlet weak var aiErrorCorrectionBox: KMBox!
  47. @IBOutlet weak var aiErrorCorrectionImageView: NSImageView!
  48. @IBOutlet weak var aiErrorCorrectionLabel: NSTextField!
  49. @IBOutlet var aiOpenPDFFilesViewController: KMAIOpenPDFFilesVC!
  50. @IBOutlet var aiTranslationViewController: KMAITranslationVC!
  51. @IBOutlet var aiRewritingViewController: KMAIRewritingVC!
  52. @IBOutlet weak var creatPDFView: KMCreatPDFView!
  53. //HomeContentView
  54. @IBOutlet weak var homeContentView: KMHomeContentView!
  55. //广告 互推
  56. @IBOutlet weak var advertisementTableView: KMAdvertisementTableView!
  57. @IBOutlet weak var advertisementTableViewHeightConstraint: NSLayoutConstraint!
  58. @IBOutlet weak var advertisementShowView: KMAdvertisementShowView!
  59. //合并
  60. var mergeWindowController: KMMergeWindowController?
  61. var aiHomeState: KMAIHomeToolState = .Home
  62. let ScrollerViewWidget: CGFloat = 15.0
  63. var homeWindowController : MainWindowController!
  64. var isShowQuickTour: Bool = false
  65. weak var myDocument: NSDocument?
  66. var currentWindowController: NSWindowController?
  67. var homeState: KMHomeToolState = .Home
  68. var urlToPDFWindowController: KMURLToPDFWindowController?
  69. var openPDFButtonVC: KMDesignButton?
  70. var createPDFButtonVC: KMDesignButton?
  71. var createPDFImage: KMDesignButton?
  72. var createPDFAddButtonVC: KMDesignButton?
  73. var homeButtonVC: KMTextImageButtonVC?
  74. var pdfToolsButtonVC: KMTextImageButtonVC?
  75. var cloudDocumentsButtonVC: KMTextImageButtonVC?
  76. var pdfSeriesButtonVC: KMTextImageButtonVC?
  77. var pdfOthersButtonVC: KMTextImageButtonVC?
  78. var popover: NSPopover?
  79. var deviceBrowserWC: KMDeviceBrowserWindowController?
  80. var progressController: SKProgressController?
  81. var timer: Timer?
  82. var timerCounter = 0.0
  83. //AI相关
  84. //试用相关
  85. var didTrialExpiredLoad: Bool = false
  86. var repeatTrialAlertLoad: Bool = false
  87. var guideWindowVC: KMFunctionGuideWindowController!
  88. var showCoupon: Bool = true
  89. var couponDueWindowVC: KMCouponDueWindowController!
  90. @IBOutlet weak var rightBottonHeight: NSLayoutConstraint!
  91. var currentController: NSWindowController?
  92. deinit {
  93. NotificationCenter.default.removeObserver(self)
  94. }
  95. override func viewWillAppear() {
  96. super.viewWillAppear()
  97. if !KMLightMemberManager.manager.isLogin() {
  98. KMLightMemberManager.manager.canShowAdvancedView = true
  99. }
  100. self.homeContentView.reloadData()
  101. #if VERSION_DMG
  102. let kDMGFirstInstallKey = "DMGFirstInstallKey"
  103. if KMDataManager.ud_object(forKey: kDMGFirstInstallKey) == nil {
  104. KMDataManager.ud_set("Show", forKey: kDMGFirstInstallKey)
  105. KMTools.openURL(urlString: "http://www.pdfreaderpro.com/thank-you-for-installation")
  106. }
  107. #else
  108. // [self loadAIInfo];
  109. #endif
  110. }
  111. override func viewWillDisappear() {
  112. super.viewWillDisappear()
  113. // self.homeContentView.reloadData()
  114. }
  115. override func viewDidLoad() {
  116. super.viewDidLoad()
  117. // Do view setup here.
  118. openPDFButtonVC = KMDesignButton.init(withType: .Text)
  119. createPDFButtonVC = KMDesignButton.init(withType: .Text)
  120. createPDFImage = KMDesignButton.init(withType: .Image)
  121. createPDFAddButtonVC = KMDesignButton.init(withType: .Image)
  122. homeButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
  123. pdfToolsButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
  124. cloudDocumentsButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
  125. pdfSeriesButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
  126. pdfOthersButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
  127. self.homeSplitView.setPosition(270.0, ofDividerAt: 0)
  128. self.leftBox.fillColor = NSColor.km_init(hex: "#F7F8FA")
  129. self.rightBox.fillColor = NSColor.km_init(hex: "#F7F8FA")
  130. NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { (aEvent) -> NSEvent? in
  131. self.otherMouseDown(with: aEvent)
  132. return aEvent
  133. }
  134. self.initNetworkingData()
  135. // self.initLocalization()
  136. // self.initializeUI()
  137. self.initializeUI_DMG()
  138. self.setup()
  139. // refreshUI()
  140. self.updateUI()
  141. self.changeEffectiveAppearance()
  142. NotificationCenter.default.addObserver(self, selector: #selector(homeFileRectChange(_:)), name: Notification.Name("KMHomeFileRectChange"), object: nil)
  143. NotificationCenter.default.addObserver(self, selector: #selector(changeEffectiveAppearance), name: NSNotification.Name(rawValue: "kEffectiveAppearance"), object: nil)
  144. // setAppearance(isDarkMode: KMAdvertisementConfig.isDarkModel())
  145. // NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name(NSApplication.didUpdateNotification.rawValue), object: nil)
  146. // NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name(NSWindow.didBecomeMainNotification.rawValue), object: nil)
  147. // NotificationCenter.default.addObserver(self, selector: #selector(appearanceChanged), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  148. NotificationCenter.default.addObserver(self, selector: #selector(openNewWindowAlertV), name: Notification.Name("KMCTTableChangeShowAlertView"), object: nil)
  149. #if VERSION_DMG
  150. NotificationCenter.default.addObserver(self, selector: #selector(deviceVerifyFinishNotification), name: Notification.Name.init(NSNotification.Name.deviceVerifyFinish.rawValue), object: nil)
  151. #endif
  152. NotificationCenter.default.addObserver(self, selector: #selector(importFromCamera), name: Notification.Name("kDeviceCameraMenuItemNotification"), object: nil)
  153. NotificationCenter.default.addObserver(self, selector: #selector(importFromScanner), name: Notification.Name("kDeviceScannerMenuItemNotification"), object: nil)
  154. self.loadFunctionGuide()
  155. }
  156. override func viewDidAppear() {
  157. super.viewDidAppear()
  158. refreshScrollView()
  159. }
  160. override func viewDidLayout() {
  161. super.viewDidLayout()
  162. refreshScrollView()
  163. // self.loadAITipIconGuide()
  164. }
  165. func initNetworkingData() {
  166. KMAdvertisementManager.manager.fetchDataWithResponseObject { [weak self] data, responseObject, error in
  167. KMPrint("获取广告数据成功")
  168. if data != nil {
  169. let showMenu = (data?.remoteControl?.showMenuHelpInfo ?? "") == "1"
  170. DispatchQueue.main.async {
  171. let mainMenu = NSApp.mainMenu?.item(at: 0)?.submenu
  172. if let item = mainMenu?.item(withTitle: NSLocalizedString("Volume Discount", comment: "")) {
  173. item.isHidden = !showMenu
  174. }
  175. if let item = mainMenu?.item(withTitle: NSLocalizedString("One License for Mac and Windows", comment: "")) {
  176. item.isHidden = !showMenu
  177. }
  178. if let item = mainMenu?.item(withTitle: NSLocalizedString("Education Discount", comment: "")) {
  179. item.isHidden = !showMenu
  180. }
  181. }
  182. let content = data!.recommondContent
  183. let item = content?.recommondContentPDFPro
  184. var infos: [KMAdvertisementItemInfo] = []
  185. for info in item?.content ?? [] {
  186. if info.version == "recommondPDF-PDFtoOfficePack" {
  187. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false && IAPProductsManager.default().isAvailableAllFunction() {
  188. infos.append(info)
  189. }
  190. } else {
  191. infos.append(info)
  192. }
  193. }
  194. item?.content = infos
  195. self?.advertisementTableView.inputData = content
  196. self?.advertisementTableView.didSelect = { view, item in
  197. let string = KMAdvertisementModelTransition.transitionLanguage(langeuage: item.linkURL)
  198. if string.count != 0 {
  199. NSWorkspace.shared.open(URL.init(string: string)!)
  200. }
  201. }
  202. self?.advertisementShowView.inputData = data!.advertisement
  203. self?.advertisementShowView.didSelect = { view, item in
  204. let string = KMAdvertisementModelTransition.transitionLanguage(langeuage: item.linkURL)
  205. if string.count != 0 {
  206. NSWorkspace.shared.open(URL.init(string: string)!)
  207. }
  208. guard let firebaseInfo = item.firebase else {
  209. return
  210. }
  211. KMAdvertisementModelTransition.sendFireBaseEvent(firebase: firebaseInfo)
  212. }
  213. if let item = data?.StoreUserRecovery?.content?.first {
  214. let url = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: item.image, highlight: false))
  215. KMAdvertisementImage.imageWithURL(url: url) { image in
  216. // 预加载
  217. }
  218. let saleUrl = URL(string: KMAdvertisementModelTransition.transitionImagePath(image: item.saleImage, highlight: false))
  219. KMAdvertisementImage.imageWithURL(url: saleUrl) { image in
  220. // 预加载
  221. }
  222. }
  223. if KMAdvertisementManager.manager.infoDict.allKeys.count > 0 {
  224. if let adsInfo = KMAdvertisementManager.manager.infoDict["adsInfo"] {
  225. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["adsInfo"] as! NSDictionary
  226. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  227. let arrM = NSMutableArray.init()
  228. for dict in array {
  229. let adsInfo = KMAdsInfo.init()
  230. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  231. adsInfo.infoDict = mutableDictionary
  232. arrM.add(adsInfo)
  233. }
  234. KMAdsInfoManager.shareInstance.adsInfoArrM = arrM
  235. }
  236. if let couponInfo = KMAdvertisementManager.manager.infoDict["couponContent"] {
  237. let infoDict: NSDictionary = KMAdvertisementManager.manager.infoDict["couponContent"] as! NSDictionary
  238. let array: [[String: Any]] = infoDict["content"] as! [[String : Any]]
  239. if array.isEmpty == false {
  240. let dict = array[0]
  241. let adsInfo = KMCouponInfo.init()
  242. let mutableDictionary = NSMutableDictionary(dictionary: dict)
  243. adsInfo.infoDict = mutableDictionary
  244. KMAdsInfoManager.shareInstance.couponInfo = adsInfo
  245. }
  246. }
  247. self?.checkTrialEndCouponInfo()
  248. }
  249. }
  250. }
  251. }
  252. func setup() {
  253. //creatPDF
  254. self.creatPDFView.openPDFAction = { [unowned self] view, sender in
  255. self.openPDFAction(sender)
  256. }
  257. self.creatPDFView.creatPDFAction = { [unowned self] view, sender in
  258. self.creatPDFAction(sender)
  259. }
  260. //history
  261. self.homeContentView.historyDidSelect = { [unowned self] view, item in
  262. self.openHistoryFilePath(url: item.url!)
  263. }
  264. self.homeContentView.historyRemoveFileAction = { [unowned self] view, item in
  265. self.historyFile(deleteDocuments: [ item.url!])
  266. }
  267. self.homeContentView.historyShowPathAction = { [unowned self] view, item in
  268. if FileManager.default.fileExists(atPath: item.url!.path) {
  269. NSWorkspace.shared.activateFileViewerSelecting([item.url!])
  270. }
  271. }
  272. self.homeContentView.historyRemoveAllFileAction = { [unowned self] view in
  273. let alert = NSAlert()
  274. alert.alertStyle = .critical
  275. alert.messageText = String(format: "%@?", NSLocalizedString("Clear All Recents", comment: ""))
  276. alert.addButton(withTitle: NSLocalizedString("Delete", comment: ""))
  277. alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
  278. alert.beginSheetModal(for: self.view.window!) { response in
  279. if response == .alertFirstButtonReturn {
  280. let urls: Array<URL> = NSDocumentController.shared.recentDocumentURLs
  281. self.historyFileDeleteAction(urls)
  282. }
  283. }
  284. }
  285. //quciktools
  286. self.homeContentView.qucikToolsDidSelect = { [unowned self] view, item in
  287. self.fastToolItemAction(item.type!)
  288. }
  289. self.homeContentView.qucikToolsAddAction = { [unowned self] view, item in
  290. KMBatchQuickActionManager.defaultManager.actionType = .add
  291. self.fastToolItemAction(item.type!)
  292. }
  293. self.homeContentView.qucikToolsRemoveAction = { [unowned self] view, item in
  294. KMBatchQuickActionManager.defaultManager.actionType = .remove
  295. self.fastToolItemAction(item.type!)
  296. }
  297. if IAPProductsManager.default().isAvailableAllFunction() {
  298. self.advertisementShowView.isHidden = true
  299. } else {
  300. self.advertisementShowView.isHidden = false
  301. }
  302. NotificationCenter.default.addObserver(self, selector: #selector(purchaseStateUpdateNoti), name: NSNotification.Name(rawValue: "KMIAPProductPurchasedNotification"), object: nil)
  303. NotificationCenter.default.addObserver(self, selector: #selector(purchaseStateUpdateNoti), name: NSNotification.Name(rawValue: "kDeviceActivateNotification"), object: nil)
  304. }
  305. // MARK: Init
  306. func initializeUI() {
  307. rightTopBox.fillColor = .white
  308. rightBottomBox.fillColor = .white
  309. rightFullBox.fillColor = .white
  310. self.refreshRightBoxUI(.Home)
  311. fastToolViewController.delete = self
  312. historyFileViewController.delete = self
  313. pdfToolsViewController.delete = self
  314. dragView.delete = self
  315. }
  316. func initLocalization() {
  317. // self.favoriteDocumentsLabel.stringValue = NSLocalizedString("Favorite Documents", comment: "")
  318. homeButtonVC?.stringValue = NSLocalizedString("Home", comment: "")
  319. pdfToolsButtonVC?.stringValue = NSLocalizedString("PDF Tools", comment: "")
  320. cloudDocumentsButtonVC?.stringValue = NSLocalizedString("Cloud Documents", comment: "")
  321. openPDFButtonVC?.stringValue = NSLocalizedString("Open File", comment: "")
  322. // openPDFBox.toolTip = NSLocalizedString("Open PDF", comment: "")
  323. createPDFButtonVC?.stringValue = NSLocalizedString("Create PDF", comment: "")
  324. // createPDFBox.toolTip = NSLocalizedString("Create PDF", comment: "")
  325. pdfSeriesButtonVC?.stringValue = NSLocalizedString("PDF Pro Series", comment: "")
  326. pdfOthersButtonVC?.stringValue = NSLocalizedString("Others", comment: "")
  327. }
  328. // MARK: Action
  329. func initializeUI_DMG() -> Void {
  330. rightTopBox.fillColor = .white
  331. rightBottomBox.fillColor = .white
  332. rightFullBox.fillColor = .white
  333. self.aiHomeBox.fillColor = .clear
  334. self.aiHomeBox.cornerRadius = 8.0
  335. self.aiHomeImageView.image = NSImage(named: "icon_home")
  336. self.aiHomeLabel.stringValue = NSLocalizedString("Home", comment: "")
  337. self.aiHomeLabel.textColor = NSColor.km_init(hex: "#252629")
  338. self.aiHomeLabel.font = NSFont.SFProTextRegularFont(16.0)
  339. self.aiHomeBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  340. if aiHomeState != .Home {
  341. if mouseEntered {
  342. self.aiHomeBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
  343. } else {
  344. self.aiHomeBox.fillColor = .clear
  345. }
  346. }
  347. }
  348. self.aiHomeBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  349. if aiHomeState != .Home {
  350. if downEntered {
  351. self.aiHomeState = .Home
  352. self.refreshAIUI()
  353. }
  354. }
  355. }
  356. self.aiTranslationBox.fillColor = .clear
  357. self.aiTranslationBox.cornerRadius = 8.0
  358. self.aiTranslationImageView.image = NSImage(named: "ic_function_other")
  359. self.aiTranslationLabel.stringValue = NSLocalizedString("AI Translation", comment: "")
  360. self.aiTranslationLabel.textColor = NSColor.km_init(hex: "#252629")
  361. self.aiTranslationLabel.font = NSFont.SFProTextRegularFont(16.0)
  362. self.aiTranslationBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  363. if aiHomeState != .AITranslation {
  364. if mouseEntered {
  365. self.aiTranslationBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
  366. } else {
  367. self.aiTranslationBox.fillColor = .clear
  368. }
  369. }
  370. }
  371. self.aiTranslationBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  372. if aiHomeState != .AITranslation {
  373. if downEntered {
  374. self.aiHomeState = .AITranslation
  375. self.trackEvent_ai(eventName: "AI Translation")
  376. self.refreshAIUI()
  377. }
  378. }
  379. }
  380. self.aiRewritingBox.fillColor = .clear
  381. self.aiRewritingBox.cornerRadius = 8.0
  382. self.aiRewritingImageView.image = NSImage(named: "ic_ai_Rewriting")
  383. self.aiRewritingLabel.stringValue = NSLocalizedString("AI Rewriting", comment: "")
  384. self.aiRewritingLabel.textColor = NSColor.km_init(hex: "#252629")
  385. self.aiRewritingLabel.font = NSFont.SFProTextRegularFont(16.0)
  386. self.aiRewritingBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  387. if aiHomeState != .AIRewriting {
  388. if mouseEntered {
  389. self.aiRewritingBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
  390. } else {
  391. self.aiRewritingBox.fillColor = .clear
  392. }
  393. }
  394. }
  395. self.aiRewritingBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  396. if aiHomeState != .AIRewriting {
  397. if downEntered {
  398. self.aiHomeState = .AIRewriting
  399. self.trackEvent_ai(eventName: "AI Rewriting")
  400. self.refreshAIUI()
  401. }
  402. }
  403. }
  404. self.aiErrorCorrectionBox.fillColor = .clear
  405. self.aiErrorCorrectionBox.cornerRadius = 8.0
  406. self.aiErrorCorrectionImageView.image = NSImage(named: "ic_ai_ErrorCorrection")
  407. self.aiErrorCorrectionLabel.stringValue = NSLocalizedString("AI Error Correction", comment: "")
  408. self.aiErrorCorrectionLabel.textColor = NSColor.km_init(hex: "#252629")
  409. self.aiErrorCorrectionLabel.font = NSFont.SFProTextRegularFont(16.0)
  410. self.aiErrorCorrectionBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  411. if aiHomeState != .AIErrorCorrection {
  412. if mouseEntered {
  413. self.aiErrorCorrectionBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
  414. } else {
  415. self.aiErrorCorrectionBox.fillColor = .clear
  416. }
  417. }
  418. }
  419. self.aiErrorCorrectionBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
  420. if aiHomeState != .AIErrorCorrection {
  421. if downEntered {
  422. self.aiHomeState = .AIErrorCorrection
  423. self.trackEvent_ai(eventName: "AI Correction")
  424. self.refreshAIUI()
  425. }
  426. }
  427. }
  428. self.refreshAIUI()
  429. historyFileViewController.delete = self
  430. dragView.delete = self
  431. }
  432. func updateUI() {
  433. self.leftBox.fillColor = KMAppearance.Layout.l0Color()
  434. // self.homeSplitView.backgroundColor(KMAppearance.Layout.l0Color())
  435. }
  436. @objc func changeEffectiveAppearance() {
  437. let isDarkModel = KMAdvertisementConfig.isDarkModel()
  438. if isDarkModel {
  439. self.view.appearance = NSAppearance(named: .darkAqua)
  440. } else {
  441. self.view.appearance = NSAppearance(named: .aqua)
  442. }
  443. self.updateUI()
  444. self.advertisementTableView.reloadData()
  445. }
  446. // MARK: Public Methods
  447. func savePDFDocument(_ pdf: CPDFDocument, password: String) -> Void {
  448. DispatchQueue.global(qos: .`default`).async {
  449. var isSuccessfully = false
  450. if pdf.isEncrypted {
  451. let dic = [
  452. CPDFDocumentWriteOption.userPasswordOption : password,
  453. CPDFDocumentWriteOption.ownerPasswordOption : password
  454. ]
  455. isSuccessfully = pdf.write(to: pdf.documentURL, withOptions: dic)
  456. } else {
  457. isSuccessfully = pdf.write(to: pdf.documentURL)
  458. }
  459. if !isSuccessfully {
  460. if let data = pdf.dataRepresentation() {
  461. isSuccessfully = NSData(data: data).write(to: pdf.documentURL, atomically: true)
  462. }
  463. }
  464. DispatchQueue.main.sync {
  465. if isSuccessfully {
  466. let workspace = NSWorkspace.shared
  467. let url = URL(fileURLWithPath: pdf.documentURL?.path ?? "")
  468. workspace.activateFileViewerSelecting([url])
  469. } else {
  470. let alert = NSAlert()
  471. alert.alertStyle = .critical
  472. alert.messageText = NSLocalizedString("Failed to insert page(s)!", comment: "")
  473. alert.runModal()
  474. }
  475. }
  476. }
  477. }
  478. // MARK: Private Methods
  479. func refreshUI() -> Void {
  480. homeButtonVC?.updateUI()
  481. pdfToolsButtonVC?.updateUI()
  482. cloudDocumentsButtonVC?.updateUI()
  483. }
  484. func refreshAIUI() -> Void {
  485. self.aiHomeBox.fillColor = .clear
  486. self.aiHomeLabel.font = NSFont.SFProTextRegularFont(16.0)
  487. self.aiTranslationBox.fillColor = .clear
  488. self.aiTranslationLabel.font = NSFont.SFProTextRegularFont(16.0)
  489. self.aiRewritingBox.fillColor = .clear
  490. self.aiRewritingLabel.font = NSFont.SFProTextRegularFont(16.0)
  491. self.aiErrorCorrectionBox.fillColor = .clear
  492. self.aiErrorCorrectionLabel.font = NSFont.SFProTextRegularFont(16.0)
  493. rightFullBox.isHidden = true
  494. rightTopBox.isHidden = true
  495. rightBottomBox.isHidden = true
  496. switch self.aiHomeState {
  497. case .Home:
  498. self.aiHomeBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
  499. self.aiHomeLabel.font = NSFont.SFProTextSemiboldFont(16.0)
  500. self.rightTopBox.isHidden = false
  501. self.rightBottomBox.isHidden = false
  502. self.rightTopBox.contentView = self.aiOpenPDFFilesViewController.view
  503. self.rightBottomBox.contentView = self.historyFileViewController.view
  504. self.rightFullBox.contentView = nil
  505. self.rightTopBoxHeightConstraint.constant = 388.0
  506. self.dragView.isHidden = false
  507. break
  508. case .AITranslation:
  509. self.aiTranslationBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
  510. self.aiTranslationLabel.textColor = NSColor.km_init(hex: "#252629")
  511. self.aiTranslationLabel.font = NSFont.SFProTextSemiboldFont(16.0)
  512. self.rightFullBox.isHidden = false
  513. self.rightTopBox.contentView = nil
  514. self.rightBottomBox.contentView = nil
  515. self.rightFullBox.contentView = self.aiTranslationViewController.view
  516. self.dragView.isHidden = false
  517. break
  518. case .AIRewriting:
  519. self.aiRewritingBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
  520. self.aiRewritingLabel.textColor = NSColor.km_init(hex: "#252629")
  521. self.aiRewritingLabel.font = NSFont.SFProTextSemiboldFont(16.0)
  522. self.rightFullBox.isHidden = false
  523. self.rightTopBox.contentView = nil
  524. self.rightBottomBox.contentView = nil
  525. self.rightFullBox.contentView = self.aiRewritingViewController.view
  526. // self.aiRewritingViewController.state = .AIRewriting
  527. self.aiRewritingViewController.initLocalization()
  528. self.aiRewritingViewController.acquisition_uiState()
  529. self.dragView.isHidden = true
  530. break
  531. case .AIErrorCorrection:
  532. self.aiErrorCorrectionBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
  533. self.aiErrorCorrectionLabel.textColor = NSColor.km_init(hex: "#252629")
  534. self.aiErrorCorrectionLabel.font = NSFont.SFProTextSemiboldFont(16.0)
  535. self.rightFullBox.isHidden = false
  536. self.rightTopBox.contentView = nil
  537. self.rightBottomBox.contentView = nil
  538. self.rightFullBox.contentView = self.aiRewritingViewController.view
  539. // self.aiRewritingViewController.state = .AIErrorCorrection
  540. self.aiRewritingViewController.initLocalization()
  541. self.aiRewritingViewController.acquisition_uiState()
  542. self.dragView.isHidden = true
  543. break
  544. default:
  545. break
  546. }
  547. }
  548. func fetchDifferentFilePath(filePath: String) -> String {
  549. var resultFilePath = filePath
  550. var index: Int = 0
  551. while (FileManager.default.fileExists(atPath: resultFilePath)) {
  552. index += 1
  553. let path = NSString(string: filePath).deletingPathExtension + "(" + String(index) + ")"
  554. resultFilePath = NSString(string: path).appendingPathExtension(NSString(string: filePath).pathExtension)!
  555. }
  556. return resultFilePath;
  557. }
  558. func showProgressWindow() {
  559. let progress = SKProgressController()
  560. progress.window?.backgroundColor = NSColor.km_init(hex: "#36383B")
  561. progress.window?.contentView?.wantsLayer = true
  562. progress.window?.contentView?.layer?.backgroundColor = NSColor.km_init(hex: "#36383B").cgColor
  563. progress.progressField.textColor = NSColor.white
  564. progress.message = NSLocalizedString("Translating...", comment: "")
  565. progress.closeBlock = { [weak self] in
  566. }
  567. self.progressController = progress
  568. self.view.window?.beginSheet(progress.window!)
  569. }
  570. func hiddenProgressWindow() {
  571. DispatchQueue.main.async {
  572. self.progressController?.doubleValue = 100.0
  573. }
  574. self.stopTimer()
  575. if (self.progressController != nil) {
  576. self.view.window?.endSheet((self.progressController?.window)!)
  577. self.progressController = nil
  578. }
  579. }
  580. func isFileGreaterThan10MB(atPath filePath: String) -> Bool {
  581. let fileManager = FileManager.default
  582. do {
  583. let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
  584. if let fileSize = fileAttributes[.size] as? UInt64 {
  585. let megabyteSize = fileSize / (1024 * 1024)
  586. return megabyteSize >= 10
  587. }
  588. } catch {
  589. KMPrint("Error: \(error)")
  590. }
  591. return false
  592. }
  593. func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
  594. let url = URL(fileURLWithPath: filePath)
  595. guard let document = PDFDocument(url: url) else {
  596. return false
  597. }
  598. let pageCount = document.pageCount
  599. return pageCount > 30
  600. }
  601. @objc func timerTick() {
  602. timerCounter += 1.0
  603. self.progressController?.increment(by: 1.0)
  604. if timerCounter >= 95 {
  605. stopTimer()
  606. }
  607. }
  608. func stopTimer() {
  609. timer?.invalidate()
  610. timer = nil
  611. }
  612. // MARK: Common methods
  613. func workSpaceOpenUrl(_ url: NSString) {
  614. let httpUrl: NSURL = NSURL.init(string: url as String)!
  615. let tWorkSpace: NSWorkspace = NSWorkspace.shared
  616. if !tWorkSpace.open(httpUrl as URL) {
  617. tWorkSpace.open(httpUrl as URL)
  618. }
  619. }
  620. }
  621. //MARK: Open Creat PDF
  622. extension KMHomeViewController: NSPopoverDelegate {
  623. }
  624. extension KMHomeViewController {
  625. func openPDFAction(_ sender: KMBox) {
  626. if needShowTabbingHintWindow() {
  627. showTabbingHintWindow()
  628. return
  629. }
  630. let openPanel = NSOpenPanel()
  631. openPanel.allowedFileTypes = ["pdf", "PDF"]
  632. openPanel.allowsMultipleSelection = false
  633. openPanel.beginSheetModal(for: self.view.window!) { (result) in
  634. if result == NSApplication.ModalResponse.OK {
  635. let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
  636. if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
  637. self.reopenDocument(forPaths: openPanel.url!)
  638. }else {
  639. NSDocumentController.shared.km_safe_limit_openDocument(withContentsOf: openPanel.url!, display: true) { (document, documentWasAlreadyOpen, error) in
  640. }
  641. }
  642. }
  643. }
  644. }
  645. func needShowTabbingHintWindow() -> Bool {
  646. let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
  647. if controll?.browser?.tabCount() ?? 0 > 1 && !IAPProductsManager.default().isAvailableAllFunction() {
  648. return true
  649. }
  650. return false
  651. }
  652. func showTabbingHintWindow(){
  653. if !KMDataManager.default.isTabbingWin{
  654. KMDataManager.default.isTabbingWin = true
  655. let tabbingWin: KMTabbingHintWindowController = KMTabbingHintWindowController()
  656. tabbingWin.selectCallBack = { [weak self] continueOrNot in
  657. KMDataManager.default.isTabbingWin = false
  658. if continueOrNot {
  659. self?.reopenDocument(forPaths: nil)
  660. } else {
  661. }
  662. }
  663. self.km_beginSheet(windowC: tabbingWin)
  664. }
  665. }
  666. func creatPDFAction(_ sender: KMBox) {
  667. let popViewDataArr: [String] = [NSLocalizedString("New Blank Page", comment: ""),
  668. NSLocalizedString("New From Images", comment: ""),
  669. NSLocalizedString("New From Web Page", comment: ""),
  670. NSLocalizedString("Import From Camera", comment: ""),
  671. NSLocalizedString("Import From Scanner", comment: "")]
  672. let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(popViewDataArr)
  673. vc.background = KMAppearance.Layout.bgColor()
  674. vc.textColor = KMAppearance.Layout.h0Color()
  675. vc.enterFillColor = KMAppearance.Interactive.s0Color()
  676. let createFilePopover: NSPopover = NSPopover.init()
  677. createFilePopover.contentViewController = vc
  678. createFilePopover.delegate = self
  679. createFilePopover.animates = true
  680. createFilePopover.behavior = .semitransient
  681. createFilePopover.setValue(true, forKey: "shouldHideAnchor")
  682. createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 10, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .minY)
  683. vc.downCallback = { [unowned self] (downEntered: Bool, count: String) -> Void in
  684. if count == NSLocalizedString("New Blank Page", comment: "") {
  685. self.openBlankPage()
  686. } else if count == NSLocalizedString("Import From Camera", comment: "") {
  687. self.importFromCamera()
  688. } else if count == NSLocalizedString("Import From Scanner", comment: "") {
  689. self.importFromScanner()
  690. } else if count == NSLocalizedString("New From Web Page", comment: "") {
  691. self.importFromWebPage()
  692. } else if count == NSLocalizedString("New From Images", comment: "") {
  693. self.newFromImages()
  694. }
  695. createFilePopover.close()
  696. }
  697. }
  698. func openBlankPage() {
  699. // let fileName: NSString = String(format: "%@.pdf", NSLocalizedString("Untitled", comment: "")) as NSString
  700. // let savePath = fetchUniquePath(fileName.kUrlToPDFFolderPath() as String)
  701. // let filePath = savePath.deletingLastPathComponent
  702. // if FileManager.default.fileExists(atPath: filePath) == false {
  703. // try?FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: false)
  704. // }
  705. //
  706. // let pdfDocument = CPDFDocument()
  707. // pdfDocument?.insertPage(CGSize(width: 595, height: 842), at: 0)
  708. // pdfDocument?.write(to: URL(fileURLWithPath: savePath))
  709. // let controll: KMBrowserWindowController? = self.view.window?.windowController as? KMBrowserWindowController
  710. // if controll?.browser?.tabCount() ?? 0 > 1 && KMPreference.shared.openDocumentType == .newWindow{
  711. // self.reopenDocument(forPaths: URL(fileURLWithPath: savePath))
  712. // }else {
  713. // NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: savePath), display: true) { document, documentWasAlreadyOpen, error in
  714. // if error != nil {
  715. // NSApp.presentError(error!)
  716. // } else {
  717. // if document is KMMainDocument {
  718. // let newDocument = document
  719. // (newDocument as! KMMainDocument).isNewCreated = true
  720. // }
  721. // }
  722. // // self.homeContentView?.reloadData()
  723. // }
  724. // }
  725. NSApplication.newBlankDocument()
  726. }
  727. func importFromWebPage() {
  728. self.urlToPDFWindowController = KMURLToPDFWindowController.init(windowNibName: NSNib.Name("KMURLToPDFWindowController"))
  729. self.urlToPDFWindowController?.beginSheetModalForWindow(NSWindow.currentWindow(), completionHandler: { filePath in
  730. if FileManager.default.fileExists(atPath: filePath) {
  731. NSDocumentController.shared.openDocument(withContentsOf: URL(fileURLWithPath: filePath), display: true) { document, documentWasAlreadyOpen, error in
  732. if error != nil {
  733. NSApp.presentError(error!)
  734. } else {
  735. if document is KMMainDocument {
  736. (document as! KMMainDocument).isNewCreated = true
  737. }
  738. }
  739. // self.homeContentView.reloadData()
  740. }
  741. }
  742. })
  743. }
  744. func importFromScanner() {
  745. let vc = KMDeviceBrowserWindowController.shared
  746. vc.type = .scanner
  747. vc.importScannerFileCallback = { [weak self](url: NSURL) -> Void in
  748. self?.openFile(withFilePath: url as URL)
  749. }
  750. vc.showWindow(NSApp.mainWindow)
  751. }
  752. func importFromCamera() {
  753. let vc = KMDeviceBrowserWindowController.shared
  754. vc.type = .camera
  755. vc.importCameraFileCallback = { [weak self] (url: NSURL) -> Void in
  756. self?.openFile(withFilePath: url as URL)
  757. }
  758. vc.showWindow(NSApp.mainWindow)
  759. }
  760. func newFromImages() {
  761. fastTool_ImageToPDF()
  762. // let openPanel = NSOpenPanel()
  763. // openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
  764. // if IAPProductsManager.defaultManager().isAvailableAllFunction {
  765. // openPanel.allowsMultipleSelection = true
  766. // } else {
  767. // openPanel.allowsMultipleSelection = false
  768. // }
  769. // openPanel.message = NSLocalizedString("Select images to create a new document. To select multiple files press cmd ⌘ button on the keyboard and click on the target files one by one.", comment: "")
  770. // openPanel.beginSheetModal(for: NSApp.mainWindow!) { result in
  771. // if result == .OK {
  772. // DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
  773. // debugPrint("缺少图片转PDF")
  774. // let baseWindowController = KMBatchOperateBaseWindowController(windowNibName: "KMBatchOperateBaseWindowController")
  775. // var arr: [KMBatchOperateFile] = []
  776. // for url in openPanel.urls {
  777. // let file = KMBatchOperateFile(filePath: url.path, type: .createPDF)
  778. // arr.append(file)
  779. // }
  780. //
  781. // if #available(macOS 10.13, *) {
  782. // baseWindowController.window?.makeKeyAndOrderFront(nil)
  783. // } else {
  784. // baseWindowController.showWindow(nil)
  785. // }
  786. // baseWindowController.checkNeedPasswordSwitch(toOperateType: .createPDF, files: arr)
  787. // if #available(macOS 10.13, *) {
  788. // baseWindowController.release()
  789. // }
  790. // }
  791. // }
  792. // }
  793. }
  794. //MARK: Purchase
  795. @objc func purchaseStateUpdateNoti() {
  796. if IAPProductsManager.default().isAvailableAllFunction() {
  797. self.advertisementShowView.isHidden = true
  798. guard let content = self.advertisementTableView.inputData else {
  799. return // 如果 content 为 nil,提前退出
  800. }
  801. let item = content.recommondContentPDFPro
  802. var infos: [KMAdvertisementItemInfo] = []
  803. for info in item?.content ?? [] {
  804. if info.version == "recommondPDF-PDFtoOfficePack" {
  805. if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false && IAPProductsManager.default().isAvailableAllFunction() {
  806. infos.append(info)
  807. }
  808. } else {
  809. infos.append(info)
  810. }
  811. }
  812. item?.content = infos
  813. self.advertisementTableView.inputData = content
  814. }
  815. }
  816. //MARK: - AI
  817. func showAITypeChooseView() -> Void {
  818. let windowVC: AINewConfigWindowController = AINewConfigWindowController.currentWC()
  819. windowVC.chooseCurFileHandle = {[unowned self] windowVC in
  820. if AIChatInfoManager.defaultManager.currentFilePath.isEmpty == false {
  821. let documentArray = NSDocumentController.shared.documents
  822. var didFileEdit: Bool = false
  823. var curDoc: KMMainDocument!
  824. for document in documentArray {
  825. if document.fileURL?.path == AIChatInfoManager.defaultManager.currentFilePath {
  826. didFileEdit = document.isDocumentEdited
  827. curDoc = document as! KMMainDocument
  828. break
  829. }
  830. }
  831. if didFileEdit {
  832. let tempFileURL = FileManager.default.temporaryDirectory.appendingPathComponent(AIChatInfoManager.defaultManager.currentFilePath.lastPathComponent)
  833. if FileManager.default.fileExists(atPath: tempFileURL.path) {
  834. do {
  835. try FileManager.default.removeItem(at: tempFileURL)
  836. } catch {
  837. }
  838. }
  839. if curDoc != nil {
  840. curDoc.mainViewController?.SaveTempPDFDocumentToURLPath(tempPath: tempFileURL.path)
  841. }
  842. }
  843. windowVC.window?.becomeMain()
  844. }
  845. }
  846. if windowVC.window?.isVisible == true && windowVC.didSetOriginFrame == true {
  847. } else {
  848. windowVC.window?.center()
  849. windowVC.didSetOriginFrame = true
  850. }
  851. windowVC.eventLabel = "AITools_Onboard"
  852. windowVC.showWindow(nil)
  853. }
  854. func loadAITipIconGuide() {
  855. if KMGuideInfoWindowController.availableShow(.aiTipIconInfo) {
  856. let guideWC = KMGuideInfoWindowController.currentWC()
  857. guideWC.type = .aiTipIconInfo
  858. guideWC.window?.collectionBehavior = [.canJoinAllSpaces]
  859. guideWC.finishHandle = { [weak self] windowVC, type in
  860. }
  861. if self.view.window != nil {
  862. var rect = self.view.window?.frame
  863. rect!.size.height -= 20
  864. guideWC.window?.setFrame(rect!, display: true)
  865. guideWC.window?.minSize = rect!.size
  866. guideWC.window?.maxSize = rect!.size
  867. self.view.window?.addChildWindow(guideWC.window!, ordered: .above)
  868. guideWC.show()
  869. }
  870. }
  871. }
  872. //MARK: - 引导
  873. func loadFunctionGuide() -> Void {
  874. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) {
  875. self.loadNewUserGuide()
  876. }
  877. }
  878. // MARK: - what's New
  879. func loadNewUserGuide() -> Void {
  880. if KMFunctionGuideWindowController.availableShow(.functionMultiAIGuide) {
  881. guideWindowVC = KMFunctionGuideWindowController.init(windowNibName: "KMFunctionGuideWindowController")
  882. guideWindowVC.type = .functionMulti
  883. guideWindowVC.showWindow(nil)
  884. guideWindowVC.window?.orderFront(nil)
  885. KMFunctionGuideWindowController.setDidShowFor(.functionMultiAIGuide)
  886. }
  887. }
  888. func checkRepeatTrialExpiredController() -> Void {
  889. //试用过期提示比较表弹窗
  890. if didTrialExpiredLoad == true {
  891. return
  892. }
  893. didTrialExpiredLoad = true
  894. let singleTon = KMPurchaseCompareDMGWindowController.init()
  895. singleTon.showWindow(nil)
  896. if singleTon.className == KMPurchaseCompareDMGWindowController.className() {
  897. singleTon.updateTitle(NSLocalizedString("Trial Expired, Upgrade to Pro Version", comment: ""), andColor: NSColor(red: 1, green: 59/255, blue: 47/255, alpha: 1))
  898. }
  899. }
  900. func checkRepeatTrialAlertController() -> Void {
  901. //允许二次试用时弹出二次试用引导弹窗
  902. if repeatTrialAlertLoad == true {
  903. return
  904. }
  905. repeatTrialAlertLoad = true
  906. let vc = KMVerificationWindowController.verification(with:.repeatTrialGuide)
  907. vc?.showWindow(nil)
  908. }
  909. //MARK: 试用到期优惠券弹窗
  910. func checkTrialEndCouponInfo() {
  911. #if VERSION_DMG
  912. KMRequestServerManager.manager.getDeviceRetensionCoupon {[weak self] success, result in
  913. if success == true {
  914. if result != nil {
  915. guard let dataDict = result!["data"] as? NSDictionary else {
  916. return
  917. }
  918. // if dataDict!["pop_up"] as? Bool == true {
  919. let discount = dataDict["discount"] as? Int
  920. let coupon_code = dataDict["coupon_code"] as? String
  921. let end_up_at = dataDict["end_up_at"] as? String
  922. let pop_up = dataDict["pop_up"] as? Bool
  923. if pop_up == true {
  924. if let versionKey = KMAdsInfoManager.shareInstance.couponInfo?.versionKey {
  925. if KMAdsInfoManager.shareInstance.couponInfo?.show == true {
  926. if (UserDefaults.standard.object(forKey: versionKey) != nil) {
  927. } else {
  928. UserDefaults.standard.set("Show", forKey: versionKey)
  929. UserDefaults.standard.synchronize()
  930. self?.showCouponInfoWindow(discount: discount, couponCode: coupon_code, endUpAt: end_up_at)
  931. }
  932. }
  933. }
  934. }
  935. }
  936. } else {
  937. if KMVerificationWindowController.allowsShowExpired() {
  938. self?.checkRepeatTrialExpiredController()
  939. } else if KMVerificationWindowController.allowRepeatTrialAlertShow() {
  940. self?.checkRepeatTrialAlertController()
  941. }
  942. }
  943. }
  944. #endif
  945. }
  946. func showCouponInfoWindow(discount: Int?, couponCode: String?, endUpAt: String?) {
  947. if self.couponDueWindowVC == nil {
  948. self.couponDueWindowVC = KMCouponDueWindowController(windowNibName: "KMCouponDueWindowController")
  949. }
  950. self.couponDueWindowVC.disCount = discount ?? 20
  951. self.couponDueWindowVC.couponCode = couponCode ?? ""
  952. self.couponDueWindowVC.endUpAt = endUpAt ?? ""
  953. self.couponDueWindowVC.showWindow(nil)
  954. self.couponDueWindowVC.reloadData()
  955. }
  956. // MARK: - Noti Actions
  957. func deviceVerifyFinishNotification(_ sender: Notification) {
  958. #if VERSION_DMG
  959. #endif
  960. }
  961. @objc func aiTipIconViewShowStateChangeNoti() {
  962. }
  963. }