Skip to content

Commit

Permalink
Fix build failure
Browse files Browse the repository at this point in the history
  • Loading branch information
duraidabdul committed Oct 17, 2022
1 parent bfc3bc4 commit 1dcb6e3
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions Sources/LocalConsole/LCManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {

/// Adds a consoleViewController to the app's main window.
func configureConsoleViewController() {
var windowSceneFound = false
var windowFound = false

// Update console cached based on last-cached origin.
func updateConsoleOrigin() {
Expand All @@ -373,26 +373,34 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
}

// Configure console window.
func fetchWindowScene() {
let windowScene = UIApplication.shared
.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first

if let windowScene = windowScene as? UIWindowScene, let keyWindow = windowScene.keyWindow {
windowSceneFound = true
func fetchWindow() -> UIWindow? {
if #available(iOS 15.0, *) {
let windowScene = UIApplication.shared
.connectedScenes
.filter { $0.activationState == .foregroundActive }
.first

SwizzleTool().swizzleContextMenuReverseOrder()

consoleViewController.view = PassthroughView()
consoleViewController.view.addSubview(consoleView)

keyWindow.addSubview(consoleViewController.view)
consoleViewController.view.frame = keyWindow.bounds
consoleViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

updateConsoleOrigin()
if let windowScene = windowScene as? UIWindowScene, let keyWindow = windowScene.keyWindow {
return keyWindow
}
return nil
} else {
return UIApplication.shared.windows.first
}

}

func addConsoleToWindow(window: UIWindow) {
SwizzleTool().swizzleContextMenuReverseOrder()

consoleViewController.view = PassthroughView()
consoleViewController.view.addSubview(consoleView)

window.addSubview(consoleViewController.view)
consoleViewController.view.frame = window.bounds
consoleViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

updateConsoleOrigin()
}

/// Ensures the window is configured (i.e. scene has been found). If not, delay and wait for a scene to prepare itself, then try again.
Expand All @@ -401,9 +409,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {

DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [self] in

guard !windowSceneFound else { return }
guard !windowFound else { return }

fetchWindowScene()
if let window = fetchWindow() {
windowFound = true
addConsoleToWindow(window: window)
}

if isVisible {
isVisible = false
Expand Down

0 comments on commit 1dcb6e3

Please sign in to comment.