]> git.r.bdr.sh - rbdr/captura/blobdiff - Captura/CapturaApp.swift
Add AppleScript support
[rbdr/captura] / Captura / CapturaApp.swift
index eb6f02ecb264a24147165745a7944435a176ca9b..c6ec9f05c6316a5074a02aa20a1a85a899a3c1f4 100644 (file)
@@ -39,6 +39,8 @@ class CapturaAppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
   var remoteFiles: [CapturaRemoteFile] = []
   var captureSessionConfiguration: CaptureSessionConfiguration = CaptureSessionConfiguration()
   
+  @objc var scriptedPreferences: ScriptedPreferences?
+  
   func applicationDidFinishLaunching(_ notification: Notification) {
     setupStatusBar()
     NotificationCenter.default.addObserver(
@@ -48,6 +50,8 @@ class CapturaAppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
       object: nil)
     closeWindow()
     fetchRemoteItems()
+    
+    scriptedPreferences = ScriptedPreferences()
   }
   
   // MARK: - Setup Functions
@@ -108,7 +112,10 @@ class CapturaAppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
             case let .configure(config):
               CapturaSettings.apply(config)
             case let .record(config):
-              captureSessionConfiguration = CaptureSessionConfiguration(from: config)
+              let config = CaptureSessionConfiguration(from: config)
+            NotificationCenter.default.post(name: .startAreaSelection, object: nil, userInfo: [
+              "config": config
+            ])
               NotificationCenter.default.post(name: .startAreaSelection, object: nil, userInfo: nil)
           }
         }
@@ -196,6 +203,14 @@ class CapturaAppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
       if let frame = notification.userInfo?["frame"] {
         receivedFrame(frame as! CVImageBuffer)
       }
+    case .reloadConfiguration:
+      reloadConfiguration()
+    case .setCaptureSessionConfiguration:
+      if let userInfo = notification.userInfo {
+        if let config = userInfo["config"] as? RecordAction {
+          setCaptureSessionConfiguration(config)
+        }
+      }
     case .NSManagedObjectContextObjectsDidChange:
       DispatchQueue.main.async {
         self.fetchRemoteItems()
@@ -324,6 +339,14 @@ class CapturaAppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
     }
   }
   
+  func reloadConfiguration() {
+    self.captureSessionConfiguration = CaptureSessionConfiguration()
+  }
+  
+  func setCaptureSessionConfiguration(_ config: RecordAction) {
+    self.captureSessionConfiguration = CaptureSessionConfiguration(from: config)
+  }
+  
   // MARK: - CoreData
   
   private func fetchRemoteItems() {