fix: application blocks on start
parent
de06cc1a32
commit
0f3a057fd4
|
@ -4,7 +4,6 @@ import Cocoa
|
|||
class MacOSHook {
|
||||
var callback: EventCallback
|
||||
let thread: MacOSHookThread
|
||||
private var dummyCounter = 0
|
||||
|
||||
init(callback: EventCallback) {
|
||||
self.callback = callback
|
||||
|
@ -17,8 +16,10 @@ class MacOSHook {
|
|||
func start() throws {
|
||||
thread.start()
|
||||
|
||||
while (!thread.started && thread.error == nil) {
|
||||
dummyCounter += 1
|
||||
while (true) {
|
||||
if (thread.started || thread.error != nil) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (thread.error != nil) {
|
||||
|
@ -31,8 +32,10 @@ class MacOSHook {
|
|||
CFRunLoopStop(self.thread.runLoop)
|
||||
}
|
||||
|
||||
while (self.thread.started) {
|
||||
dummyCounter += 1
|
||||
while (true) {
|
||||
if (!self.thread.started) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ class MacOSHookThread : Thread {
|
|||
|
||||
eventTap = nil
|
||||
|
||||
started = false
|
||||
self.started = false
|
||||
}
|
||||
|
||||
func eventCallback(proxy: OpaquePointer, type: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? {
|
||||
|
|
|
@ -40,4 +40,3 @@ public func stopMacOSHook(callback: EventCallback) -> UnsafePointer<CChar>? {
|
|||
public func macosHookRunning() -> Bool {
|
||||
return hook != nil;
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue