fix: ignore more non-user-facing apps (xpc processes)
This commit is contained in:
1 parent
cd0d53d6bc
commit
84175640f7
3 files changed
+26
-15
No files matched your search
@@ -170,3 +170,10 @@ extension pid_t {
|
||||
return kinfo.kp_proc.p_stat == SZOMB
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
// convert a FourCharCode into a String
|
||||
init(_ fourCharCode: FourCharCode) { // or `OSType`, or `UInt32`
|
||||
self = NSFileTypeForHFSTypeCode(fourCharCode).trimmingCharacters(in: CharacterSet(charactersIn: "'"))
|
||||
}
|
||||
}
|
||||
@@ -136,6 +136,16 @@ func setNativeCommandTabEnabled(_ isEnabled: Bool) {
|
||||
CGSSetSymbolicHotKeyEnabled(2, isEnabled) // command+shift+tab
|
||||
}
|
||||
|
||||
// returns info about a given psn
|
||||
// * macOS 10.9-10.15 (officially removed in 10.9, but available as a private API still)
|
||||
@_silgen_name("GetProcessInformation") @discardableResult
|
||||
func GetProcessInformation(_ psn: inout ProcessSerialNumber, _ info: inout ProcessInfoRec) -> OSErr
|
||||
//
|
||||
// returns the psn for a given pid
|
||||
// * macOS 10.9-10.15 (officially removed in 10.9, but available as a private API still)
|
||||
@_silgen_name("GetProcessForPID") @discardableResult
|
||||
func GetProcessForPID(_ pid: pid_t, _ psn: inout ProcessSerialNumber) -> OSStatus
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// below are some notes on some private APIs I experimented with
|
||||
@@ -190,16 +200,6 @@ func setNativeCommandTabEnabled(_ isEnabled: Bool) {
|
||||
//@_silgen_name("GetProcessPID")
|
||||
//func GetProcessPID(_ psn: inout ProcessSerialNumber, _ pid: inout pid_t) -> Void
|
||||
//
|
||||
//// returns info about a given psn
|
||||
//// * macOS 10.9-
|
||||
//@_silgen_name("GetProcessInformation") @discardableResult
|
||||
//func GetProcessInformation(_ psn: inout ProcessSerialNumber, _ info: inout ProcessInfoRec) -> OSErr
|
||||
//
|
||||
//// returns the psn for a given pid
|
||||
//// * macOS 10.9-
|
||||
//@_silgen_name("GetProcessForPID") @discardableResult
|
||||
//func GetProcessForPID(_ pid: pid_t, _ psn: inout ProcessSerialNumber) -> OSStatus
|
||||
//
|
||||
//// crashed the app with SIGSEGV
|
||||
//// * macOS 10.10+
|
||||
//@_silgen_name("CGSGetWindowType") @discardableResult
|
||||
|
||||
@@ -101,14 +101,18 @@ class Applications {
|
||||
}
|
||||
|
||||
private static func isActualApplication(_ app: NSRunningApplication) -> Bool {
|
||||
return (app.activationPolicy != .prohibited || isNotXpc(app)) && !app.processIdentifier.isZombie()
|
||||
// an app can be both activationPolicy == .accessory and XPC (e.g. com.apple.dock.etci)
|
||||
return app.activationPolicy != .prohibited && isNotXpc(app) && !app.processIdentifier.isZombie()
|
||||
}
|
||||
|
||||
private static func isNotXpc(_ app: NSRunningApplication) -> Bool {
|
||||
return app.bundleURL
|
||||
.flatMap { Bundle(url: $0) }
|
||||
.flatMap { $0.infoDictionary }
|
||||
.flatMap { $0["CFBundlePackageType"] as? String } != "XPC!"
|
||||
// these private APIs are more reliable than Bundle.init? as it can return nil (e.g. for com.apple.dock.etci)
|
||||
var psn = ProcessSerialNumber()
|
||||
GetProcessForPID(app.processIdentifier, &psn)
|
||||
var info = ProcessInfoRec()
|
||||
GetProcessInformation(&psn, &info)
|
||||
debugPrint(app.bundleIdentifier, String(info.processType))
|
||||
return String(info.processType) != "XPC!"
|
||||
}
|
||||
|
||||
// managing AltTab windows within AltTab create all sorts of side effects
|
||||
|
||||
Reference in new issue
Block a user