+ }
+ }
+
+ func failed(_ requestPermission: Bool = false) {
+ captureState = .error
+ updateImage()
+ if requestPermission {
+ requestPermissionToRecord()
+ }
+ stop()
+ DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
+ NotificationCenter.default.post(name: .reset, object: nil, userInfo: nil)
+ }
+ }
+
+ func reloadConfiguration() {
+ self.captureSessionConfiguration = CaptureSessionConfiguration()
+ }
+
+ func setCaptureSessionConfiguration(_ config: RecordAction) {
+ self.captureSessionConfiguration = CaptureSessionConfiguration(from: config)
+ }
+
+ // MARK: - CoreData
+
+ private func fetchRemoteItems() {
+ let viewContext = PersistenceController.shared.container.viewContext
+ let fetchRequest = NSFetchRequest<CapturaRemoteFile>(entityName: "CapturaRemoteFile")
+ fetchRequest.fetchLimit = 5
+ fetchRequest.sortDescriptors = [NSSortDescriptor(key: "timestamp", ascending: false)]
+
+ let results = try? viewContext.fetch(fetchRequest)
+ remoteFiles = results ?? []
+ }
+
+ // MARK: - Presentation Helpers
+
+
+ private func requestPermissionToRecord() {
+ showPopoverWithMessage("Please grant Captura permission to record")
+ if let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenRecording") {
+ NSWorkspace.shared.open(url)
+ }
+ }
+
+ private func showPopoverWithMessage(_ message: String) {
+ if let button = statusItem.button {
+ (self.popover?.contentViewController as? HelpPopoverViewController)?.updateLabel(message)
+ self.popover?.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
+ DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
+ self.popover?.performClose(nil)