123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730 |
- //
- // KMHomeViewController.swift
- // PDF Master
- //
- // Created by wanjun on 2022/10/13.
- //
- import Cocoa
- import KMAdvertisement
- @objc enum KMHomeToolState : Int {
- case OpenPDF = 0
- case CreatePDF
- case Home
- case PDFTools
- case FavoriteDocuments
- case CloudDocuments
- }
- @objc enum KMAIHomeToolState : Int {
- case Home = 0
- case AITranslation
- case AIRewriting
- case AIErrorCorrection
- }
- @objcMembers class KMHomeViewController: NSViewController {
- @IBOutlet weak var leftBox: NSBox!
- @IBOutlet weak var rightBox: NSBox!
- @IBOutlet weak var homeSplitView: NSSplitView!
- @IBOutlet weak var homeRightScrollViewView: NSScrollView!
-
- @IBOutlet weak var openPDFBox: NSBox! // Open PDF
- @IBOutlet weak var openPDFBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var createPDFBox: NSBox! // Create PDF
- @IBOutlet weak var createPDFView: NSBox! // Create PDF
- @IBOutlet weak var createPDFBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var createPDFViewHeight: NSLayoutConstraint!
- @IBOutlet weak var homeBox: NSBox! // Home
- @IBOutlet weak var homeBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var pdfToolsBox: NSBox! // PDF Tools
- @IBOutlet weak var pdfToolsBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var favoriteDocumentsBox: KMBox! // Favorite Documents
- @IBOutlet weak var favoriteDocumentsLabel: NSTextField!
- @IBOutlet weak var favoriteDocumentsImageView: NSImageView!
- @IBOutlet weak var cloudDocumentsBox: NSBox! // Cloud Documents
- @IBOutlet weak var cloudDocumentsBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var productPromotionBox: KMBox! // 产品推广
- @IBOutlet weak var pdfSeriesBox: NSBox!
- @IBOutlet weak var pdfSeriesBoxHeight: NSLayoutConstraint!
- @IBOutlet weak var pdfProSeriesBox: NSBox!
- @IBOutlet weak var pdfProSeriesBoxHeightConstraint: NSLayoutConstraint!
- @IBOutlet weak var pdfOthersBox: NSBox!
- @IBOutlet weak var pdfOthersBoxHeightConstraint: NSLayoutConstraint!
- @IBOutlet weak var othersBox: NSBox!
- @IBOutlet weak var othersBoxHeightConstraint: NSLayoutConstraint!
- @IBOutlet weak var activitiesBox: KMBox! // 活动
- @IBOutlet weak var product_active_box: NSBox!
- @IBOutlet weak var product_active_scrollView: NSScrollView!
-
- @IBOutlet weak var product_active_spacing: NSLayoutConstraint!
- @IBOutlet weak var rightTopBox: NSBox!
- @IBOutlet weak var rightBottomBox: NSBox!
- @IBOutlet weak var rightFullBox: NSBox!
- @IBOutlet weak var rightTopBoxHeightConstraint: NSLayoutConstraint!
-
- @IBOutlet var fastToolViewController: KMHomeFastToolViewController!
- @IBOutlet var historyFileViewController: KMHomeHistoryFileViewController!
- @IBOutlet var pdfToolsViewController: KMPDFToolsViewController!
- @IBOutlet var cloudDocumentsViewController: KMCloudDocumentsViewController!
-
- @IBOutlet weak var dragView: KMHomeDragView!
-
- // AI 临时UI
- @IBOutlet weak var aiHomeBox: KMBox!
- @IBOutlet weak var aiHomeImageView: NSImageView!
- @IBOutlet weak var aiHomeLabel: NSTextField!
- @IBOutlet weak var aiTranslationBox: KMBox!
- @IBOutlet weak var aiTranslationImageView: NSImageView!
- @IBOutlet weak var aiTranslationLabel: NSTextField!
- @IBOutlet weak var aiRewritingBox: KMBox!
- @IBOutlet weak var aiRewritingImageView: NSImageView!
- @IBOutlet weak var aiRewritingLabel: NSTextField!
- @IBOutlet weak var aiErrorCorrectionBox: KMBox!
- @IBOutlet weak var aiErrorCorrectionImageView: NSImageView!
- @IBOutlet weak var aiErrorCorrectionLabel: NSTextField!
- @IBOutlet var aiOpenPDFFilesViewController: KMAIOpenPDFFilesVC!
- @IBOutlet var aiTranslationViewController: KMAITranslationVC!
- @IBOutlet var aiRewritingViewController: KMAIRewritingVC!
-
- var aiHomeState: KMAIHomeToolState = .Home
-
- let ScrollerViewWidget: CGFloat = 15.0
-
- var homeWindowController : MainWindowController!
-
- // 产品推广数据
- var productPromotionPDFProSeries: NSArray!
- var productPromotionOthers: NSArray!
- var productPromotionData: NSDictionary!
-
- var isShowQuickTour: Bool = false
- var myDocument: NSDocument?
- var currentWindowController: NSWindowController?
- var homeState: KMHomeToolState = .Home
-
- var urlToPDFWindowController: KMURLToPDFWindowController?
-
- var openPDFButtonVC: KMDesignButton!
- var createPDFButtonVC: KMDesignButton!
- var createPDFImage: KMDesignButton!
- var createPDFAddButtonVC: KMDesignButton!
- var homeButtonVC: KMTextImageButtonVC!
- var pdfToolsButtonVC: KMTextImageButtonVC!
- var cloudDocumentsButtonVC: KMTextImageButtonVC!
- var pdfSeriesButtonVC: KMTextImageButtonVC!
- var pdfOthersButtonVC: KMTextImageButtonVC!
- var popover: NSPopover?
- var deviceBrowserWC: KMDeviceBrowserWindowController?
- var progressController: SKProgressController?
- var timer: Timer?
- var timerCounter = 0.0
-
- @IBOutlet weak var rightBottonHeight: NSLayoutConstraint!
-
- deinit {
-
- }
-
- override func viewWillAppear() {
- super.viewWillAppear()
- if !KMLightMemberManager.manager.isLogin() {
- KMLightMemberManager.manager.canShowAdvancedView = true
- }
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- openPDFButtonVC = KMDesignButton.init(withType: .Text)
- createPDFButtonVC = KMDesignButton.init(withType: .Text)
- createPDFImage = KMDesignButton.init(withType: .Image)
- createPDFAddButtonVC = KMDesignButton.init(withType: .Image)
- homeButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
- pdfToolsButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
- cloudDocumentsButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
- pdfSeriesButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
- pdfOthersButtonVC = KMTextImageButtonVC.init(nibName: "KMTextImageButtonVC", bundle: nil)
- self.homeSplitView.setPosition(270.0, ofDividerAt: 0)
- self.leftBox.fillColor = NSColor.km_init(hex: "#F7F8FA")
-
- self.productPromotionPDFProSeries = ["Windows", "iPhone / iPad", "Android"]
- self.productPromotionOthers = ["ComPDFKit", "SignFlow", "FiImage Editor", "FiImage Screen", "Free PDF Templates"]
- self.productPromotionData = ["Windows": ["Name" : "Windows", "Image" : "icon_home_logo_windows", "link":""],
- "iPhone / iPad" : ["Name" : "iPhone / iPad", "Image" : "icon_home_logo_mac", "link":""],
- "Android" : ["Name" : "Android", "Image" : "icon_home_logo_android", "link":""],
- "ComPDFKit" : ["Name" : "ComPDFKit", "Image" : "icon_home_logo_comPDFKit", "link":""],
- "SignFlow" : ["Name" : "SignFlow", "Image" : "icon_home_logo_signflow", "link":""],
- "FiImage Editor" : ["Name" : "FiImage Editor", "Image" : "icon_home_logo_editor", "link":""],
- "FiImage Screen" : ["Name" : "FiImage Screen", "Image" : "icon_home_logo_screen", "link":""],
- "Free PDF Templates" : ["Name" : "Free PDF Templates", "Image" : "icon_home_logo_templates"], "link":""]
- NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { (aEvent) -> NSEvent? in
- self.otherMouseDown(with: aEvent)
- return aEvent
- }
- // self.initNetworkingData()
- // self.initLocalization()
- // self.initializeUI()
- self.initializeUI_DMG()
-
- // refreshUI()
-
- NotificationCenter.default.addObserver(self, selector: #selector(homeFileRectChange(_:)), name: Notification.Name("KMHomeFileRectChange"), object: nil)
- }
-
- override func viewDidAppear() {
- super.viewDidAppear()
- refreshScrollView()
- }
-
- override func viewDidLayout() {
- super.viewDidLayout()
-
- refreshScrollView()
- }
-
- func initNetworkingData() {
- KMAdvertisementManager.manager.fetchDataWithResponseObject { [unowned self] data, responseObject, error in
- KMPrint("获取广告数据成功")
- if data != nil {
- for model in data! {
- guard let sectionContent = model.content else { break }
- if model.showType == .list {
- for section in sectionContent {
- KMPrint("list section 标题" + KMAdvertisementModelTransition.transitionLanguage(langeuage: section.sectionTitle?.language))
- guard let itemContent = section.content else { break }
-
- for item in itemContent {
- KMPrint("item 标题" + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.title?.language))
- KMPrint("item 图片链接" + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.imageURL?.normal?.universal))
- KMPrint("item 点击链接" + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.linkURL))
- KMPrint("item tips" + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.tips))
- KMPrint("item actionType" + String(Int(item.actionType.rawValue)))
- }
- }
- }
- if model.showType == .view {
- for section in sectionContent {
- KMPrint("view section 标题" + KMAdvertisementModelTransition.transitionLanguage(langeuage: section.sectionTitle?.language))
- guard let itemContent = section.content else { break }
-
- for item in itemContent {
- KMPrint("item 标题 = " + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.title?.language))
- KMPrint("item 图片链接 = " + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.imageURL?.normal?.universal))
- KMPrint("item 点击链接 = " + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.linkURL))
- KMPrint("item tips = " + KMAdvertisementModelTransition.transitionLanguage(langeuage: item.tips))
- KMPrint("item actionType = " + String(Int(item.actionType.rawValue)))
- }
- }
- }
- }
- }
- }
- }
-
- // MARK: Init
-
- func initializeUI() {
- openPDFBox.fillColor = .clear
- openPDFBox.contentView = openPDFButtonVC.view
- openPDFButtonVC.target = self
- openPDFButtonVC.action = #selector(self.homeToolAction(_:))
- openPDFButtonVC.button(type: .Brand, size: .l, height: openPDFBoxHeight)
- createPDFBox.fillColor = .clear
- createPDFBox.contentView = createPDFButtonVC.view
- createPDFButtonVC.target = self
- createPDFButtonVC.action = #selector(self.homeToolAction(_:))
- createPDFButtonVC.button(type: .Sec, size: .l, height: createPDFBoxHeight)
- createPDFButtonVC.textButtonBox.move = { [unowned self](mouseEntered: Bool) -> Void in
- if mouseEntered {
- if self.createPDFButtonVC.state != .Sel && self.createPDFButtonVC.canHover {
- self.createPDFButtonVC.state = .Hov
- self.createPDFButtonVC.updateUI()
- self.createPDFImage.state = .Hov
- self.createPDFImage.updateUI()
- self.createPDFImage.canHover = false
- }
- } else {
- if self.createPDFButtonVC.state != .Sel && self.createPDFButtonVC.canHover {
- self.createPDFButtonVC.state = .Norm
- self.createPDFButtonVC.updateUI()
- self.createPDFImage.state = .Norm
- self.createPDFImage.updateUI()
- self.createPDFImage.canHover = true
- }
- }
- }
-
- createPDFView.contentView = createPDFImage.view
- createPDFImage.image = NSImage(named: "icon_btn_arrow_gray_down_s_norm_false")!
- createPDFImage.target = self
- createPDFImage.action = #selector(self.homeToolAction(_:))
- createPDFImage.button(type: .Icon_Fill, size: .m, height: createPDFViewHeight)
- homeBox.fillColor = .clear
- homeBox.contentView = homeButtonVC.view
- homeButtonVC.target = self
- homeButtonVC.action = #selector(self.homeToolAction(_:))
- homeButtonVC.image = NSImage(named: "icon_home_sidebar_home_false")!
- homeButtonVC.image_hover = NSImage(named: "icon_home_sidebar_home_false")!
- homeButtonVC.image_click = NSImage(named: "icon_home_sidebar_home_true")!
- homeButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.norm", text: "navmenu.win-text.def", height: homeBoxHeight)
- homeButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.hov", text: "navmenu.win-text.def", state:.Hov)
- homeButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.sel", text: "navmenu.win-text.sel", state:.Sel)
- pdfToolsBox.fillColor = .clear
- pdfToolsBox.contentView = pdfToolsButtonVC.view
- pdfToolsButtonVC.target = self
- pdfToolsButtonVC.action = #selector(self.homeToolAction(_:))
- pdfToolsButtonVC.image = NSImage(named: "icon_home_sidebar_tool_false")!
- pdfToolsButtonVC.image_hover = NSImage(named: "icon_home_sidebar_tool_false")!
- pdfToolsButtonVC.image_click = NSImage(named: "icon_home_sidebar_tool_true")!
- pdfToolsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.norm", text: "navmenu.win-text.def", height: pdfToolsBoxHeight)
- pdfToolsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.hov", text: "navmenu.win-text.def", state:.Hov)
- pdfToolsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.sel", text: "navmenu.win-text.sel", state:.Sel)
-
- cloudDocumentsBox.fillColor = .clear
- cloudDocumentsBox.contentView = cloudDocumentsButtonVC.view
- cloudDocumentsButtonVC.target = self
- cloudDocumentsButtonVC.action = #selector(self.homeToolAction(_:))
- cloudDocumentsButtonVC.image = NSImage(named: "icon_home_sidebar_cloud_false")!
- cloudDocumentsButtonVC.image_hover = NSImage(named: "icon_home_sidebar_cloud_false")!
- cloudDocumentsButtonVC.image_click = NSImage(named: "icon_home_sidebar_cloud_true")!
- cloudDocumentsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.norm", text: "navmenu.win-text.def", height: cloudDocumentsBoxHeight)
- cloudDocumentsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.hov", text: "navmenu.win-text.def", state:.Hov)
- cloudDocumentsButtonVC.navMenu(bg: "navmenu.has-icon.m.bg.sel", text: "navmenu.win-text.sel", state:.Sel)
- pdfSeriesBox.fillColor = .clear
- pdfSeriesBox.contentView = pdfSeriesButtonVC.view
- pdfSeriesButtonVC.target = self
- pdfSeriesButtonVC.action = #selector(self.productPromotionFoldOrUnfold(_:))
- pdfSeriesButtonVC.type = .Right
- pdfSeriesButtonVC.canHover = false
- pdfSeriesButtonVC.imageWidth = 12.0
- pdfSeriesButtonVC.imageHeight = 12.0
- pdfSeriesButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
- pdfSeriesButtonVC.navMenu(bg: "collapse.ad-list.bg", text: "collapse.ad-list.mac-text.norm", height: pdfSeriesBoxHeight)
- pdfOthersBox.fillColor = .clear
- pdfOthersBox.contentView = pdfOthersButtonVC.view
- pdfOthersButtonVC.target = self
- pdfOthersButtonVC.action = #selector(self.productPromotionFoldOrUnfold(_:))
- pdfOthersButtonVC.type = .Right
- pdfOthersButtonVC.canHover = false
- pdfOthersButtonVC.imageWidth = 12.0
- pdfOthersButtonVC.imageHeight = 12.0
- pdfOthersButtonVC.image = NSImage(named: "icon_btn_expand_lv2_down_false")!
- pdfOthersButtonVC.navMenu(bg: "collapse.ad-list.bg", text: "collapse.ad-list.mac-text.norm", height: othersBoxHeightConstraint)
- // if self.activitiesBox.isHidden {
- // self.productPromotionShow(self.productPromotionPDFProSeries, withOthers: self.productPromotionOthers, isInitialize: true)
- // } else {
- // self.productPromotionShow(self.productPromotionPDFProSeries, withOthers: [], isInitialize: true)
- // }
- self.productPromotionShow(self.productPromotionPDFProSeries, withOthers: self.productPromotionOthers, isInitialize: true)
-
- self.activitiesBox.contentView = KMProductPromotionViewController.init().view
- activitiesBox.cornerRadius = 8.0
-
- rightTopBox.fillColor = .white
- rightBottomBox.fillColor = .white
- rightFullBox.fillColor = .white
-
- productPromotionBox.fillColor = .clear
-
- product_active_scrollView.verticalScrollElasticity = .none
-
- self.refreshRightBoxUI(.Home)
- fastToolViewController.delete = self
- historyFileViewController.delete = self
- pdfToolsViewController.delete = self
- dragView.delete = self
- }
-
- func initLocalization() {
- self.favoriteDocumentsLabel.stringValue = NSLocalizedString("Favorite Documents", comment: "")
-
- homeButtonVC.stringValue = NSLocalizedString("Home", comment: "")
- pdfToolsButtonVC.stringValue = NSLocalizedString("PDF Tools", comment: "")
- cloudDocumentsButtonVC.stringValue = NSLocalizedString("Cloud Documents", comment: "")
- openPDFButtonVC.stringValue = NSLocalizedString("Open File", comment: "")
- openPDFBox.toolTip = NSLocalizedString("Open PDF", comment: "")
- createPDFButtonVC.stringValue = NSLocalizedString("Create PDF", comment: "")
- createPDFBox.toolTip = NSLocalizedString("Create PDF", comment: "")
- pdfSeriesButtonVC.stringValue = NSLocalizedString("PDF Pro Series", comment: "")
- pdfOthersButtonVC.stringValue = NSLocalizedString("Others", comment: "")
- }
-
- // MARK: Action
- func initializeUI_DMG() -> Void {
- rightTopBox.fillColor = .white
- rightBottomBox.fillColor = .white
- rightFullBox.fillColor = .white
- self.aiHomeBox.fillColor = .clear
- self.aiHomeBox.cornerRadius = 8.0
- self.aiHomeImageView.image = NSImage(named: "icon_home")
- self.aiHomeLabel.stringValue = NSLocalizedString("Home", comment: "")
- self.aiHomeLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiHomeLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiHomeBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
- if aiHomeState != .Home {
- if mouseEntered {
- self.aiHomeBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
- } else {
- self.aiHomeBox.fillColor = .clear
- }
- }
- }
- self.aiHomeBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
- if aiHomeState != .Home {
- if downEntered {
- self.aiHomeState = .Home
-
- self.refreshAIUI()
- }
- }
- }
- self.aiTranslationBox.fillColor = .clear
- self.aiTranslationBox.cornerRadius = 8.0
- self.aiTranslationImageView.image = NSImage(named: "ic_function_other")
- self.aiTranslationLabel.stringValue = NSLocalizedString("AI Translation", comment: "")
- self.aiTranslationLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiTranslationLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiTranslationBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
- if aiHomeState != .AITranslation {
- if mouseEntered {
- self.aiTranslationBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
- } else {
- self.aiTranslationBox.fillColor = .clear
- }
- }
- }
- self.aiTranslationBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
- if aiHomeState != .AITranslation {
- if downEntered {
- self.aiHomeState = .AITranslation
-
- self.trackEvent_ai(eventName: "AI Translation")
-
- self.refreshAIUI()
- }
- }
- }
- self.aiRewritingBox.fillColor = .clear
- self.aiRewritingBox.cornerRadius = 8.0
- self.aiRewritingImageView.image = NSImage(named: "ic_ai_Rewriting")
- self.aiRewritingLabel.stringValue = NSLocalizedString("AI Rewriting", comment: "")
- self.aiRewritingLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiRewritingLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiRewritingBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
- if aiHomeState != .AIRewriting {
- if mouseEntered {
- self.aiRewritingBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
- } else {
- self.aiRewritingBox.fillColor = .clear
- }
- }
- }
- self.aiRewritingBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
- if aiHomeState != .AIRewriting {
- if downEntered {
- self.aiHomeState = .AIRewriting
-
- self.trackEvent_ai(eventName: "AI Rewriting")
-
- self.refreshAIUI()
- }
- }
- }
- self.aiErrorCorrectionBox.fillColor = .clear
- self.aiErrorCorrectionBox.cornerRadius = 8.0
- self.aiErrorCorrectionImageView.image = NSImage(named: "ic_ai_ErrorCorrection")
- self.aiErrorCorrectionLabel.stringValue = NSLocalizedString("AI Error Correction", comment: "")
- self.aiErrorCorrectionLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiErrorCorrectionLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiErrorCorrectionBox.moveCallback = { [unowned self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
- if aiHomeState != .AIErrorCorrection {
- if mouseEntered {
- self.aiErrorCorrectionBox.fillColor = NSColor.km_init(hex: "#EDEEF0")
- } else {
- self.aiErrorCorrectionBox.fillColor = .clear
- }
- }
- }
- self.aiErrorCorrectionBox.downCallback = { [unowned self](downEntered: Bool, mouseBox: KMBox, event) -> Void in
- if aiHomeState != .AIErrorCorrection {
- if downEntered {
- self.aiHomeState = .AIErrorCorrection
-
- self.trackEvent_ai(eventName: "AI Correction")
-
- self.refreshAIUI()
- }
- }
- }
-
- self.refreshAIUI()
-
- historyFileViewController.delete = self
- dragView.delete = self
- }
-
- // MARK: Action
-
- @IBAction func productPromotionButtonAction(_ sender: NSButton) {
- self.productPromotionFoldOrUnfold(sender)
- }
-
- // MARK: Public Methods
-
- func savePDFDocument(_ pdf: CPDFDocument, password: String) -> Void {
- DispatchQueue.global(qos: .`default`).async {
- var isSuccessfully = false
- if pdf.isEncrypted {
- let dic = [
- CPDFDocumentWriteOption.userPasswordOption : password,
- CPDFDocumentWriteOption.ownerPasswordOption : password
- ]
- isSuccessfully = pdf.write(to: pdf.documentURL, withOptions: dic)
- } else {
- isSuccessfully = pdf.write(to: pdf.documentURL)
- }
- if !isSuccessfully {
- isSuccessfully = NSData(data: pdf.dataRepresentation()).write(to: pdf.documentURL, atomically: true)
- }
-
- DispatchQueue.main.sync {
- if isSuccessfully {
- let workspace = NSWorkspace.shared
- let url = URL(fileURLWithPath: pdf.documentURL?.path ?? "")
- workspace.activateFileViewerSelecting([url])
- } else {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Failed to insert page(s)!", comment: "")
- alert.runModal()
- }
- }
- }
- }
-
- // MARK: Private Methods
- func refreshUI() -> Void {
- homeButtonVC.updateUI()
- pdfToolsButtonVC.updateUI()
- cloudDocumentsButtonVC.updateUI()
- }
-
- func refreshAIUI() -> Void {
- self.aiHomeBox.fillColor = .clear
- self.aiHomeLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiTranslationBox.fillColor = .clear
- self.aiTranslationLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiRewritingBox.fillColor = .clear
- self.aiRewritingLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.aiErrorCorrectionBox.fillColor = .clear
- self.aiErrorCorrectionLabel.font = NSFont.SFProTextRegularFont(16.0)
- rightFullBox.isHidden = true
- rightTopBox.isHidden = true
- rightBottomBox.isHidden = true
- switch self.aiHomeState {
- case .Home:
- self.aiHomeBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
- self.aiHomeLabel.font = NSFont.SFProTextSemiboldFont(16.0)
-
- self.rightTopBox.isHidden = false
- self.rightBottomBox.isHidden = false
- self.rightTopBox.contentView = self.aiOpenPDFFilesViewController.view
- self.rightBottomBox.contentView = self.historyFileViewController.view
- self.rightFullBox.contentView = nil
-
- self.rightTopBoxHeightConstraint.constant = 388.0
-
- self.dragView.isHidden = false
- break
- case .AITranslation:
- self.aiTranslationBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
- self.aiTranslationLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiTranslationLabel.font = NSFont.SFProTextSemiboldFont(16.0)
- self.rightFullBox.isHidden = false
- self.rightTopBox.contentView = nil
- self.rightBottomBox.contentView = nil
- self.rightFullBox.contentView = self.aiTranslationViewController.view
-
- self.dragView.isHidden = false
- break
- case .AIRewriting:
- self.aiRewritingBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
- self.aiRewritingLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiRewritingLabel.font = NSFont.SFProTextSemiboldFont(16.0)
- self.rightFullBox.isHidden = false
- self.rightTopBox.contentView = nil
- self.rightBottomBox.contentView = nil
- self.rightFullBox.contentView = self.aiRewritingViewController.view
- self.aiRewritingViewController.state = .AIRewriting
- self.aiRewritingViewController.initLocalization()
- self.aiRewritingViewController.acquisition_uiState()
-
- self.dragView.isHidden = true
- break
- case .AIErrorCorrection:
- self.aiErrorCorrectionBox.fillColor = NSColor.km_init(hex: "#1770F4", alpha: 0.1)
- self.aiErrorCorrectionLabel.textColor = NSColor.km_init(hex: "#252629")
- self.aiErrorCorrectionLabel.font = NSFont.SFProTextSemiboldFont(16.0)
- self.rightFullBox.isHidden = false
- self.rightTopBox.contentView = nil
- self.rightBottomBox.contentView = nil
- self.rightFullBox.contentView = self.aiRewritingViewController.view
- self.aiRewritingViewController.state = .AIErrorCorrection
- self.aiRewritingViewController.initLocalization()
- self.aiRewritingViewController.acquisition_uiState()
-
- self.dragView.isHidden = true
- break
- default:
- break
- }
- }
-
- func refreshProductActiveSpacing() -> Void {
- let height = self.view.frame.height - 32.0 - openPDFBoxHeight.constant - 16.0 - createPDFBoxHeight.constant - 24.0 - pdfSeriesBoxHeight.constant - pdfProSeriesBoxHeightConstraint.constant - 8 - othersBoxHeightConstraint.constant - pdfOthersBoxHeightConstraint.constant - 242 - 30
- // print("height == %f", height)
- if height > 24.0 {
- self.product_active_spacing.constant = height
- } else {
- self.product_active_spacing.constant = 24.0
- }
- }
-
- func fetchDifferentFilePath(filePath: String) -> String {
- var resultFilePath = filePath
- var index: Int = 0
- while (FileManager.default.fileExists(atPath: resultFilePath)) {
- index += 1
- let path = NSString(string: filePath).deletingPathExtension + "(" + String(index) + ")"
- resultFilePath = NSString(string: path).appendingPathExtension(NSString(string: filePath).pathExtension)!
- }
-
- return resultFilePath;
- }
-
- func showProgressWindow() {
- let progress = SKProgressController()
- progress.message = NSLocalizedString("Translating...", comment: "")
- progress.window?.backgroundColor = NSColor.km_init(hex: "#36383B")
- progress.window?.contentView?.wantsLayer = true
- progress.window?.contentView?.layer?.backgroundColor = NSColor.km_init(hex: "#36383B").cgColor
- progress.progressField.textColor = NSColor.white
-
- progress.closeBlock = { [unowned self] in
-
- }
-
- self.progressController = progress
- self.view.window?.beginSheet(progress.window!)
- }
-
- func hiddenProgressWindow() {
- DispatchQueue.main.async {
- self.progressController?.doubleValue = 100.0
- }
- self.stopTimer()
- if (self.progressController != nil) {
- self.view.window?.endSheet((self.progressController?.window)!)
- self.progressController = nil
- }
- }
-
- func isFileGreaterThan10MB(atPath filePath: String) -> Bool {
- let fileManager = FileManager.default
- do {
- let fileAttributes = try fileManager.attributesOfItem(atPath: filePath)
- if let fileSize = fileAttributes[.size] as? UInt64 {
- let megabyteSize = fileSize / (1024 * 1024)
- return megabyteSize >= 10
- }
- } catch {
- KMPrint("Error: \(error)")
- }
- return false
- }
-
- func isPDFPageCountExceedsLimit(filePath: String) -> Bool {
- let url = URL(fileURLWithPath: filePath)
- guard let document = PDFDocument(url: url) else {
- return false
- }
-
- let pageCount = document.pageCount
- return pageCount > 30
- }
-
- @objc func timerTick() {
- timerCounter += 1.0
- self.progressController?.increment(by: 1.0)
-
- if timerCounter >= 95 {
- stopTimer()
- }
- }
-
- func stopTimer() {
- timer?.invalidate()
- timer = nil
- }
- // MARK: Common methods
-
- func workSpaceOpenUrl(_ url: NSString) {
- let httpUrl: NSURL = NSURL.init(string: url as String)!
- let tWorkSpace: NSWorkspace = NSWorkspace.shared
- if !tWorkSpace.open(httpUrl as URL) {
- tWorkSpace.open(httpUrl as URL)
- }
- }
-
- func createPopoverAction(_ data: [String]) {
- if (self.popover != nil && self.popover!.isShown) {
- self.popover?.close()
- self.popover = nil
- return
- }
- let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(data)
- let createFilePopover: NSPopover = NSPopover.init()
- self.popover = createFilePopover
- createFilePopover.contentViewController = vc
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: createPDFBox.bounds.origin.x, y: 10, width: createPDFBox.bounds.size.width, height: createPDFBox.bounds.size.height), of: createPDFBox, preferredEdge: .minY)
-
- vc.customBoxWidthLayoutConstraint.constant = createPDFBox.frame.width
- vc.downCallback = { [weak self] (downEntered: Bool, count: String) -> Void in
- if downEntered {
- self?.popover?.close()
- self?.popover = nil
- self?.popoverItemAction(count)
- }
- }
- }
- }
|