fix: application blocks on start

v1
paring 2023-05-28 17:25:15 +09:00
parent de06cc1a32
commit 0f3a057fd4
Signed by: pikokr
GPG Key ID: 8C7ABCEF704FD728
3 changed files with 9 additions and 7 deletions

View File

@ -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
}
}
}
}

View File

@ -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>? {

View File

@ -40,4 +40,3 @@ public func stopMacOSHook(callback: EventCallback) -> UnsafePointer<CChar>? {
public func macosHookRunning() -> Bool {
return hook != nil;
}