Skip to content

Commit

Permalink
Fix crash when closing the macos app from full screen
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Feb 1, 2024
1 parent 3ebd1e6 commit f1fd1e6
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Sources/App/Scenes/WindowSizeObserver.swift
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import Foundation
import Shared
import UIKit

final class WindowSizeObserver: NSObject {
@objc private(set) var observedScene: UIWindowScene?
private var observation: NSKeyValueObservation?
private weak var observation: NSKeyValueObservation?

init(windowScene: UIWindowScene) {
self.observedScene = windowScene
super.init()
#if targetEnvironment(macCatalyst)

guard Current.isCatalyst else { return }
startObserving()
#endif
}

private func startObserving() {
#if targetEnvironment(macCatalyst)
guard #available(macCatalyst 16.0, *) else { return }
observation = observe(\.observedScene?.effectiveGeometry, options: [.new]) { _, change in

Check failure on line 19 in Sources/App/Scenes/WindowSizeObserver.swift

View workflow job for this annotation

GitHub Actions / test

'effectiveGeometry' is only available in iOS 16.0 or newer

Check failure on line 19 in Sources/App/Scenes/WindowSizeObserver.swift

View workflow job for this annotation

GitHub Actions / test

'effectiveGeometry' is only available in iOS 16.0 or newer
guard let newSystemFrame = change.newValue??.systemFrame,

Check failure on line 20 in Sources/App/Scenes/WindowSizeObserver.swift

View workflow job for this annotation

GitHub Actions / test

'systemFrame' is unavailable in iOS

Check failure on line 20 in Sources/App/Scenes/WindowSizeObserver.swift

View workflow job for this annotation

GitHub Actions / test

'systemFrame' is unavailable in iOS
newSystemFrame.size != .zero, newSystemFrame.origin != .zero else { return }
ScenesWindowSizeConfig.defaultSceneLatestSystemFrame = newSystemFrame
}
#endif
}
}

Expand Down

0 comments on commit f1fd1e6

Please sign in to comment.