SecureEventInputSputnik // Patch a memory leak, etc.
This commit is contained in:
parent
005116c429
commit
d8aba434d9
|
@ -20,15 +20,19 @@ public class SecureEventInputSputnik {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func getIORegListResults() -> String? {
|
public static func getIORegListResults() -> String? {
|
||||||
|
// Don't generate results under any of the following situations:
|
||||||
|
// - Hibernation / LoggedOut / SwitchedOut / ScreenSaver situations.
|
||||||
|
guard NSWorkspace.activationFlags.isEmpty else { return nil }
|
||||||
var resultDictionaryCF: Unmanaged<CFMutableDictionary>?
|
var resultDictionaryCF: Unmanaged<CFMutableDictionary>?
|
||||||
|
defer { resultDictionaryCF = nil }
|
||||||
/// Regarding the parameter in IORegistryGetRootEntry:
|
/// Regarding the parameter in IORegistryGetRootEntry:
|
||||||
/// Both kIOMasterPortDefault and kIOMainPortDefault are 0.
|
/// Both kIOMasterPortDefault and kIOMainPortDefault are 0.
|
||||||
/// The latter one is similar to what `git` had done: changing "Master" to "Main".
|
/// The latter one is similar to what `git` had done: changing "Master" to "Main".
|
||||||
let statusSucceeded = IORegistryEntryCreateCFProperties(
|
let statusSucceeded = IORegistryEntryCreateCFProperties(
|
||||||
IORegistryGetRootEntry(0), &resultDictionaryCF, kCFAllocatorDefault, IOOptionBits(0)
|
IORegistryGetRootEntry(0), &resultDictionaryCF, kCFAllocatorDefault, IOOptionBits(0)
|
||||||
)
|
)
|
||||||
|
let dict: CFMutableDictionary? = resultDictionaryCF?.takeRetainedValue()
|
||||||
guard statusSucceeded == KERN_SUCCESS else { return nil }
|
guard statusSucceeded == KERN_SUCCESS else { return nil }
|
||||||
let dict = resultDictionaryCF?.takeRetainedValue()
|
|
||||||
guard let dict: [CFString: Any] = dict as? [CFString: Any] else { return nil }
|
guard let dict: [CFString: Any] = dict as? [CFString: Any] else { return nil }
|
||||||
return (dict.description)
|
return (dict.description)
|
||||||
}
|
}
|
||||||
|
@ -75,7 +79,7 @@ public extension NSWorkspace {
|
||||||
|
|
||||||
public static let hibernating = ActivationFlags(rawValue: 1 << 0)
|
public static let hibernating = ActivationFlags(rawValue: 1 << 0)
|
||||||
public static let desktopLocked = ActivationFlags(rawValue: 1 << 1)
|
public static let desktopLocked = ActivationFlags(rawValue: 1 << 1)
|
||||||
public static let sesssionSwitchedOut = ActivationFlags(rawValue: 1 << 2)
|
public static let sessionSwitchedOut = ActivationFlags(rawValue: 1 << 2)
|
||||||
public static let screenSaverRunning = ActivationFlags(rawValue: 1 << 3)
|
public static let screenSaverRunning = ActivationFlags(rawValue: 1 << 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +127,11 @@ extension SecureEventInputSputnik {
|
||||||
.store(in: &Self.combinePool)
|
.store(in: &Self.combinePool)
|
||||||
NSWorkspace.shared.notificationCenter
|
NSWorkspace.shared.notificationCenter
|
||||||
.publisher(for: NSWorkspace.sessionDidResignActiveNotification)
|
.publisher(for: NSWorkspace.sessionDidResignActiveNotification)
|
||||||
.sink { _ in NSWorkspace.activationFlags.insert(.sesssionSwitchedOut) }
|
.sink { _ in NSWorkspace.activationFlags.insert(.sessionSwitchedOut) }
|
||||||
.store(in: &Self.combinePool)
|
.store(in: &Self.combinePool)
|
||||||
NSWorkspace.shared.notificationCenter
|
NSWorkspace.shared.notificationCenter
|
||||||
.publisher(for: NSWorkspace.sessionDidBecomeActiveNotification)
|
.publisher(for: NSWorkspace.sessionDidBecomeActiveNotification)
|
||||||
.sink { _ in NSWorkspace.activationFlags.remove(.sesssionSwitchedOut) }
|
.sink { _ in NSWorkspace.activationFlags.remove(.sessionSwitchedOut) }
|
||||||
.store(in: &Self.combinePool)
|
.store(in: &Self.combinePool)
|
||||||
} else {
|
} else {
|
||||||
Self.combinePoolCocoa.append(
|
Self.combinePoolCocoa.append(
|
||||||
|
@ -169,13 +173,13 @@ extension SecureEventInputSputnik {
|
||||||
Self.combinePoolCocoa.append(
|
Self.combinePoolCocoa.append(
|
||||||
NSWorkspace.shared.notificationCenter
|
NSWorkspace.shared.notificationCenter
|
||||||
.addObserver(forName: NSWorkspace.sessionDidResignActiveNotification, object: nil, queue: .main) { _ in
|
.addObserver(forName: NSWorkspace.sessionDidResignActiveNotification, object: nil, queue: .main) { _ in
|
||||||
NSWorkspace.activationFlags.insert(.sesssionSwitchedOut)
|
NSWorkspace.activationFlags.insert(.sessionSwitchedOut)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Self.combinePoolCocoa.append(
|
Self.combinePoolCocoa.append(
|
||||||
NSWorkspace.shared.notificationCenter
|
NSWorkspace.shared.notificationCenter
|
||||||
.addObserver(forName: NSWorkspace.sessionDidBecomeActiveNotification, object: nil, queue: .main) { _ in
|
.addObserver(forName: NSWorkspace.sessionDidBecomeActiveNotification, object: nil, queue: .main) { _ in
|
||||||
NSWorkspace.activationFlags.remove(.sesssionSwitchedOut)
|
NSWorkspace.activationFlags.remove(.sessionSwitchedOut)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue