KMHomeViewController.swift 46 KB

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