// // KMNHomeQuickToolManager.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/10/12. // import Cocoa @objc public enum HomeQuickToolType: Int, CaseIterable{ case Batch = 0 // 批量处理 case MergePDF // 合并 case ImageToPDF // 图片转PDF case OCR // 批量OCR case ConvertPDF // 转换PDF case PDFToWord // PDF转Word case PDFToExcel // PDF转Excel case Compression // 压缩 case PDFToPPT // PDF转PPT case Security // 安全 case FileCompare // 文件对比 case Watermark // 水印 case Insert // 插入 case Extract // 提取 case DigitalSignature //数字签名 case Print //print } //MARK: - KMNHomeQuickToolMode class KMNHomeQuickToolMode: NSObject { var toolImageName: String = "" //图片名称 var toolTitle: String = "" //主标题 var toolSubtitle: String = "" //副标题 var quickToolType: HomeQuickToolType = .Batch //副标题 var isNewState: Bool = false //是否新的功能 class func toolModeData(type: HomeQuickToolType) -> KMNHomeQuickToolMode { let mode: KMNHomeQuickToolMode = KMNHomeQuickToolMode() mode.quickToolType = type switch type { case .Batch: mode.toolTitle = KMLocalizedString("Batch") mode.toolSubtitle = KMLocalizedString("Batch convert, compress, secure, watermark PDFs") mode.toolImageName = "KMNImageNameQuickToolBatch" mode.isNewState = true break case .OCR: mode.toolTitle = KMLocalizedString("OCR") mode.toolSubtitle = KMLocalizedString("Recognize text from images or scanned PDF with OCR") mode.toolImageName = "KMNImageNameQuickToolOCR" break case .ConvertPDF: mode.toolTitle = KMLocalizedString("Convert PDF") mode.toolSubtitle = KMLocalizedString("Convert PDFs to Word/HTML/TXT/JPEG/PNG files") mode.toolImageName = "KMNImageNameQuickToolConvert" mode.isNewState = true break case .ImageToPDF: mode.toolTitle = KMLocalizedString("Image To PDF") mode.toolSubtitle = KMLocalizedString("Convert JPEG/JPG/PNG/TIFF/BMP/PSD files to PDFs") mode.toolImageName = "KMNImageNameQuickToolImageToPDF" break case .MergePDF: mode.toolTitle = KMLocalizedString("Merge") mode.toolSubtitle = KMLocalizedString("Combine multiple documents into a new PDF file") mode.toolImageName = "KMNImageNameQuickToolMerge" break case .Compression: mode.toolTitle = KMLocalizedString("Compress") mode.toolSubtitle = KMLocalizedString("Reduce files size to make sure you can easily send them by email.") mode.toolImageName = "KMNImageNameQuickToolCompress" break case .Security: mode.toolTitle = KMLocalizedString("Security") mode.toolSubtitle = KMLocalizedString("Easily batch encrypt PDFs or decrypt the protected files") mode.toolImageName = "KMNImageNameQuickToolSecurity" break case .FileCompare: mode.toolTitle = KMLocalizedString("Compare") mode.toolSubtitle = KMLocalizedString("Compare the differences between two files") mode.toolImageName = "KMNImageNameQuickToolCompare" break case .PDFToPPT: mode.toolTitle = KMLocalizedString("PDF To PPT") mode.toolSubtitle = KMLocalizedString("Turn your PDF into a formatted PPT file that you can edit") mode.toolImageName = "KMNImageNameQuickToolToPPT" break case .PDFToExcel: mode.toolTitle = KMLocalizedString("PDF To Excel") mode.toolSubtitle = KMLocalizedString("Turn PDF table into a formatted Excel file") mode.toolImageName = "KMNImageNameQuickToolToExcel" break case .PDFToWord: mode.toolTitle = KMLocalizedString("PDF To Word") mode.toolSubtitle = KMLocalizedString("Convert PDFs to Word, Fonts & formatting get converted") mode.toolImageName = "KMNImageNameQuickToolToWord" break case .Watermark: mode.toolTitle = KMLocalizedString("Watermark") mode.toolSubtitle = KMLocalizedString("Protect PDFs with image/text watermarks from plagiarism") mode.toolImageName = "KMNImageNameQuickToolWater" break case .Extract: mode.toolTitle = KMLocalizedString("Extract") mode.toolSubtitle = KMLocalizedString("Extract selected pages to a new PDF") mode.toolImageName = "KMNImageNameQuickToolExtra" break case .Insert: mode.toolTitle = KMLocalizedString("Insert") mode.toolSubtitle = KMLocalizedString("Inserting pages into an existing PDF") mode.toolImageName = "KMNImageNameQuickToolInsert" case .DigitalSignature: mode.toolTitle = KMLocalizedString("Digital Signature") mode.toolSubtitle = KMLocalizedString("Delete/Rotate/Copy/Paste PDF pages") mode.toolImageName = "KMNImageNameQuickToolDigitalSignature" case .Print: mode.toolTitle = KMLocalizedString("Print") mode.toolSubtitle = KMLocalizedString("Powerful PDF printer allows to print PDF from any computer without much hassle") mode.toolImageName = "KMNImageNameQuickToolPrint" mode.isNewState = true } return mode } } class KMNHomeQuickToolManager: NSObject { var quickToolsItemMutableArray: [Int] = [] { didSet { UserDefaults.standard.set(quickToolsItemMutableArray, forKey: "kmnHomeQucikToolsItemArrayKey") UserDefaults.standard.synchronize() } } var fullToolsItemMutableArray: [Int] = [] { didSet { UserDefaults.standard.set(fullToolsItemMutableArray, forKey: "kmnHomeQucikToolsFullItemsArrayKey") UserDefaults.standard.synchronize() } } var collapseTools: Bool = false { didSet { UserDefaults.standard.set(collapseTools ? "1":"0", forKey: "quickToolsCollapseKey") UserDefaults.standard.synchronize() } } static let defaultManager: KMNHomeQuickToolManager = { let singleton = KMNHomeQuickToolManager() return singleton }() private override init() { let key = "kmnHomeQucikToolsItemArrayKey" if UserDefaults.standard.object(forKey: key) != nil { quickToolsItemMutableArray = UserDefaults.standard.array(forKey: key) as? [Int] ?? [] } else { quickToolsItemMutableArray = [HomeQuickToolType.Batch.rawValue, HomeQuickToolType.MergePDF.rawValue, HomeQuickToolType.ImageToPDF.rawValue, HomeQuickToolType.OCR.rawValue, HomeQuickToolType.ConvertPDF.rawValue, HomeQuickToolType.PDFToWord.rawValue, HomeQuickToolType.PDFToExcel.rawValue, HomeQuickToolType.Compression.rawValue] UserDefaults.standard.set(quickToolsItemMutableArray, forKey: key) UserDefaults.standard.synchronize() } if UserDefaults.standard.object(forKey: "quickToolsCollapseKey") != nil { self.collapseTools = UserDefaults.standard.bool(forKey: "quickToolsCollapseKey") } else { self.collapseTools = false UserDefaults.standard.setValue(collapseTools ? "1" : "0", forKey: "quickToolsCollapseKey") UserDefaults.standard.synchronize() } let fullKey = "kmnHomeQucikToolsFullItemsArrayKey" if UserDefaults.standard.object(forKey: fullKey) != nil { fullToolsItemMutableArray = UserDefaults.standard.array(forKey: fullKey) as? [Int] ?? [] } else { fullToolsItemMutableArray = [HomeQuickToolType.Batch.rawValue, HomeQuickToolType.MergePDF.rawValue, HomeQuickToolType.ImageToPDF.rawValue, HomeQuickToolType.OCR.rawValue, HomeQuickToolType.ConvertPDF.rawValue, HomeQuickToolType.PDFToWord.rawValue, HomeQuickToolType.PDFToExcel.rawValue, HomeQuickToolType.Compression.rawValue, HomeQuickToolType.PDFToPPT.rawValue, HomeQuickToolType.Security.rawValue, HomeQuickToolType.FileCompare.rawValue, HomeQuickToolType.Watermark.rawValue, HomeQuickToolType.Insert.rawValue, HomeQuickToolType.Extract.rawValue, HomeQuickToolType.Print.rawValue] UserDefaults.standard.set(fullToolsItemMutableArray, forKey: fullKey) UserDefaults.standard.synchronize() } } }