frenzy-ios/Reader/PrefsSceneDelegate.swift

69 lines
2.2 KiB
Swift
Raw Normal View History

2022-01-16 16:58:28 +00:00
//
// PrefsSceneDelegate.swift
// Reader
//
// Created by Shadowfacts on 1/16/22.
//
#if targetEnvironment(macCatalyst)
import UIKit
import SwiftUI
class PrefsSceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
return
}
window = UIWindow(windowScene: windowScene)
window!.tintColor = .appTintColor
windowScene.sizeRestrictions?.minimumSize = CGSize(width: 640, height: 480)
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 640, height: 480)
window!.rootViewController = UIHostingController(rootView: PrefsView())
if let titlebar = windowScene.titlebar {
titlebar.toolbarStyle = .preference
titlebar.toolbar = NSToolbar(identifier: .init("ReaderPrefsToolbar"))
titlebar.toolbar!.delegate = self
titlebar.toolbar!.allowsUserCustomization = false
}
window!.makeKeyAndVisible()
NotificationCenter.default.addObserver(self, selector: #selector(updateAppearance), name: .appearanceChanged, object: nil)
updateAppearance()
2022-01-16 16:58:28 +00:00
}
@objc private func updateAppearance() {
switch Preferences.shared.appearance {
case .unspecified:
window!.overrideUserInterfaceStyle = .unspecified
case .light:
window!.overrideUserInterfaceStyle = .light
case .dark:
window!.overrideUserInterfaceStyle = .dark
}
2022-01-16 16:58:28 +00:00
}
}
extension PrefsSceneDelegate: NSToolbarDelegate {
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
return nil
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return []
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return []
}
}
#endif