+
+ init(_ configuration: CaptureSessionConfiguration, frame: NSRect, button: NSRect) {
+ self.buttonSize = button.size
+ var buttonOffset = NSPoint()
+ for screen in NSScreen.screens {
+ if screen.frame.intersects(button) {
+ let relativeY = screen.frame.height - (button.minY - screen.frame.minY)
+ let relativeX = screen.frame.width - (button.minX - screen.frame.minX)
+ buttonOffset = NSPoint(x: relativeX, y: relativeY)
+ }
+ }
+ self.buttonOffset = buttonOffset
+ super.init(frame: frame)
+ preventResize = configuration.preventResize
+ preventMove = configuration.preventMove
+ autoStart = configuration.autoStart
+
+ self.bounds = frame
+ self.button = NSRect(
+ x: frame.maxX - buttonOffset.x, y: frame.maxY - buttonOffset.y, width: buttonSize.width,
+ height: buttonSize.height)
+
+ 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")
+ }
+
+ private let buttonSize: NSSize
+ private let buttonOffset: NSPoint