From 9681915e6c98896639e35cd299a84824a3106410 Mon Sep 17 00:00:00 2001 From: cparish312 <54302513+cparish312@users.noreply.github.com> Date: Tue, 14 May 2024 12:27:10 -0400 Subject: [PATCH 1/4] startScreenCapture in loop --- rem/remApp.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rem/remApp.swift b/rem/remApp.swift index 9fec03e..664548a 100644 --- a/rem/remApp.swift +++ b/rem/remApp.swift @@ -324,8 +324,8 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { let shareableContent = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: false) setupMenu() - screenshotQueue.async { [weak self] in - self?.scheduleScreenshot(shareableContent: shareableContent) + Task { + await startScreenCapture() } } catch { logger.error("Error starting screen capture: \(error.localizedDescription)") From 09c1116297266ba06801bc219543dcbd21c6f02a Mon Sep 17 00:00:00 2001 From: cparish312 <54302513+cparish312@users.noreply.github.com> Date: Tue, 14 May 2024 12:31:31 -0400 Subject: [PATCH 2/4] startScreenCapture in loop --- rem/remApp.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rem/remApp.swift b/rem/remApp.swift index 664548a..f8cad22 100644 --- a/rem/remApp.swift +++ b/rem/remApp.swift @@ -324,8 +324,8 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { let shareableContent = try await SCShareableContent.excludingDesktopWindows(false, onScreenWindowsOnly: false) setupMenu() - Task { - await startScreenCapture() + screenshotQueue.async { [weak self] in + self?.scheduleScreenshot(shareableContent: shareableContent) } } catch { logger.error("Error starting screen capture: \(error.localizedDescription)") @@ -352,8 +352,8 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { private func retryScreenshot(shareableContent: SCShareableContent) { if screenshotRetries < 3 { screenshotRetries += 1 - screenshotQueue.asyncAfter(deadline: .now() + 2) { [weak self] in - self?.scheduleScreenshot(shareableContent: shareableContent) + Task { + await startScreenCapture() } } else { disableRecording() From 67bf6a1779477093bc67039e7c8bb9a689f5b1cf Mon Sep 17 00:00:00 2001 From: cparish312 <54302513+cparish312@users.noreply.github.com> Date: Tue, 14 May 2024 12:34:55 -0400 Subject: [PATCH 3/4] retryScreenCapture() --- rem/remApp.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rem/remApp.swift b/rem/remApp.swift index f8cad22..5e689af 100644 --- a/rem/remApp.swift +++ b/rem/remApp.swift @@ -90,7 +90,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { private var lastImageData: Data? = nil private var lastActiveApplication: String? = nil private var lastDisplayID: UInt32? = nil - private var screenshotRetries: Int = 0 + private var screenCaptureRetries: Int = 0 private var imageResizer = ImageResizer( @@ -349,15 +349,15 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { return false } - private func retryScreenshot(shareableContent: SCShareableContent) { - if screenshotRetries < 3 { - screenshotRetries += 1 + private func retryScreenCapture() { + if screenCaptureRetries < 3 { + screenCaptureRetries += 1 Task { await startScreenCapture() } } else { disableRecording() - screenshotRetries = 0 + screenCaptureRetries = 0 } } @@ -388,13 +388,13 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { guard displayID != nil else { logger.debug("DisplayID is nil") - retryScreenshot(shareableContent: shareableContent) + retryScreenCapture() return } guard let display = shareableContent.displays.first(where: { $0.displayID == displayID }) else { logger.debug("Display could not be retrieved") - retryScreenshot(shareableContent: shareableContent) + retryScreenCapture() return } @@ -452,7 +452,7 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { logger.error("Error taking screenshot: \(error)") } - screenshotRetries = 0 + screenCaptureRetries = 0 screenshotQueue.asyncAfter(deadline: .now() + 2) { [weak self] in self?.scheduleScreenshot(shareableContent: shareableContent) } From 23d208f2a97d9c09cbcf263b8c8e77b3542a8e22 Mon Sep 17 00:00:00 2001 From: cparish312 <54302513+cparish312@users.noreply.github.com> Date: Thu, 16 May 2024 09:34:26 -0400 Subject: [PATCH 4/4] add delay before retry --- rem/remApp.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/rem/remApp.swift b/rem/remApp.swift index 5e689af..da4103a 100644 --- a/rem/remApp.swift +++ b/rem/remApp.swift @@ -353,6 +353,7 @@ func drawStatusBarIcon(rect: CGRect) -> Bool { if screenCaptureRetries < 3 { screenCaptureRetries += 1 Task { + try await Task.sleep(nanoseconds: 2_000_000_000) await startScreenCapture() } } else {