Skip to content

Commit 7ef5fa5

Browse files
committed
Fix hang detection
1 parent 601e88e commit 7ef5fa5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Clop/ErrorReports.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Cocoa
12
import Combine
23
import Defaults
34
import Lowtech
@@ -91,6 +92,7 @@ private let appHangStateQueue = DispatchQueue(label: "com.lowtechguys.Clop.appHa
9192
@MainActor private var appHangTimer: DispatchSourceTimer?
9293
private var lastMainThreadCheckin: TimeInterval = 0
9394
private var appHangTriggered = false
95+
private var sleeping = false
9496

9597
@MainActor func configureAppHangDetection() {
9698
guard appHangTimer == nil else {
@@ -102,7 +104,7 @@ private var appHangTriggered = false
102104
appHangTriggered = false
103105
}
104106

105-
let timer = DispatchSource.makeTimerSource(queue: DispatchQueue.global(qos: .background))
107+
let timer = DispatchSource.makeTimerSource(queue: DispatchQueue.global(qos: .userInteractive))
106108
timer.schedule(
107109
deadline: .now() + APP_HANG_CHECK_INTERVAL,
108110
repeating: APP_HANG_CHECK_INTERVAL,
@@ -113,7 +115,7 @@ private var appHangTriggered = false
113115
var shouldTrigger = false
114116

115117
appHangStateQueue.sync {
116-
if !appHangTriggered, now - lastMainThreadCheckin > APP_HANG_DETECTION_INTERVAL {
118+
if !appHangTriggered, !sleeping, now - lastMainThreadCheckin > APP_HANG_DETECTION_INTERVAL {
117119
appHangTriggered = true
118120
shouldTrigger = true
119121
}
@@ -131,6 +133,23 @@ private var appHangTriggered = false
131133
}
132134
appHangTimer = timer
133135
timer.resume()
136+
137+
let nc = NSWorkspace.shared.notificationCenter
138+
nc.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: nil) { _ in
139+
appHangStateQueue.sync {
140+
lastMainThreadCheckin = Date().timeIntervalSince1970
141+
sleeping = true
142+
appHangTriggered = false
143+
}
144+
}
145+
nc.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: nil) { _ in
146+
let now = Date().timeIntervalSince1970
147+
appHangStateQueue.sync {
148+
lastMainThreadCheckin = now
149+
sleeping = false
150+
appHangTriggered = false
151+
}
152+
}
134153
}
135154

136155
private func mainThreadStack(from sampleOutput: String) -> String {

ReleaseNotes/2.11.3.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Fixes
2+
3+
- Fix keyboard shortcuts modifiers not working correctly
4+
- Fix iCloud watched files being duplicated or optimised in a loop in specific scenarios ([#71](https://github.com/FuzzyIdeas/Clop/pull/71))

0 commit comments

Comments
 (0)