|
|
|
@@ -155,13 +155,14 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
var scrollLocked = true
|
|
|
|
|
|
|
|
|
|
/// Feedback generator for the long press action.
|
|
|
|
|
lazy var feedbackGenerator = UISelectionFeedbackGenerator()
|
|
|
|
|
lazy var feedbackGenerator = UIImpactFeedbackGenerator(style: .soft)
|
|
|
|
|
|
|
|
|
|
lazy var panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(consolePiPPanner(recognizer:)))
|
|
|
|
|
lazy var longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(recognizer:)))
|
|
|
|
|
|
|
|
|
|
/// Gesture endpoints. Each point represents a corner of the screen. TODO: Handle screen rotation.
|
|
|
|
|
var possibleEndpoints: [CGPoint] {
|
|
|
|
|
guard let consoleWindow = consoleWindow else { return [] }
|
|
|
|
|
|
|
|
|
|
let screenSize = viewController.view.frame.size
|
|
|
|
|
|
|
|
|
@@ -169,32 +170,31 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
let isPortraitNotchedPhone = UIDevice.current.hasNotch && viewController.view.frame.size.width < viewController.view.frame.size.height
|
|
|
|
|
|
|
|
|
|
// Fix incorrect reported orientation on phone.
|
|
|
|
|
let isLandscapePhone = (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) && UIDevice.current.userInterfaceIdiom == .phone
|
|
|
|
|
let isLandscapePhone = UIDevice.current.userInterfaceIdiom == .phone && viewController.view.frame.width > viewController.view.frame.height
|
|
|
|
|
|
|
|
|
|
let isLandscapeLeftNotchedPhone = UIDevice.current.orientation == .landscapeLeft
|
|
|
|
|
&& UIDevice.current.userInterfaceIdiom == .phone
|
|
|
|
|
&& UIDevice.current.hasNotch
|
|
|
|
|
&& isLandscapePhone
|
|
|
|
|
|
|
|
|
|
let isLandscapeRightNotchedPhone = UIDevice.current.orientation == .landscapeRight
|
|
|
|
|
&& UIDevice.current.userInterfaceIdiom == .phone
|
|
|
|
|
&& UIDevice.current.hasNotch
|
|
|
|
|
&& isLandscapePhone
|
|
|
|
|
|
|
|
|
|
let leftEndpointX = consoleSize.width / 2 + consoleWindow.safeAreaInsets.left + (isLandscapePhone ? 4 : 12) + (isLandscapeRightNotchedPhone ? -16 : 0)
|
|
|
|
|
let rightEndpointX = screenSize.width - (consoleSize.width / 2 + consoleWindow.safeAreaInsets.right) - (isLandscapePhone ? 4 : 12) + (isLandscapeLeftNotchedPhone ? 16 : 0)
|
|
|
|
|
let topEndpointY = consoleSize.height / 2 + consoleWindow.safeAreaInsets.top + 12 + (isPortraitNotchedPhone ? -10 : 0)
|
|
|
|
|
let bottomEndpointY = screenSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow.safeAreaInsets.bottom) - 12 + (isLandscapePhone ? 10 : 0)
|
|
|
|
|
|
|
|
|
|
if consoleSize.width < screenSize.width - 112 {
|
|
|
|
|
|
|
|
|
|
// Four endpoints, one for each corner.
|
|
|
|
|
var endpoints = [
|
|
|
|
|
|
|
|
|
|
// Top endpoints.
|
|
|
|
|
CGPoint(x: consoleSize.width / 2 + 12 + (isLandscapeLeftNotchedPhone ? 40 : isLandscapePhone ? 12 : 0),
|
|
|
|
|
y: (isPortraitNotchedPhone ? 38 : isLandscapePhone ? 0 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
CGPoint(x: screenSize.width - consoleSize.width / 2 - 12 - (isLandscapeRightNotchedPhone ? 40 : isLandscapePhone ? 12 : 0),
|
|
|
|
|
y: (isPortraitNotchedPhone ? 38 : isLandscapePhone ? 0 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
|
|
|
|
|
// Bottom endpoints.
|
|
|
|
|
CGPoint(x: consoleSize.width / 2 + 12 + (isLandscapeLeftNotchedPhone ? 40 : isLandscapePhone ? 12 : 0),
|
|
|
|
|
y: screenSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12),
|
|
|
|
|
CGPoint(x: screenSize.width - consoleSize.width / 2 - 12 - (isLandscapeRightNotchedPhone ? 40 : isLandscapePhone ? 12 : 02),
|
|
|
|
|
y: screenSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
|
|
|
|
CGPoint(x: leftEndpointX, y: topEndpointY),
|
|
|
|
|
CGPoint(x: rightEndpointX, y: topEndpointY),
|
|
|
|
|
CGPoint(x: leftEndpointX, y: bottomEndpointY),
|
|
|
|
|
CGPoint(x: rightEndpointX, y: bottomEndpointY),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if consoleView.frame.minX <= 0 {
|
|
|
|
|
|
|
|
|
@@ -231,12 +231,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
return endpoints
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// Two endpoints, one for the top, one for the bottom..
|
|
|
|
|
var endpoints = [CGPoint(x: screenSize.width / 2,
|
|
|
|
|
y: (UIScreen.hasRoundedCorners ? 38 : 16) + consoleSize.height / 2 + 12),
|
|
|
|
|
CGPoint(x: screenSize.width / 2,
|
|
|
|
|
y: screenSize.height - consoleSize.height / 2 - (keyboardHeight ?? consoleWindow?.safeAreaInsets.bottom ?? 0) - 12)]
|
|
|
|
|
var endpoints = [
|
|
|
|
|
CGPoint(x: screenSize.width / 2, y: topEndpointY),
|
|
|
|
|
CGPoint(x: screenSize.width / 2, y: bottomEndpointY)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if consoleView.frame.minX <= 0 {
|
|
|
|
|
|
|
|
|
@@ -281,10 +280,12 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
let _ = lumaView
|
|
|
|
|
|
|
|
|
|
borderView.frame = CGRect(x: -1, y: -1,
|
|
|
|
|
width: consoleSize.width + 2,
|
|
|
|
|
height: consoleSize.height + 2)
|
|
|
|
|
borderView.layer.borderWidth = 1
|
|
|
|
|
let borderWidth = 2 - 1 / consoleView.traitCollection.displayScale
|
|
|
|
|
|
|
|
|
|
borderView.frame = CGRect(x: -borderWidth, y: -borderWidth,
|
|
|
|
|
width: consoleSize.width + 2 * borderWidth,
|
|
|
|
|
height: consoleSize.height + 2 * borderWidth)
|
|
|
|
|
borderView.layer.borderWidth = borderWidth
|
|
|
|
|
borderView.layer.borderColor = UIColor(white: 1, alpha: 0.08).cgColor
|
|
|
|
|
borderView.layer.cornerRadius = consoleView.layer.cornerRadius + 1
|
|
|
|
|
borderView.layer.cornerCurve = .continuous
|
|
|
|
@@ -383,9 +384,11 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
.first
|
|
|
|
|
|
|
|
|
|
if let windowScene = windowScene as? UIWindowScene {
|
|
|
|
|
|
|
|
|
|
windowSceneFound = true
|
|
|
|
|
|
|
|
|
|
UIWindow.swizzleStatusBarAppearanceOverride()
|
|
|
|
|
SwizzleTool().swizzleContextMenuReverseOrder()
|
|
|
|
|
|
|
|
|
|
consoleWindow = ConsoleWindow(windowScene: windowScene)
|
|
|
|
|
consoleWindow?.frame = UIScreen.main.bounds
|
|
|
|
|
consoleWindow?.windowLevel = UIWindow.Level.statusBar
|
|
|
|
@@ -397,9 +400,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
viewController.view.addSubview(consoleView)
|
|
|
|
|
|
|
|
|
|
UIWindow.swizzleStatusBarAppearanceOverride
|
|
|
|
|
SwizzleTool().swizzleContextMenuReverseOrder()
|
|
|
|
|
|
|
|
|
|
updateConsoleOrigin()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -483,7 +483,6 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
guard oldValue != grabberMode else { return }
|
|
|
|
|
|
|
|
|
|
if grabberMode {
|
|
|
|
|
|
|
|
|
|
lumaView.layer.cornerRadius = consoleView.layer.cornerRadius
|
|
|
|
|
lumaHeightAnchor.constant = consoleView.frame.size.height
|
|
|
|
|
consoleView.layoutIfNeeded()
|
|
|
|
@@ -501,7 +500,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
lumaWidthAnchor.constant = -34
|
|
|
|
|
lumaHeightAnchor.constant = 96
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.4, dampingRatio: 1) { [self] in
|
|
|
|
|
lumaView.layer.cornerRadius = 8
|
|
|
|
|
lumaView.layer.cornerRadius = 9
|
|
|
|
|
consoleView.layoutIfNeeded()
|
|
|
|
|
}.startAnimation(afterDelay: 0.06)
|
|
|
|
|
|
|
|
|
@@ -581,10 +580,9 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
// MARK: Handle keyboard show/hide.
|
|
|
|
|
private var keyboardHeight: CGFloat? = nil {
|
|
|
|
|
didSet {
|
|
|
|
|
|
|
|
|
|
temporaryKeyboardHeightValueTracker = oldValue
|
|
|
|
|
|
|
|
|
|
if consoleView.center != possibleEndpoints[0] && consoleView.center != possibleEndpoints[1] {
|
|
|
|
|
if possibleEndpoints.count > 2, consoleView.center != possibleEndpoints[0] && consoleView.center != possibleEndpoints[1] {
|
|
|
|
|
let nearestTargetPosition = nearestTargetTo(consoleView.center, possibleTargets: possibleEndpoints.suffix(2))
|
|
|
|
|
|
|
|
|
|
UIViewPropertyAnimator(duration: 0.55, dampingRatio: 1) {
|
|
|
|
@@ -716,13 +714,20 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
if currentText != "" { print("\n") }
|
|
|
|
|
|
|
|
|
|
let safeAreaInsets = consoleWindow?.safeAreaInsets ?? .zero
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
"""
|
|
|
|
|
Screen Size: \(UIScreen.main.bounds.size)
|
|
|
|
|
Screen Corner Radius: \(UIScreen.main.value(forKey: "_displ" + "ayCorn" + "erRa" + "dius") as! CGFloat)
|
|
|
|
|
Screen Scale: \(UIScreen.main.scale)
|
|
|
|
|
Max Frame Rate: \(UIScreen.main.maximumFramesPerSecond) Hz
|
|
|
|
|
Brightness: \(String(format: "%.2f", UIScreen.main.brightness))
|
|
|
|
|
Screen Size: \(UIScreen.main.bounds.size)
|
|
|
|
|
Corner Radius: \(UIScreen.main.value(forKey: "_displ" + "ayCorn" + "erRa" + "dius") as! CGFloat)
|
|
|
|
|
Screen Scale: \(UIScreen.main.scale)
|
|
|
|
|
Max Frame Rate: \(UIScreen.main.maximumFramesPerSecond) Hz
|
|
|
|
|
Brightness: \(String(format: "%.2f", UIScreen.main.brightness))
|
|
|
|
|
|
|
|
|
|
Safe Area Insets: top: \(String(describing: safeAreaInsets.top))
|
|
|
|
|
left: \(String(describing: safeAreaInsets.left))
|
|
|
|
|
bottom: \(String(describing: safeAreaInsets.bottom))
|
|
|
|
|
right: \(String(describing: safeAreaInsets.right))
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
@@ -765,7 +770,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
func makeMenu() -> UIMenu {
|
|
|
|
|
|
|
|
|
|
let share = UIAction(title: "Share",
|
|
|
|
|
let share = UIAction(title: "Share Text...",
|
|
|
|
|
image: UIImage(systemName: "square.and.arrow.up"), handler: { _ in
|
|
|
|
|
let activityViewController = UIActivityViewController(activityItems: [self.consoleTextView.text ?? ""],
|
|
|
|
|
applicationActivities: nil)
|
|
|
|
@@ -1006,7 +1011,7 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
guard !grabberMode else { return }
|
|
|
|
|
|
|
|
|
|
feedbackGenerator.selectionChanged()
|
|
|
|
|
feedbackGenerator.impactOccurred(intensity: 1)
|
|
|
|
|
|
|
|
|
|
scrollLocked = false
|
|
|
|
|
|
|
|
|
@@ -1173,28 +1178,19 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
|
|
|
|
|
|
|
|
|
// Custom window for the console to appear above other windows while passing touches down.
|
|
|
|
|
class ConsoleWindow: UIWindow {
|
|
|
|
|
|
|
|
|
|
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
|
|
|
|
|
|
|
|
if let hitView = super.hitTest(point, with: event) {
|
|
|
|
|
return hitView.isKind(of: ConsoleWindow.self) ? nil : hitView
|
|
|
|
|
}
|
|
|
|
|
return super.hitTest(point, with: event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Custom view for the console to appear above other windows while passing touches down.
|
|
|
|
|
class PassthroughView: UIView {
|
|
|
|
|
|
|
|
|
|
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
|
|
|
|
|
|
|
|
if let hitView = super.hitTest(point, with: event) {
|
|
|
|
|
return hitView.isKind(of: PassthroughView.self) ? nil : hitView
|
|
|
|
|
if hitView.isKind(of: PassthroughView.self) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return hitView
|
|
|
|
|
}
|
|
|
|
|
return super.hitTest(point, with: event)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Custom view that is passed through if it is the returned hitTest for ConsoleWindow.
|
|
|
|
|
class PassthroughView: UIView { }
|
|
|
|
|
|
|
|
|
|
import UIKit.UIGestureRecognizerSubclass
|
|
|
|
|
|
|
|
|
@@ -1231,12 +1227,13 @@ extension UIView {
|
|
|
|
|
extension UIWindow {
|
|
|
|
|
|
|
|
|
|
/// Make sure this window does not have control over the status bar appearance.
|
|
|
|
|
static let swizzleStatusBarAppearanceOverride: Void = {
|
|
|
|
|
static func swizzleStatusBarAppearanceOverride() {
|
|
|
|
|
guard let originalMethod = class_getInstanceMethod(UIWindow.self, NSSelectorFromString("_can" + "Affect" + "Status" + "Bar" + "Appearance")),
|
|
|
|
|
let swizzledMethod = class_getInstanceMethod(UIWindow.self, #selector(swizzled_statusBarAppearance))
|
|
|
|
|
else { return }
|
|
|
|
|
|
|
|
|
|
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc func swizzled_statusBarAppearance() -> Bool {
|
|
|
|
|
return isKeyWindow
|
|
|
|
@@ -1273,41 +1270,56 @@ class SwizzleTool: NSObject {
|
|
|
|
|
class LumaView: UIView {
|
|
|
|
|
lazy var visualEffectView: UIView = {
|
|
|
|
|
Bundle(path: "/Sys" + "tem/Lib" + "rary/Private" + "Framework" + "s/Material" + "Kit." + "framework")!.load()
|
|
|
|
|
|
|
|
|
|
let Pill = NSClassFromString("MT" + "Luma" + "Dodge" + "Pill" + "View") as! UIView.Type
|
|
|
|
|
|
|
|
|
|
let pillView = Pill.init()
|
|
|
|
|
|
|
|
|
|
enum Style: Int {
|
|
|
|
|
case none = 0
|
|
|
|
|
case thin = 1
|
|
|
|
|
case gray = 2
|
|
|
|
|
case black = 3
|
|
|
|
|
case white = 4
|
|
|
|
|
|
|
|
|
|
if let Pill = NSClassFromString("MT" + "Luma" + "Dodge" + "Pill" + "View") as? UIView.Type {
|
|
|
|
|
|
|
|
|
|
let pillView = Pill.init()
|
|
|
|
|
|
|
|
|
|
enum Style: Int {
|
|
|
|
|
case none = 0
|
|
|
|
|
case thin = 1
|
|
|
|
|
case gray = 2
|
|
|
|
|
case black = 3
|
|
|
|
|
case white = 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum BackgroundLuminance: Int {
|
|
|
|
|
case unknown = 0
|
|
|
|
|
case dark = 1
|
|
|
|
|
case light = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pillView.setValue(2, forKey: "style")
|
|
|
|
|
pillView.setValue(1, forKey: "background" + "Luminance")
|
|
|
|
|
pillView.perform(NSSelectorFromString("_" + "update" + "Style"))
|
|
|
|
|
|
|
|
|
|
addSubview(pillView)
|
|
|
|
|
|
|
|
|
|
pillView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
pillView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
|
pillView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
|
pillView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
|
|
pillView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return pillView
|
|
|
|
|
} else {
|
|
|
|
|
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterialDark))
|
|
|
|
|
addSubview(visualEffectView)
|
|
|
|
|
|
|
|
|
|
visualEffectView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
visualEffectView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
|
visualEffectView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
|
visualEffectView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
|
|
visualEffectView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return visualEffectView
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum BackgroundLuminance: Int {
|
|
|
|
|
case unknown = 0
|
|
|
|
|
case dark = 1
|
|
|
|
|
case light = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pillView.setValue(2, forKey: "style")
|
|
|
|
|
pillView.setValue(1, forKey: "background" + "Luminance")
|
|
|
|
|
pillView.perform(NSSelectorFromString("_" + "update" + "Style"))
|
|
|
|
|
|
|
|
|
|
addSubview(pillView)
|
|
|
|
|
|
|
|
|
|
pillView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
pillView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
|
|
pillView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
|
|
pillView.topAnchor.constraint(equalTo: topAnchor),
|
|
|
|
|
pillView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
return pillView
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
lazy var foregroundView: UIView = {
|
|
|
|
|