Prevent infinite loop in DetailWebView.setFrameSize()

DetailWebView.setFrameSize() calls bigSurOffsetFix(), which changes the window's frame, which ultimately calls setFrameSize() again (which calls bigSurOffsetFix(), etc). In practice, this isn't causing an infinite loop (I think NSWindow.setFrame(_:display:) is smart enough to prevent reentrancy) but it's still dangerous to have such a glaring logic error in the code.
This commit is contained in:
Chris Campbell 2021-04-30 00:52:15 -04:00
parent bf77d77669
commit 364f3a7639
No known key found for this signature in database
GPG Key ID: 77DB1B61A93AFC6C
1 changed files with 14 additions and 1 deletions

View File

@ -58,11 +58,13 @@ final class DetailWebView: WKWebView {
override func setFrameSize(_ newSize: NSSize) {
super.setFrameSize(newSize)
if (!self.inLiveResize) {
if (!inLiveResize) {
bigSurOffsetFix()
}
}
private var inBigSurOffsetFix = false
private func bigSurOffsetFix() {
/*
On macOS 11, when a user exits full screen
@ -76,6 +78,17 @@ final class DetailWebView: WKWebView {
guard var frame = window?.frame else {
return
}
guard !inBigSurOffsetFix else {
return
}
inBigSurOffsetFix = true
defer {
inBigSurOffsetFix = false
}
frame.size = NSSize(width: window!.frame.width, height: window!.frame.height - 1)
window!.setFrame(frame, display: false)
frame.size = NSSize(width: window!.frame.width, height: window!.frame.height + 1)