Files
Attractor/App/AppDelegate.swift

101 lines
3.4 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)
}
2022-08-22 17:10:47 -07:00
if userActivity.activityType == SessionActivityType.ReaderWindow.rawValue {
return UISceneConfiguration(name: "Reader", sessionRole: connectingSceneSession.role)
}
}
return UISceneConfiguration(name: "Browser", sessionRole: connectingSceneSession.role)
}
2020-09-21 18:35:39 -07:00
2023-01-27 13:46:23 -08:00
private func historyMenu() -> UIMenu {
let historyItems = BrowserHistory.shared.allHistory(limit: 50).map { item in
let title = (item.title.count > 0) ? item.title : item.url.absoluteString
return UIAction(title: title) { action in
UIApplication.shared.sendAction(#selector(ShortcutResponder.handleOpenURL), to: nil, from: action, for: OpenURLEvent(url: item.url))
}
}
return UIMenu(title: "History", children: [
UIKeyCommand(
modifiers: [ .command ],
input: "y",
title: "Show All History…",
action: #selector(ShortcutResponder.showHistory)
),
UIMenu(options: .displayInline, children: historyItems)
])
}
override var keyCommands: [UIKeyCommand]? {
2022-05-09 14:37:41 -07:00
get { KeyboardShortcuts.allKeyCommands() }
}
override func buildMenu(with builder: UIMenuBuilder) {
2022-05-09 14:37:41 -07:00
// File
2020-09-21 18:35:39 -07:00
builder.replaceChildren(ofMenu: .file) { children in
2022-05-09 14:37:41 -07:00
return KeyboardShortcuts.menu(for: .file) + children
2020-09-21 18:35:39 -07:00
}
2021-03-03 16:17:54 -08:00
2022-05-09 14:37:41 -07:00
// X Format X
2021-03-08 23:53:07 -08:00
builder.remove(menu: .format)
2022-05-09 14:37:41 -07:00
// Application
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
2022-05-09 14:37:41 -07:00
let shortcuts = KeyboardShortcuts.menu(for: .application)
2021-03-03 16:17:54 -08:00
if let index = index {
2022-05-09 14:37:41 -07:00
newChildren.insert(contentsOf: shortcuts, at: index + 1)
2021-03-03 16:17:54 -08:00
} else {
2022-05-09 14:37:41 -07:00
newChildren.append(contentsOf: shortcuts)
2021-03-03 16:17:54 -08:00
}
return newChildren
})
2022-05-09 14:37:41 -07:00
// Go
builder.insertSibling(UIMenu(title: "Go", children: KeyboardShortcuts.menu(for: .go)), beforeMenu: .view)
2023-01-27 13:46:23 -08:00
// History
builder.insertSibling(historyMenu(), beforeMenu: .view)
2022-05-09 14:37:41 -07:00
// View
builder.replaceChildren(ofMenu: .view) { children in
KeyboardShortcuts.menu(for: .view) + children
}
2020-09-21 18:35:39 -07:00
}
}