// MARK: - URL Event Handler
func application(_ application: NSApplication, open urls: [URL]) {
- print("AAAH OPENING")
if (CapturaSettings.shouldAllowURLAutomation) {
for url in urls {
if let action = CapturaURLDecoder.decodeParams(url: url) {
switch action {
case let .configure(config):
- print("AAAH CONFIGURING \(config)")
CapturaSettings.apply(config)
case let .record(config):
- print(config)
+ captureSessionConfiguration = CaptureSessionConfiguration(from: config)
+ NotificationCenter.default.post(name: .startAreaSelection, object: nil, userInfo: nil)
}
}
}
let rectInWindow = button.convert(button.bounds, to: nil)
let rectInScreen = button.window?.convertToScreen(rectInWindow)
NSApp.activate(ignoringOtherApps: true)
- recordingWindow = RecordingWindow(rectInScreen)
+ recordingWindow = RecordingWindow(captureSessionConfiguration, rectInScreen)
recordingWindow?.makeKeyAndOrderFront(nil)
recordingWindow?.orderFrontRegardless()
boxListener = recordingWindow?.recordingContentView.$box
stopTimer = DispatchWorkItem {
self.stopRecording()
}
- DispatchQueue.main.asyncAfter(deadline: .now() + 300, execute: stopTimer!)
+ DispatchQueue.main.asyncAfter(deadline: .now() + Double(captureSessionConfiguration.maxLength), execute: stopTimer!)
outputFile = CapturaFile()
if captureSessionConfiguration.shouldSaveMp4 {
func reset() {
captureState = .idle
updateImage()
+ captureSessionConfiguration = CaptureSessionConfiguration()
stop()
}
boxListener?.cancel()
recordingWindow?.close()
recordingWindow = nil
- captureSessionConfiguration = CaptureSessionConfiguration()
}
private func uploadOrCopy() async -> Bool {
var backendOutput: OutputFormatSetting? { get }
var keepLocalFiles: Bool? { get }
var autoStart: Bool? { get }
+ var skipBackend: Bool { get }
+ var maxLength: Int? { get }
}
// The concrete implementations
var backendOutput: OutputFormatSetting?
var keepLocalFiles: Bool?
var autoStart: Bool?
+ var skipBackend: Bool
+ var maxLength: Int?
}
enum CapturaAction {
let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
+ let autoStart = Bool(paramsDict["auto_start"] as? String ?? "")
+ var maxLength = Int(paramsDict["max_length"] as? String ?? "")
if fps != nil {
fps = min(10, max(4, fps!))
}
+ if maxLength != nil {
+ maxLength = min(300, max(1, fps!))
+ }
+
if backendOutput == .all {
backendOutput = .gifOnly
}
+ var skipBackend = false
+ if let backendString = paramsDict["backend"] as? String {
+ if backendString == "" {
+ skipBackend = true
+ }
+ }
+
return .record(RecordAction(
action: action,
x: x,
outputs: outputs,
backend: backend,
backendOutput: backendOutput,
- keepLocalFiles: keepLocalFiles
+ keepLocalFiles: keepLocalFiles,
+ autoStart: autoStart,
+ skipBackend: skipBackend,
+ maxLength: maxLength
))
default:
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,
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 {
self.contentView as! RecordingContentView
}
- init(_ button: NSRect?) {
+ init(_ configuration: CaptureSessionConfiguration, _ button: NSRect?) {
let screens = NSScreen.screens
var boundingBox = NSZeroRect
self.titlebarAppearsTransparent = true
self.setFrame(boundingBox, display: true)
self.titleVisibility = .hidden
- let recordingView = RecordingContentView()
+ let recordingView = RecordingContentView(configuration, frame: boundingBox)
recordingView.frame = boundingBox
recordingView.button = button
self.contentView = recordingView
class RecordingContentView: NSView {
+ init(_ configuration: CaptureSessionConfiguration, frame: NSRect) {
+ super.init(frame: frame)
+ preventResize = configuration.preventResize
+ preventMove = configuration.preventMove
+ autoStart = configuration.autoStart
+
+ if configuration.x != nil || configuration.y != nil || configuration.width != nil || configuration.height != nil {
+ box = NSRect(
+ x: configuration.x ?? Int(frame.width / 2.0),
+ y: configuration.y ?? Int(frame.height / 2.0),
+ width: configuration.width ?? 400,
+ height: configuration.height ?? 400
+ )
+ }
+
+ if autoStart {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
+ NotificationCenter.default.post(name: .startRecording, object: nil, userInfo: nil)
+ }
+ }
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
public var button: NSRect? = nil
@Published public var box: NSRect? = nil
public var state: RecordingWindowState = .idle
private var mouseLocation: NSPoint = NSPoint()
private var origin: NSPoint = NSPoint()
private var boxOrigin: NSPoint = NSPoint()
+ private var preventResize = false
+ private var preventMove = false
+ private var autoStart = false
private var resizeBox: NSRect? {
if let box {
}
}
- if resizeBox!.contains(origin) {
+ if resizeBox!.contains(origin) && !preventResize {
self.origin = NSPoint(x: box.minX, y: box.maxY)
state = .resizing
return
}
- if box.contains(origin) {
+ if box.contains(origin) && !preventMove {
state = .moving
self.boxOrigin = NSPoint(x: box.origin.x, y: box.origin.y)
return
}
}
+ if preventResize || preventMove {
+ return
+ }
+
state = .drawing
}