Files
Recordly/electron/native/ScreenCaptureKitRecorder/RecorderService.swift
T

55 lines
1.1 KiB
Swift

import Foundation
final class RecorderService {
private let recorder = ScreenCaptureRecorder()
private let queue = DispatchQueue(label: "recordly.screencapturekit.commands")
private let completionGroup = DispatchGroup()
func start(configJSON: String) {
completionGroup.enter()
queue.async {
Task {
do {
try await self.recorder.startCapture(configJSON: configJSON)
} catch {
fputs("Error starting capture: \(error.localizedDescription)\n", stderr)
fflush(stderr)
self.completionGroup.leave()
}
}
}
}
func stop() {
queue.async {
Task {
do {
let outputPath = try await self.recorder.stopCapture()
print("Recording stopped. Output path: \(outputPath)")
fflush(stdout)
self.completionGroup.leave()
} catch {
fputs("Error stopping capture: \(error.localizedDescription)\n", stderr)
fflush(stderr)
self.completionGroup.leave()
}
}
}
}
func pause() {
queue.async {
self.recorder.pauseCapture()
}
}
func resume() {
queue.async {
self.recorder.resumeCapture()
}
}
func waitUntilFinished() {
completionGroup.wait()
}
}