mirror of
https://github.com/lwouis/alt-tab-macos.git
synced 2026-05-24 11:20:36 +00:00
fix: app would sometimes quit while in the background (closes #704)
This commit is contained in:
@@ -20,25 +20,19 @@ class SystemPermissions {
|
||||
return true
|
||||
}
|
||||
|
||||
// there is no official API to check the status of the Screen Recording permission
|
||||
// there is the private API SLSRequestScreenCaptureAccess, but its value is not updated during the app lifetime
|
||||
// workaround: we check if we can get the title of at least one window, except from AltTab or the Dock
|
||||
// workaround: public API CGPreflightScreenCaptureAccess and private API SLSRequestScreenCaptureAccess exist, but
|
||||
// their return value is not updated during the app lifetime
|
||||
// note: shows the system prompt if there's no permission
|
||||
private static func screenRecordingIsGranted_() -> Bool {
|
||||
let appPid = NSRunningApplication.current.processIdentifier
|
||||
if let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [CGWindow],
|
||||
let _ = windows.first(where: { (window) -> Bool in
|
||||
if let windowPid = window.ownerPID(),
|
||||
windowPid != appPid,
|
||||
let windowRunningApplication = NSRunningApplication(processIdentifier: windowPid),
|
||||
windowRunningApplication.executableURL?.lastPathComponent != "Dock",
|
||||
let _ = window.title() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return CGDisplayStream(
|
||||
dispatchQueueDisplay: CGMainDisplayID(),
|
||||
outputWidth: 1,
|
||||
outputHeight: 1,
|
||||
pixelFormat: Int32(kCVPixelFormatType_32BGRA),
|
||||
properties: nil,
|
||||
queue: .global(),
|
||||
handler: { _, _, _, _ in }
|
||||
) != nil
|
||||
}
|
||||
|
||||
static func observePermissionsPostStartup() {
|
||||
|
||||
Reference in New Issue
Block a user