diff --git a/Blink/Info.plist b/Blink/Info.plist index 8c68ecf2d..9a7217bc6 100644 --- a/Blink/Info.plist +++ b/Blink/Info.plist @@ -167,7 +167,7 @@ Blink.WhatsNewSceneDelegate - UIWindowSceneSessionRoleExternalDisplay + UIWindowSceneSessionRoleExternalDisplayNonInteractive UISceneConfigurationName diff --git a/Blink/LayoutManager.m b/Blink/LayoutManager.m index 2bfb4b835..60f30e395 100644 --- a/Blink/LayoutManager.m +++ b/Blink/LayoutManager.m @@ -56,7 +56,7 @@ + (BKLayoutMode) deviceDefaultLayoutMode { + (UIEdgeInsets) buildSafeInsetsForController:(UIViewController *)ctrl andMode:(BKLayoutMode) mode { UIWindow *window = ctrl.view.window; - if (window == ShadowWindow.shared || window.windowScene.session.role == UIWindowSceneSessionRoleExternalDisplay) { + if (window == ShadowWindow.shared || window.windowScene.session.role == UIWindowSceneSessionRoleExternalDisplayNonInteractive) { // we are on external monitor, so we use device margins to accomodate overscan and ignore mode // it is like BKLayoutModeSafeFit mode return ShadowWindow.shared.refWindow.safeAreaInsets; diff --git a/Blink/SceneDelegate.swift b/Blink/SceneDelegate.swift index b6914fcdf..028c50098 100644 --- a/Blink/SceneDelegate.swift +++ b/Blink/SceneDelegate.swift @@ -239,7 +239,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { _spCtrl.sceneRole = session.role _spCtrl.restoreWith(stateRestorationActivity: session.stateRestorationActivity) - if session.role == .windowExternalDisplay, + if session.role == .windowExternalDisplayNonInteractive, let mainScene = UIApplication.shared.connectedScenes.activeAppScene() { if BLKDefaults.overscanCompensation() == .BKBKOverscanCompensationMirror { @@ -287,36 +287,46 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } } - func sceneDidBecomeActive(_ scene: UIScene) { - - guard let window = window else { + private func _lockNonInteractiveScreenIfNeeded() { + guard + let window = ShadowWindow.shared?.refWindow, + let sceneDelegate = window.windowScene?.delegate as? SceneDelegate + else { return } - if (scene.session.role == .windowExternalDisplay) { - if LocalAuth.shared.lockRequired { - if let lockCtrl = _lockCtrl { - if window.rootViewController != lockCtrl { - window.rootViewController = lockCtrl - } - - return + if LocalAuth.shared.lockRequired { + if let lockCtrl = sceneDelegate._lockCtrl { + if window.rootViewController != lockCtrl { + window.rootViewController = lockCtrl } - - _lockCtrl = UIHostingController(rootView: LockView(unlockAction: nil)) - window.rootViewController = _lockCtrl return } - if window.rootViewController == _lockCtrl { - window.rootViewController = UIViewController() - } - _lockCtrl = nil - if let shadowWin = ShadowWindow.shared { - window.layer.addSublayer(shadowWin.layer) - } + sceneDelegate._lockCtrl = UIHostingController(rootView: LockView(unlockAction: nil)) + window.rootViewController = _lockCtrl + return + } + + + if window.rootViewController == _lockCtrl { + window.rootViewController = UIViewController() + } + _lockCtrl = nil + + if let shadowWin = ShadowWindow.shared { + window.layer.addSublayer(shadowWin.layer) + } + } + + func sceneDidBecomeActive(_ scene: UIScene) { + + // 0. Local Auth AutoLock Check on old screens + _lockNonInteractiveScreenIfNeeded() + + guard let window = window else { return } diff --git a/Blink/SpaceController.swift b/Blink/SpaceController.swift index 17824b68a..a84e142f0 100644 --- a/Blink/SpaceController.swift +++ b/Blink/SpaceController.swift @@ -304,7 +304,7 @@ class SpaceController: UIViewController { #endif - if scene.session.role == .windowExternalDisplay, + if scene.session.role == .windowExternalDisplayNonInteractive, let sharedWindow = ShadowWindow.shared, sharedWindow === view.window, let ctrl = sharedWindow.spaceController.currentTerm() { @@ -787,7 +787,7 @@ extension SpaceController { return } - sessions = sessions.filter { $0.role != .windowExternalDisplay } + sessions = sessions.filter { $0.role != .windowExternalDisplayNonInteractive } let nextSession: UISceneSession if idx < sessions.endIndex { @@ -838,7 +838,7 @@ extension SpaceController { return } - sessions = sessions.filter { $0.role != .windowExternalDisplay } + sessions = sessions.filter { $0.role != .windowExternalDisplayNonInteractive } let nextSession: UISceneSession if idx < sessions.endIndex { @@ -944,13 +944,12 @@ extension SpaceController { return } self.presentSnippetsController() - if let _ = _blinkMenu { + if let _ = self._interactiveSpaceController()._blinkMenu { self.toggleQuickActionsAction() } } - @objc func toggleQuickActionsAction() { - + private func _toggleQuickActionActionWith(receiver: SpaceController) { if let menu = _blinkMenu { _blinkMenu = nil UIView.animate(withDuration: 0.15) { @@ -973,7 +972,7 @@ extension SpaceController { ids.append(contentsOf: [.layoutMenu]) } ids.append(contentsOf: [.toggleLayoutLock, .toggleGeoTrack]) - menu.delegate = self; + menu.delegate = receiver; menu.build(withIDs: ids, andAppearance: [:]) _blinkMenu = menu self.view.addSubview(menu) @@ -988,7 +987,23 @@ extension SpaceController { menu.frame = finalMenuFrame } } - + } + + func _interactiveSpaceController() -> SpaceController { + if let shadowWin = ShadowWindow.shared, + self.view.window == shadowWin, + let mainScreenSession = _activeSessions() + .first(where: {$0.role == .windowApplication }), + let delegate = mainScreenSession.scene?.delegate as? SceneDelegate + { + return delegate.spaceController + } + return self + } + + @objc func toggleQuickActionsAction() { + _interactiveSpaceController() + ._toggleQuickActionActionWith(receiver: self) } @objc func toggleGeoTrack() { @@ -1139,27 +1154,39 @@ extension SpaceController: CommandsHUDDelegate { } extension SpaceController: SnippetContext { - func presentSnippetsController() { + + func _presentSnippetsController(receiver: SpaceController) { do { - let ctrl = try SnippetsViewController.create(context: self, transitionFrame: _blinkMenu?.bounds) - ctrl.view.frame = self.view.bounds - ctrl.willMove(toParent: self) - self.view.addSubview(ctrl.view) - self.addChild(ctrl) - ctrl.didMove(toParent: self) - _snippetsVC = ctrl + self.view.window?.makeKeyAndVisible() + let ctrl = try SnippetsViewController.create(context: receiver, transitionFrame: _blinkMenu?.bounds) + DispatchQueue.main.async { + ctrl.view.frame = self.view.bounds + ctrl.willMove(toParent: self) + self.view.addSubview(ctrl.view) + self.addChild(ctrl) + ctrl.didMove(toParent: self) + self._snippetsVC = ctrl + } } catch { self.showAlert(msg: "Could not display Snips: \(error)") } } + func presentSnippetsController() { + _interactiveSpaceController()._presentSnippetsController(receiver: self) + } + + func _dismissSnippetsController(ctrl: SpaceController) { + ctrl.presentedViewController?.dismiss(animated: true) + ctrl._snippetsVC?.willMove(toParent: nil) + ctrl._snippetsVC?.view.removeFromSuperview() + ctrl._snippetsVC?.removeFromParent() + ctrl._snippetsVC?.didMove(toParent: nil) + ctrl._snippetsVC = nil + } + func dismissSnippetsController() { - self.presentedViewController?.dismiss(animated: true) - self._snippetsVC?.willMove(toParent: nil) - self._snippetsVC?.view.removeFromSuperview() - self._snippetsVC?.removeFromParent() - self._snippetsVC?.didMove(toParent: nil) - self._snippetsVC = nil + _dismissSnippetsController(ctrl: _interactiveSpaceController()) self.focusOnShellAction() } @@ -1169,3 +1196,5 @@ extension SpaceController: SnippetContext { } } + + diff --git a/Blink/TermController.swift b/Blink/TermController.swift index c210783df..6c5f06fc9 100644 --- a/Blink/TermController.swift +++ b/Blink/TermController.swift @@ -164,7 +164,7 @@ class TermController: UIViewController { convenience init(sceneRole: UISceneSession.Role? = nil) { self.init(meta: nil) - if sceneRole == .windowExternalDisplay { + if sceneRole == .windowExternalDisplayNonInteractive { _sessionParams.fontSize = BLKDefaults.selectedExternalDisplayFontSize()?.intValue ?? 24 } }