Skip to content

Commit

Permalink
Use function-local cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Oct 28, 2024
1 parent 17496a1 commit f0b7fd4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Ice/Utilities/ScreenCapture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@ import ScreenCaptureKit

/// A namespace for screen capture operations.
enum ScreenCapture {
private static var lastCheckResult: Bool?
static func cachedCheckPermissions(reset: Bool = false) -> Bool {
enum Context {
static var lastCheckResult: Bool?
}

// Now that we can work without this permission, this call gets called way more often.
// According to the energy meter, this has some minor impact on energy consumption
// Let's cache the result until we are asked not to (e.g. the settings window is visible)
if !reset {
if let lastCheckResultUnrawpped = lastCheckResult {
return lastCheckResultUnrawpped
if let lastCheckResult = Context.lastCheckResult {
return lastCheckResult
}
}

let realResult = checkPermissions()

lastCheckResult = realResult
Context.lastCheckResult = realResult

return realResult
}
Expand Down

0 comments on commit f0b7fd4

Please sign in to comment.