KMHomeViewController.swift 48 KB

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