Tabs implementation
Favicons and stuff too
This commit is contained in:
@@ -30,16 +30,16 @@ class ScriptPolicyControl: UIControl
|
||||
convenience init() {
|
||||
self.init(frame: .zero)
|
||||
|
||||
allowButton.addAction(UIAction(handler: { _ in
|
||||
self.policyStatus = .allowed
|
||||
self.sendActions(for: .valueChanged)
|
||||
allowButton.addAction(UIAction(handler: { [weak self] _ in
|
||||
self?.policyStatus = .allowed
|
||||
self?.sendActions(for: .valueChanged)
|
||||
}), for: .touchUpInside)
|
||||
allowButton.imageView?.contentMode = .scaleAspectFit
|
||||
addSubview(allowButton)
|
||||
|
||||
denyButton.addAction(UIAction(handler: { _ in
|
||||
self.policyStatus = .blocked
|
||||
self.sendActions(for: .valueChanged)
|
||||
denyButton.addAction(UIAction(handler: { [weak self] _ in
|
||||
self?.policyStatus = .blocked
|
||||
self?.sendActions(for: .valueChanged)
|
||||
}), for: .touchUpInside)
|
||||
denyButton.imageView?.contentMode = .scaleAspectFit
|
||||
addSubview(denyButton)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol ScriptPolicyViewControllerDelegate {
|
||||
protocol ScriptPolicyViewControllerDelegate: class {
|
||||
func didChangeScriptPolicy()
|
||||
func setScriptsEnabledForTab(_ enabled: Bool)
|
||||
}
|
||||
@@ -77,8 +77,8 @@ class SwitchListCell: UICollectionViewListCell
|
||||
class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
{
|
||||
var collectionView: UICollectionView?
|
||||
var delegate: ScriptPolicyViewControllerDelegate? = nil
|
||||
var allowScriptsForTab = false
|
||||
weak var delegate: ScriptPolicyViewControllerDelegate? = nil
|
||||
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Section, String>?
|
||||
private var didChangeScriptPolicy = false
|
||||
@@ -102,7 +102,8 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
let otherOriginScripts = loadedScripts.subtracting([ hostOrigin ])
|
||||
let originItems = [ hostOrigin ] + otherOriginScripts
|
||||
|
||||
let switchCellRegistry = UICollectionView.CellRegistration<SwitchListCell, String> { (listCell, indexPath, item) in
|
||||
let switchCellRegistry = UICollectionView.CellRegistration<SwitchListCell, String> { [weak self] (listCell, indexPath, item) in
|
||||
guard let self = self else { return }
|
||||
var config = listCell.defaultContentConfiguration()
|
||||
if item == Self.enableScriptsForTabItem {
|
||||
config.text = "Allow for Tab"
|
||||
@@ -132,7 +133,8 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
listCell.contentConfiguration = config
|
||||
}
|
||||
|
||||
let scriptPolicyRegistry = UICollectionView.CellRegistration<ScriptPolicyControlListCell, String> { (listCell, indexPath, item) in
|
||||
let scriptPolicyRegistry = UICollectionView.CellRegistration<ScriptPolicyControlListCell, String> { [weak self] (listCell, indexPath, item) in
|
||||
guard let self = self else { return }
|
||||
var config = listCell.defaultContentConfiguration()
|
||||
config.text = item
|
||||
|
||||
@@ -194,7 +196,8 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate
|
||||
self.collectionView = collectionView
|
||||
|
||||
title = "Script Origin Policy"
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: UIAction(handler: { action in
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: UIAction(handler: { [weak self] action in
|
||||
guard let self = self else { return }
|
||||
if self.didChangeScriptPolicy {
|
||||
self.delegate?.didChangeScriptPolicy()
|
||||
self.delegate?.setScriptsEnabledForTab(self.allowScriptsForTab)
|
||||
|
||||
Reference in New Issue
Block a user