]> git.r.bdr.sh - rbdr/captura/blob - Captura/Domain/CaptureSessionConfiguration.swift
673db5f563f39200a06b38f19954e752b6c71aac
[rbdr/captura] / Captura / Domain / CaptureSessionConfiguration.swift
1 import Foundation
2
3 struct CaptureSessionConfiguration {
4 let frameRate: Int
5 let outputFormats: OutputFormatSetting
6 let backendFormat: OutputFormatSetting
7 let backend: URL?
8 let shouldKeepLocalFiles: Bool
9 let x: Int?
10 let y: Int?
11 let width: Int?
12 let height: Int?
13 let preventMove: Bool
14 let preventResize: Bool
15 let autoStart: Bool
16 let maxLength: Int
17
18 init(
19 frameRate: Int? = nil,
20 outputFormats: OutputFormatSetting? = nil,
21 backendFormat: OutputFormatSetting? = nil,
22 backend: URL? = nil,
23 shouldKeepLocalFiles: Bool? = nil
24 ) {
25 self.frameRate = frameRate ?? CapturaSettings.frameRate
26 self.outputFormats = outputFormats ?? CapturaSettings.outputFormats
27 self.backendFormat = backendFormat ?? CapturaSettings.backendFormat
28 self.backend = backend ?? CapturaSettings.backend
29 self.shouldKeepLocalFiles = shouldKeepLocalFiles ?? CapturaSettings.shouldKeepLocalFiles
30 x = nil
31 y = nil
32 width = nil
33 height = nil
34 preventMove = false
35 preventResize = false
36 autoStart = false
37 maxLength = 300
38 }
39
40 init(from action: RecordAction) {
41 self.frameRate = action.fps ?? CapturaSettings.frameRate
42 self.outputFormats = action.outputs ?? CapturaSettings.outputFormats
43 self.backendFormat = action.backendOutput ?? CapturaSettings.backendFormat
44 if action.skipBackend {
45 self.backend = nil
46 } else {
47 self.backend = action.backend ?? CapturaSettings.backend
48 }
49 self.shouldKeepLocalFiles = action.keepLocalFiles ?? CapturaSettings.shouldKeepLocalFiles
50 self.x = action.x
51 self.y = action.y
52 self.width = action.width
53 self.height = action.height
54 preventMove = action.preventMove ?? false
55 preventResize = action.preventResize ?? false
56 autoStart = action.autoStart ?? false
57 maxLength = action.maxLength ?? 300
58 }
59
60 var shouldSaveMp4: Bool {
61 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
62 }
63
64 var shouldSaveGif: Bool {
65 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
66 }
67
68 var shouldUploadGif: Bool {
69 backendFormat.shouldSaveGif()
70 }
71
72 var shouldUploadMp4: Bool {
73 backendFormat.shouldSaveMp4()
74 }
75
76 var shouldUseBackend: Bool {
77 backend != nil
78 }
79 }