Settings View: SwiftUI wrapper
This commit is contained in:
@@ -22,6 +22,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
|
||||
}
|
||||
|
||||
static func appMenuShortcuts() -> [UIKeyCommand] {
|
||||
[
|
||||
// Preferences
|
||||
UIKeyCommand(
|
||||
modifiers: .command,
|
||||
input: ",",
|
||||
title: "Preferences",
|
||||
action: #selector(ShortcutResponder.showPreferences)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
static func fileMenuShortcuts() -> [UIKeyCommand] {
|
||||
[
|
||||
// Open Location...
|
||||
@@ -90,13 +102,31 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
}
|
||||
|
||||
override var keyCommands: [UIKeyCommand]? {
|
||||
get { return Self.fileMenuShortcuts() }
|
||||
get { return Self.fileMenuShortcuts() + Self.appMenuShortcuts() }
|
||||
}
|
||||
|
||||
override func buildMenu(with builder: UIMenuBuilder) {
|
||||
builder.replaceChildren(ofMenu: .file) { children in
|
||||
return Self.fileMenuShortcuts() + children
|
||||
}
|
||||
|
||||
builder.replaceChildren(ofMenu: .application, from: { children in
|
||||
let index = children.firstIndex(where: { elem in
|
||||
if let elem = elem as? UIMenu {
|
||||
return elem.identifier == .about
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
var newChildren = children
|
||||
if let index = index {
|
||||
newChildren.insert(contentsOf: Self.appMenuShortcuts(), at: index + 1)
|
||||
} else {
|
||||
newChildren.append(contentsOf: Self.appMenuShortcuts())
|
||||
}
|
||||
|
||||
return newChildren
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,4 +146,7 @@ extension BrowserViewController: ShortcutResponder
|
||||
tab.webView._viewScale -= 0.10
|
||||
}
|
||||
|
||||
func showPreferences(_ sender: Any?) {
|
||||
showSettingsWindow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,6 +286,12 @@ class BrowserViewController: UIViewController
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
}, for: .touchUpInside)
|
||||
|
||||
// Settings
|
||||
documentControls.settingsView.addAction(UIAction { [unowned self] _ in
|
||||
documentControls.dismiss(animated: false, completion: nil)
|
||||
showSettingsWindow()
|
||||
}, for: .touchUpInside)
|
||||
|
||||
present(documentControls, animated: true, completion: nil)
|
||||
}), for: .touchUpInside)
|
||||
|
||||
@@ -312,6 +318,16 @@ class BrowserViewController: UIViewController
|
||||
self.view = browserView
|
||||
}
|
||||
|
||||
internal func showSettingsWindow() {
|
||||
#if targetEnvironment(macCatalyst)
|
||||
let userActivity = NSUserActivity(activityType: SessionActivityType.SettingsWindow.rawValue)
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: userActivity, options: .none, errorHandler: nil)
|
||||
#else
|
||||
let settingsVC = SettingsViewController()
|
||||
present(settingsVC, animated: true, completion: nil)
|
||||
#endif
|
||||
}
|
||||
|
||||
internal func updateLoadProgress(forWebView webView: WKWebView) {
|
||||
if let loadError = loadError {
|
||||
toolbarController.urlBar.loadProgress = .error(error: loadError)
|
||||
|
||||
@@ -35,4 +35,7 @@ protocol ShortcutResponder: AnyObject {
|
||||
|
||||
@objc
|
||||
optional func refresh(_ sender: Any?)
|
||||
|
||||
@objc
|
||||
optional func showPreferences(_ sender: Any?)
|
||||
}
|
||||
|
||||
@@ -7,28 +7,43 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
public enum SessionActivityType: String {
|
||||
case BrowserWindow = "net.buzzert.rossler-attix.browser"
|
||||
case SettingsWindow = "net.buzzert.rossler-attix.settings"
|
||||
}
|
||||
|
||||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
let navigationController = UINavigationController()
|
||||
let browserViewController = BrowserViewController()
|
||||
|
||||
var browserViewController: BrowserViewController?
|
||||
var settingsViewController: SettingsViewController?
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
|
||||
{
|
||||
guard let windowScene = (scene as? UIWindowScene) else { return }
|
||||
|
||||
navigationController.viewControllers = [ browserViewController ]
|
||||
navigationController.setNavigationBarHidden(true, animated: false)
|
||||
|
||||
let window = UIWindow(windowScene: windowScene)
|
||||
window.rootViewController = navigationController
|
||||
if let userActivity = connectionOptions.userActivities.first {
|
||||
if userActivity.activityType == SessionActivityType.SettingsWindow.rawValue {
|
||||
let settingsViewController = SettingsViewController()
|
||||
self.settingsViewController = settingsViewController
|
||||
window.rootViewController = settingsViewController
|
||||
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 500.0, height: 1200.0)
|
||||
}
|
||||
} else {
|
||||
let browserViewController = BrowserViewController()
|
||||
self.browserViewController = browserViewController
|
||||
window.rootViewController = browserViewController
|
||||
|
||||
if let urlContext = connectionOptions.urlContexts.first {
|
||||
let url = urlContext.url
|
||||
browserViewController.tab.beginLoadingURL(url)
|
||||
}
|
||||
}
|
||||
|
||||
window.makeKeyAndVisible()
|
||||
self.window = window
|
||||
|
||||
if let urlContext = connectionOptions.urlContexts.first {
|
||||
let url = urlContext.url
|
||||
browserViewController.tab.beginLoadingURL(url)
|
||||
}
|
||||
|
||||
#if targetEnvironment(macCatalyst)
|
||||
windowScene.titlebar?.titleVisibility = .hidden
|
||||
windowScene.titlebar?.separatorStyle = .none
|
||||
@@ -38,7 +53,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
|
||||
{
|
||||
for urlContext in URLContexts {
|
||||
browserViewController.createNewTab(withURL: urlContext.url)
|
||||
browserViewController?.createNewTab(withURL: urlContext.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
49
App/Settings/SettingsView.swift
Normal file
49
App/Settings/SettingsView.swift
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// SettingsView.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 3/3/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsCategoryCell: View {
|
||||
@State var title: String = ""
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Text(title)
|
||||
.bold()
|
||||
.frame(height: 34.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView: View {
|
||||
@Environment(\.presentationMode)
|
||||
@Binding private var presentationMode
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List {
|
||||
Section(header: Text("Redirect Rules"), content: {
|
||||
Text("To Do")
|
||||
})
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationBarTitle("Settings", displayMode: .inline)
|
||||
.toolbar(content: {
|
||||
#if !targetEnvironment(macCatalyst)
|
||||
Button("Done", action: { presentationMode.dismiss() })
|
||||
#endif
|
||||
})
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsView()
|
||||
}
|
||||
}
|
||||
22
App/Settings/SettingsViewController.swift
Normal file
22
App/Settings/SettingsViewController.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// SettingsViewController.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 3/3/21.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
class SettingsViewController: UIHostingController<SettingsView>
|
||||
{
|
||||
var settingsView = SettingsView()
|
||||
|
||||
init() {
|
||||
super.init(rootView: settingsView)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user