Settings: Tweaks for Catalyst
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import MachO
|
||||||
|
|
||||||
class RedirectRulesSettingsViewController: UICollectionViewController
|
class RedirectRulesSettingsViewController: UICollectionViewController
|
||||||
{
|
{
|
||||||
@@ -51,7 +52,16 @@ class RedirectRulesSettingsViewController: UICollectionViewController
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
|
let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
|
||||||
let layout = UICollectionViewCompositionalLayout.list(using: config)
|
let layout = UICollectionViewCompositionalLayout { section, layoutEnvironment in
|
||||||
|
let listSection = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment)
|
||||||
|
|
||||||
|
#if targetEnvironment(macCatalyst)
|
||||||
|
listSection.contentInsets = NSDirectionalEdgeInsets(top: 24.0, leading: 164.0, bottom: 24.0, trailing: 164.0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return listSection
|
||||||
|
}
|
||||||
|
|
||||||
super.init(collectionViewLayout: layout)
|
super.init(collectionViewLayout: layout)
|
||||||
|
|
||||||
tabBarItem.title = "Redirect Rules"
|
tabBarItem.title = "Redirect Rules"
|
||||||
@@ -71,6 +81,8 @@ class RedirectRulesSettingsViewController: UICollectionViewController
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
|
collectionView.deselectItem(at: indexPath, animated: true)
|
||||||
|
|
||||||
let item = dataSource.itemIdentifier(for: indexPath)
|
let item = dataSource.itemIdentifier(for: indexPath)
|
||||||
if item == Items.addButton.rawValue {
|
if item == Items.addButton.rawValue {
|
||||||
let createRuleViewController = CreateRedirectRuleViewController()
|
let createRuleViewController = CreateRedirectRuleViewController()
|
||||||
@@ -180,5 +192,9 @@ class CreateRedirectRuleViewController: UICollectionViewController
|
|||||||
snapshot.appendItems([ Item.fromHost, Item.toHost ], toSection: .hosts)
|
snapshot.appendItems([ Item.fromHost, Item.toHost ], toSection: .hosts)
|
||||||
dataSource.applySnapshotUsingReloadData(snapshot)
|
dataSource.applySnapshotUsingReloadData(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ class Settings
|
|||||||
public var redirectRules: [String: String] = [:]
|
public var redirectRules: [String: String] = [:]
|
||||||
|
|
||||||
func redirectRule(for url: URL) -> URL? {
|
func redirectRule(for url: URL) -> URL? {
|
||||||
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), let host = url.host {
|
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), var host = url.host {
|
||||||
|
// Remove "www." if necessary.
|
||||||
|
host = host.replacingOccurrences(of: "www.", with: "")
|
||||||
|
|
||||||
if let alternateHost = redirectRules[host] {
|
if let alternateHost = redirectRules[host] {
|
||||||
components.host = alternateHost
|
components.host = alternateHost
|
||||||
return components.url
|
return components.url
|
||||||
|
|||||||
Reference in New Issue
Block a user