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:
parent
bf77d77669
commit
364f3a7639
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue