From 3c2683c6bfcc93c25ab8308a3d95610f09ebe767 Mon Sep 17 00:00:00 2001 From: Duraid Abdul Date: Wed, 1 Sep 2021 19:04:56 -0600 Subject: [PATCH] Update LCManager.swift --- Sources/LocalConsole/LCManager.swift | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Sources/LocalConsole/LCManager.swift b/Sources/LocalConsole/LCManager.swift index bd41850..3cbe487 100644 --- a/Sources/LocalConsole/LCManager.swift +++ b/Sources/LocalConsole/LCManager.swift @@ -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 @@ -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 { @@ -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 - } } } }