aboutsummaryrefslogtreecommitdiff
path: root/Captura/Domain/CaptureSessionConfiguration.swift
blob: 673db5f563f39200a06b38f19954e752b6c71aac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Foundation

struct CaptureSessionConfiguration {
  let frameRate: Int
  let outputFormats: OutputFormatSetting
  let backendFormat: OutputFormatSetting
  let backend: URL?
  let shouldKeepLocalFiles: Bool
  let x: Int?
  let y: Int?
  let width: Int?
  let height: Int?
  let preventMove: Bool
  let preventResize: Bool
  let autoStart: Bool
  let maxLength: Int

  init(
    frameRate: Int? = nil,
    outputFormats: OutputFormatSetting? = nil,
    backendFormat: OutputFormatSetting? = nil,
    backend: URL? = nil,
    shouldKeepLocalFiles: Bool? = nil
  ) {
    self.frameRate = frameRate ?? CapturaSettings.frameRate
    self.outputFormats = outputFormats ?? CapturaSettings.outputFormats
    self.backendFormat = backendFormat ?? CapturaSettings.backendFormat
    self.backend = backend ?? CapturaSettings.backend
    self.shouldKeepLocalFiles = shouldKeepLocalFiles ?? CapturaSettings.shouldKeepLocalFiles
    x = nil
    y = nil
    width = nil
    height = nil
    preventMove = false
    preventResize = false
    autoStart = false
    maxLength = 300
  }

  init(from action: RecordAction) {
    self.frameRate = action.fps ?? CapturaSettings.frameRate
    self.outputFormats = action.outputs ?? CapturaSettings.outputFormats
    self.backendFormat = action.backendOutput ?? CapturaSettings.backendFormat
    if action.skipBackend {
      self.backend = nil
    } else {
      self.backend = action.backend ?? CapturaSettings.backend
    }
    self.shouldKeepLocalFiles = action.keepLocalFiles ?? CapturaSettings.shouldKeepLocalFiles
    self.x = action.x
    self.y = action.y
    self.width = action.width
    self.height = action.height
    preventMove = action.preventMove ?? false
    preventResize = action.preventResize ?? false
    autoStart = action.autoStart ?? false
    maxLength = action.maxLength ?? 300
  }

  var shouldSaveMp4: Bool {
    outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
  }

  var shouldSaveGif: Bool {
    outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
  }

  var shouldUploadGif: Bool {
    backendFormat.shouldSaveGif()
  }

  var shouldUploadMp4: Bool {
    backendFormat.shouldSaveMp4()
  }

  var shouldUseBackend: Bool {
    backend != nil
  }
}