fix: rare crash at launch
This commit is contained in:
1 parent
a7247da478
commit
461840ef3d
3 files changed
+8
-12
No files matched your search
@@ -10,18 +10,14 @@ class MouseEvents {
|
||||
observe_()
|
||||
}
|
||||
|
||||
static func disable() {
|
||||
shouldBeEnabled = false
|
||||
CGEvent.tapEnable(tap: eventTap, enable: false)
|
||||
}
|
||||
|
||||
static func enable() {
|
||||
shouldBeEnabled = true
|
||||
CGEvent.tapEnable(tap: eventTap, enable: true)
|
||||
static func toggle(_ enabled: Bool) {
|
||||
shouldBeEnabled = enabled
|
||||
if let eventTap = eventTap {
|
||||
CGEvent.tapEnable(tap: eventTap, enable: enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func observe_() {
|
||||
let eventMask = [CGEventType.leftMouseDown, CGEventType.leftMouseUp].reduce(CGEventMask(0), { $0 | (1 << $1.rawValue) })
|
||||
// CGEvent.tapCreate returns null if ensureAccessibilityCheckboxIsChecked() didn't pass
|
||||
@@ -32,7 +28,7 @@ private func observe_() {
|
||||
eventsOfInterest: eventMask,
|
||||
callback: mouseHandler,
|
||||
userInfo: nil)
|
||||
MouseEvents.disable()
|
||||
MouseEvents.toggle(false)
|
||||
let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0)
|
||||
CFRunLoopAddSource(BackgroundWork.mouseEventsThread.runLoop, runLoopSource, .commonModes)
|
||||
}
|
||||
|
||||
+1
-1
@@ -135,7 +135,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
debugPrint("hideUi")
|
||||
appIsBeingUsed = false
|
||||
isFirstSummon = true
|
||||
MouseEvents.disable()
|
||||
MouseEvents.toggle(false)
|
||||
thumbnailsPanel.orderOut(nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class ThumbnailsPanel: NSPanel {
|
||||
|
||||
func show() {
|
||||
orderFrontRegardless()
|
||||
MouseEvents.enable()
|
||||
MouseEvents.toggle(true)
|
||||
thumbnailsView.scrollView.flashScrollers()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user