KMBatchOperation.swift 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // KMBatchOperation.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/10/31.
  6. //
  7. import Foundation
  8. @objc(KMBatchOperateProtocol)
  9. protocol KMBatchOperateProtocol: AnyObject {
  10. @objc optional func fileBeginOperate(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  11. @objc optional func fileOperating(_ file: KMBatchOperateFile, progress: CGFloat, info: KMBatchBaseParameter)
  12. @objc optional func fileOperateSuccessed(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  13. @objc optional func fileOperateFailed(_ file: KMBatchOperateFile, error: NSError, info: KMBatchBaseParameter)
  14. @objc optional func fileOperateCanceled(_ file: KMBatchOperateFile, info: KMBatchBaseParameter)
  15. }
  16. class KMBatchOperation: Operation{
  17. var hasCanceled: Bool = false
  18. var hasFinished: Bool = false
  19. var hasExcuting: Bool = false
  20. weak var operateFile: KMBatchOperateFile?
  21. weak var delegate: KMBatchOperateProtocol?
  22. var viewController: NSViewController?
  23. init(file: KMBatchOperateFile) {
  24. super.init()
  25. self.operateFile = file
  26. }
  27. override var isCancelled: Bool{
  28. return self.hasCanceled
  29. }
  30. override var isFinished: Bool{
  31. return self.hasFinished
  32. }
  33. override var isExecuting: Bool{
  34. return self.hasExcuting
  35. }
  36. func errorWithMsg(_ errorMsg: String) -> NSError {
  37. var errorDict = NSMutableDictionary()
  38. errorDict[NSLocalizedDescriptionKey] = errorMsg
  39. let error = NSError(domain: "PDFReaderBatchErrorDomain", code: -1, userInfo: (errorDict as! [String : Any]))
  40. return error
  41. }
  42. }