- @Environment(\.openURL) var openURL
- var statusItem: NSStatusItem!
- var captureState: CaptureState = .idle
- var recordingWindow: RecordingWindow? = nil
-
- func applicationDidFinishLaunching(_ notification: Notification) {
- setupMenu()
- NotificationCenter.default.addObserver(
- self,
- selector: #selector(self.didReceiveNotification(_:)),
- name: nil,
- object: nil)
- closeWindow()
+ @Environment(\.openURL) var openURL
+ var statusItem: NSStatusItem!
+ var captureState: CaptureState = .idle
+ var recordingWindow: RecordingWindow? = nil
+ var preferencesWindow: PreferencesWindow? = nil
+ var boxListener: AnyCancellable? = nil
+ var popover: NSPopover? = nil
+ var helpShown = false
+ var captureSession: CapturaCaptureSession? = nil
+ var images: [CGImage] = []
+ var outputFile: CapturaFile? = nil
+ var gifCallbackTimer = ContinuousClock.now
+ var pixelDensity: CGFloat = 1.0
+ var stopTimer: DispatchWorkItem?
+ var remoteFiles: [CapturaRemoteFile] = []
+ var captureSessionConfiguration: CaptureSessionConfiguration = CaptureSessionConfiguration()
+
+ @objc var scriptedPreferences: ScriptedPreferences?
+
+ func applicationDidFinishLaunching(_ notification: Notification) {
+ setupStatusBar()
+ NotificationCenter.default.addObserver(
+ self,
+ selector: #selector(self.didReceiveNotification(_:)),
+ name: nil,
+ object: nil)
+ closeWindow()
+ fetchRemoteItems()
+
+ scriptedPreferences = ScriptedPreferences()
+ }
+
+ // MARK: - Setup Functions
+
+
+ private func setupStatusBar() {
+ statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
+
+ if let button = statusItem.button {
+ button.image = NSImage(systemSymbolName: "rectangle.dashed.badge.record", accessibilityDescription: "Captura")
+ }
+
+ statusItem.isVisible = true
+ statusItem.menu = NSMenu()
+ statusItem.menu?.delegate = self
+
+ // Create the Popover
+ popover = NSPopover()
+ popover?.contentViewController = HelpPopoverViewController()
+ popover?.behavior = .transient
+
+ setupMenu()
+ }
+
+ private func setupMenu() {
+
+ statusItem.menu?.removeAllItems()
+
+ statusItem.menu?.addItem(NSMenuItem(title: "Record", action: #selector(CapturaAppDelegate.onClickStartRecording), keyEquivalent: ""))
+ if (remoteFiles.count > 0) {
+ statusItem.menu?.addItem(NSMenuItem.separator())
+ for remoteFile in remoteFiles {
+ let remoteFileItem = NSMenuItem(title: remoteFile.name, action: #selector(CapturaAppDelegate.onClickRemoteFile), keyEquivalent: "")
+ remoteFileItem.representedObject = remoteFile
+ statusItem.menu?.addItem(remoteFileItem)
+ }