mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Programatically focus the main window when invoking the global search
This commit is contained in:
committed by
Stefan Ceriu
parent
a010306b41
commit
ac5b61c973
@@ -16,6 +16,6 @@ class SceneDelegate: NSObject, UIWindowSceneDelegate {
|
|||||||
|
|
||||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||||
guard let windowScene = scene as? UIWindowScene else { return }
|
guard let windowScene = scene as? UIWindowScene else { return }
|
||||||
Self.windowManager.configure(with: windowScene)
|
Self.windowManager.configure(withScene: windowScene, session: session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import SwiftUI
|
|||||||
|
|
||||||
class WindowManager: SecureWindowManagerProtocol {
|
class WindowManager: SecureWindowManagerProtocol {
|
||||||
private let appDelegate: AppDelegate
|
private let appDelegate: AppDelegate
|
||||||
weak var windowScene: UIWindowScene?
|
weak var mainScene: UIWindowScene?
|
||||||
|
weak var mainSession: UISceneSession?
|
||||||
weak var delegate: SecureWindowManagerDelegate?
|
weak var delegate: SecureWindowManagerDelegate?
|
||||||
|
|
||||||
private(set) var mainWindow: UIWindow!
|
private(set) var mainWindow: UIWindow!
|
||||||
@@ -38,28 +39,30 @@ class WindowManager: SecureWindowManagerProtocol {
|
|||||||
self.appDelegate = appDelegate
|
self.appDelegate = appDelegate
|
||||||
}
|
}
|
||||||
|
|
||||||
func configure(with windowScene: UIWindowScene) {
|
func configure(withScene scene: UIWindowScene, session: UISceneSession) {
|
||||||
// This gets called for all opened windows, we're only interested in the
|
// This gets called for all opened windows, we're only interested in the
|
||||||
// first call, for the main window (works with state restoration too).
|
// first call, for the main window (works with state restoration too).
|
||||||
guard mainWindow == nil else {
|
guard mainWindow == nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
self.windowScene = windowScene
|
mainScene = scene
|
||||||
mainWindow = windowScene.keyWindow
|
mainSession = session
|
||||||
|
|
||||||
|
mainWindow = scene.keyWindow
|
||||||
mainWindow.tintColor = .compound.textActionPrimary
|
mainWindow.tintColor = .compound.textActionPrimary
|
||||||
|
|
||||||
overlayWindow = PassthroughWindow(windowScene: windowScene)
|
overlayWindow = PassthroughWindow(windowScene: scene)
|
||||||
overlayWindow.tintColor = .compound.textActionPrimary
|
overlayWindow.tintColor = .compound.textActionPrimary
|
||||||
overlayWindow.backgroundColor = .clear
|
overlayWindow.backgroundColor = .clear
|
||||||
overlayWindow.isHidden = false
|
overlayWindow.isHidden = false
|
||||||
|
|
||||||
globalSearchWindow = UIWindow(windowScene: windowScene)
|
globalSearchWindow = UIWindow(windowScene: scene)
|
||||||
globalSearchWindow.tintColor = .compound.textActionPrimary
|
globalSearchWindow.tintColor = .compound.textActionPrimary
|
||||||
globalSearchWindow.backgroundColor = .clear
|
globalSearchWindow.backgroundColor = .clear
|
||||||
globalSearchWindow.isHidden = true
|
globalSearchWindow.isHidden = true
|
||||||
|
|
||||||
alternateWindow = UIWindow(windowScene: windowScene)
|
alternateWindow = UIWindow(windowScene: scene)
|
||||||
alternateWindow.tintColor = .compound.textActionPrimary
|
alternateWindow.tintColor = .compound.textActionPrimary
|
||||||
|
|
||||||
delegate?.windowManagerDidConfigureWindows(self)
|
delegate?.windowManagerDidConfigureWindows(self)
|
||||||
@@ -144,8 +147,15 @@ class WindowManager: SecureWindowManagerProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let mainSession {
|
||||||
|
let request = UISceneSessionActivationRequest(session: mainSession)
|
||||||
|
UIApplication.shared.activateSceneSession(for: request) { error in
|
||||||
|
MXLog.error("Failed to focus window with error: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
globalSearchWindow.isHidden = false
|
globalSearchWindow.isHidden = false
|
||||||
globalSearchWindow.makeKey()
|
globalSearchWindow.makeKeyAndVisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
func hideGlobalSearch() {
|
func hideGlobalSearch() {
|
||||||
@@ -158,7 +168,7 @@ class WindowManager: SecureWindowManagerProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setOrientation(_ orientation: UIInterfaceOrientationMask) {
|
func setOrientation(_ orientation: UIInterfaceOrientationMask) {
|
||||||
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
|
mainScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientation))
|
||||||
}
|
}
|
||||||
|
|
||||||
func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
|
func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ protocol SecureWindowManagerProtocol: WindowManagerProtocol {
|
|||||||
var delegate: SecureWindowManagerDelegate? { get set }
|
var delegate: SecureWindowManagerDelegate? { get set }
|
||||||
|
|
||||||
/// Configures the window manager to operate on the supplied scene.
|
/// Configures the window manager to operate on the supplied scene.
|
||||||
func configure(with windowScene: UIWindowScene)
|
func configure(withScene scene: UIWindowScene, session: UISceneSession)
|
||||||
|
|
||||||
func configure(withOpenWinddowAction openWindowAction: OpenWindowAction, dismissWindowAction: DismissWindowAction)
|
func configure(withOpenWinddowAction openWindowAction: OpenWindowAction, dismissWindowAction: DismissWindowAction)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user