Files
Attractor/App/AppDelegate.swift

158 lines
4.9 KiB
Swift
Raw Normal View History

//
// AppDelegate.swift
// SBrowser
//
// Created by James Magahern on 7/21/20.
//
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration
{
if let userActivity = options.userActivities.first {
if userActivity.activityType == SessionActivityType.SettingsWindow.rawValue {
return UISceneConfiguration(name: "Settings", sessionRole: connectingSceneSession.role)
}
}
return UISceneConfiguration(name: "Browser", sessionRole: connectingSceneSession.role)
}
2020-09-21 18:35:39 -07:00
2021-03-03 16:17:54 -08:00
static func appMenuShortcuts() -> [UIKeyCommand] {
[
// Preferences
UIKeyCommand(
modifiers: .command,
input: ",",
title: "Preferences",
action: #selector(ShortcutResponder.showPreferences)
)
]
}
static func fileMenuShortcuts() -> [UIKeyCommand] {
[
2020-09-21 18:35:39 -07:00
// Open Location...
UIKeyCommand(
modifiers: .command, input: "L",
title: "Open Location",
action: #selector(ShortcutResponder.focusURLBar)
),
2021-03-04 16:07:30 -08:00
// Focus Web View
UIKeyCommand(
2021-03-08 23:53:07 -08:00
modifiers: .command, input: "e",
2021-03-04 16:07:30 -08:00
title: "Focus Web View",
action: #selector(ShortcutResponder.focusWebView)
),
2020-09-21 18:35:39 -07:00
// Go Back
UIKeyCommand(
modifiers: .command, input: "[",
title: "Go Back",
action: #selector(ShortcutResponder.goBack)
),
// Go Forward
UIKeyCommand(
modifiers: .command, input: "]",
title: "Go Forward",
action: #selector(ShortcutResponder.goForward)
),
// Create Tab
UIKeyCommand(
modifiers: .command, input: "T",
title: "New Tab",
action: #selector(ShortcutResponder.createTab)
),
// Previous Tab
UIKeyCommand(
modifiers: [.command, .shift], input: "[",
title: "Previous Tab",
action: #selector(ShortcutResponder.previousTab)
),
2020-11-10 11:57:40 -06:00
// Close tab
UIKeyCommand(
modifiers: [.command], input: "W",
title: "Close Tab",
action: #selector(ShortcutResponder.closeTab)
),
2020-09-21 18:35:39 -07:00
// Next Tab
UIKeyCommand(
modifiers: [.command, .shift], input: "]",
title: "Next Tab",
action: #selector(ShortcutResponder.nextTab)
),
2020-09-30 18:06:47 -07:00
// Find on page
2022-03-28 16:52:03 -07:00
(FindOnPageViewController.isEnabled() ?
UIKeyCommand(
modifiers: [.command], input: "F",
title: "Find on Page",
action: #selector(ShortcutResponder.findOnPage)
)
2022-03-29 17:27:07 -07:00
: UIKeyCommand.null()
2020-09-30 18:06:47 -07:00
),
// Refresh
UIKeyCommand(
modifiers: [.command], input: "R",
title: "Refresh",
action: #selector(ShortcutResponder.refresh)
),
2021-03-08 23:38:01 -08:00
// Toggle Dark Mode
UIKeyCommand(
2021-03-08 23:53:07 -08:00
modifiers: [.command], input: "M",
2021-03-08 23:38:01 -08:00
title: "Toggle Dark Mode",
action: #selector(ShortcutResponder.toggleDarkMode)
),
2020-09-21 18:35:39 -07:00
]
}
override var keyCommands: [UIKeyCommand]? {
2021-03-03 16:17:54 -08:00
get { return Self.fileMenuShortcuts() + Self.appMenuShortcuts() }
}
override func buildMenu(with builder: UIMenuBuilder) {
2020-09-21 18:35:39 -07:00
builder.replaceChildren(ofMenu: .file) { children in
2021-03-08 23:53:07 -08:00
return Self.fileMenuShortcuts() + children
2020-09-21 18:35:39 -07:00
}
2021-03-03 16:17:54 -08:00
2021-03-08 23:53:07 -08:00
builder.remove(menu: .format)
2021-03-03 16:17:54 -08:00
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
})
2020-09-21 18:35:39 -07:00
}
}