KMPDFConvertManager.swift 1002 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // KMPDFConvertManager.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/12/7.
  6. //
  7. import Cocoa
  8. class KMPDFConvertManager: NSObject {
  9. static let defaultManager = KMPDFConvertManager()
  10. var operationQueue: OperationQueue = OperationQueue()
  11. override init() {
  12. super.init()
  13. operationQueue.maxConcurrentOperationCount = 1
  14. }
  15. func convert(convert: KMPDFConvert, completion: @escaping (_ finished: Bool, _ error: Error?) -> ()) {
  16. convert.callback = completion
  17. operationQueue.addOperation(convert)
  18. }
  19. func convert(convert: KMPDFConvert, progress:@escaping (Int)->Void, completion: @escaping (_ finished: Bool, _ error: Error?) -> ()) {
  20. convert.callback = completion
  21. convert.progress = progress
  22. operationQueue.addOperation(convert)
  23. }
  24. func cancel(convert: KMPDFConvert) {
  25. convert.cancel()
  26. self.operationQueue.cancelAllOperations()
  27. }
  28. }