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