2023-11-15 21:30:14 -06:00
|
|
|
//
|
|
|
|
// SceneDelegate.swift
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by David Sinclair on 2023-11-15.
|
|
|
|
// Copyright © 2023 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|
|
|
let appDelegate: NewsBlurAppDelegate = .shared
|
|
|
|
|
|
|
|
var window: UIWindow?
|
2024-01-05 22:02:43 -05:00
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
var toolbar = NSToolbar(identifier: "main")
|
|
|
|
var toolbarDelegate = ToolbarDelegate()
|
|
|
|
#endif
|
2023-11-15 21:30:14 -06:00
|
|
|
|
2024-05-31 17:05:38 -04:00
|
|
|
@objc(closeAuxWindows) class func closeAuxWindows() {
|
|
|
|
for window in UIApplication.shared.windows {
|
|
|
|
if window.windowScene?.delegate is AuxSceneDelegate, let session = window.windowScene?.session {
|
|
|
|
window.isHidden = true
|
|
|
|
UIApplication.shared.requestSceneSessionDestruction(session, options: .none)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-15 21:30:14 -06:00
|
|
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
2024-05-31 17:05:38 -04:00
|
|
|
if appDelegate.window != nil {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.window?.isHidden = true
|
|
|
|
UIApplication.shared.requestSceneSessionDestruction(session, options: .none)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-15 21:30:14 -06:00
|
|
|
appDelegate.window = window
|
2024-01-05 22:02:43 -05:00
|
|
|
|
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
guard let windowScene = scene as? UIWindowScene, let titlebar = windowScene.titlebar else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-08-29 13:35:52 -07:00
|
|
|
// if #available(macCatalyst 16.0, *) {
|
|
|
|
// windowScene.windowingBehaviors?.isClosable = false
|
|
|
|
// }
|
2024-05-31 17:05:38 -04:00
|
|
|
|
2024-01-05 22:02:43 -05:00
|
|
|
toolbar.delegate = toolbarDelegate
|
|
|
|
toolbar.displayMode = .iconOnly
|
|
|
|
|
|
|
|
titlebar.toolbar = toolbar
|
|
|
|
titlebar.toolbarStyle = .automatic
|
|
|
|
#endif
|
2024-05-31 17:05:38 -04:00
|
|
|
|
2023-11-15 21:30:14 -06:00
|
|
|
appDelegate.prepareViewControllers()
|
|
|
|
}
|
2024-06-27 14:47:10 -04:00
|
|
|
|
2024-08-29 13:35:52 -07:00
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
func sceneDidDisconnect(_ scene: UIScene) {
|
|
|
|
appDelegate.window = nil
|
|
|
|
|
|
|
|
exit(0)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-06-27 14:47:10 -04:00
|
|
|
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
|
|
|
|
guard let url = URLContexts.first?.url else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
appDelegate.open(url)
|
|
|
|
}
|
2023-11-15 21:30:14 -06:00
|
|
|
}
|