Skip to content

Commit

Permalink
Update LCManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
duraidabdul committed Sep 2, 2021
1 parent fd11148 commit 3c2683c
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions Sources/LocalConsole/LCManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,20 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
func configureWindow() {
var windowSceneFound = false

// Update console cached based on last-cached origin.
func updateConsoleOrigin() {
let cachedConsolePosition = CGPoint(x: UserDefaults.standard.object(forKey: "LocalConsole_X") as? CGFloat ?? possibleEndpoints.first!.x,
y: UserDefaults.standard.object(forKey: "LocalConsole_Y") as? CGFloat ?? possibleEndpoints.first!.y)

consoleView.center = cachedConsolePosition // Update console center so possibleEndpoints are calculated correctly.
consoleView.center = nearestTargetTo(cachedConsolePosition, possibleTargets: possibleEndpoints)

if consoleView.center.x < 0 || consoleView.center.x > UIScreen.portraitSize.width {
grabberMode = true
scrollLocked = !grabberMode
}
}

// Configure console window.
func fetchWindowScene() {
let windowScene = UIApplication.shared
Expand All @@ -326,11 +340,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
consoleWindow?.addSubview(consoleView)

UIWindow.swizzleStatusBarAppearanceOverride

updateConsoleOrigin()
}
}

fetchWindowScene()

/// 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.
for i in 1...10 {

Expand All @@ -347,16 +361,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
consoleView.layer.removeAllAnimations()
isVisible = true
}

let cachedConsolePosition = CGPoint(x: UserDefaults.standard.object(forKey: "LocalConsole_X") as? CGFloat ?? possibleEndpoints.first!.x,
y: UserDefaults.standard.object(forKey: "LocalConsole_Y") as? CGFloat ?? possibleEndpoints.first!.y)
consoleView.center = cachedConsolePosition // Update console center so possibleEndpoints are calculated correctly.
consoleView.center = nearestTargetTo(cachedConsolePosition, possibleTargets: possibleEndpoints)

if consoleView.center.x < 0 || consoleView.center.x > UIScreen.portraitSize.width {
grabberMode = true
scrollLocked = !grabberMode
}
}
}
}
Expand Down

0 comments on commit 3c2683c

Please sign in to comment.