Last active
January 26, 2021 06:01
-
-
Save MainasuK/4bce9bcb5c99bab7945d85e6ca835fc5 to your computer and use it in GitHub Desktop.
Screen Record Permission Request Helper for macOS Catalina
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let stream = CGDisplayStream(display: CGDirectDisplayID(), outputWidth: 1, outputHeight: 1, pixelFormat: Int32(kCVPixelFormatType_32BGRA), properties: nil, handler: { (status, time, surface, update) in | |
// do nothing | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nemu = NSWorkspace().runningApplications.first { application -> Bool in | |
return application.bundleIdentifier == "com.netease.nemu" | |
} | |
let windowInfoArray = CGWindowListCopyWindowInfo(.optionAll, kCGNullWindowID)! as NSArray | |
let nemuWindowInfo = windowInfoArray.first { anyInfo -> Bool in | |
guard let info = anyInfo as? NSDictionary else { return false } | |
guard let pid = info[kCGWindowOwnerPID as NSString] as? NSNumber else { return false } | |
return pid.int32Value == nemu?.processIdentifier | |
} as? NSDictionary | |
let image = nemuWindowInfo | |
.flatMap { info -> CGWindowID? in | |
(info[kCGWindowNumber as NSString] as? NSNumber)?.uint32Value | |
} | |
.flatMap { windowID -> CGImage? in | |
CGWindowListCreateImage(.null, .optionIncludingWindow, windowID, [.boundsIgnoreFraming, .nominalResolution]) | |
} | |
.flatMap { cgImage -> NSImage? in | |
NSImage(cgImage: cgImage, size: .zero) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment