From 669da89ff3abd525e503b13b26e963c15454b00a Mon Sep 17 00:00:00 2001 From: James Magahern Date: Fri, 14 Aug 2020 17:40:01 -0700 Subject: [PATCH] Some fixes for macOS --- App/Common UI/ReliefButton.swift | 11 +++++-- .../ScriptPolicyControl.swift | 17 ++++------ .../ScriptPolicyViewController.swift | 32 +++++++++++++++---- .../SBRProcessBundleBridge.m | 5 +++ SBrowser.xcodeproj/project.pbxproj | 17 ++++++---- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/App/Common UI/ReliefButton.swift b/App/Common UI/ReliefButton.swift index 35b4a79..94cfab1 100644 --- a/App/Common UI/ReliefButton.swift +++ b/App/Common UI/ReliefButton.swift @@ -20,7 +20,6 @@ class ReliefButton: UIButton } } - init() { super.init(frame: .zero) @@ -105,8 +104,14 @@ class ReliefButton: UIButton } override func imageRect(forContentRect contentRect: CGRect) -> CGRect { - let inset = CGFloat(7.0) - return contentRect.insetBy(dx: inset, dy: inset) + let ratio = CGFloat(0.45) + return CGRect( + origin: .zero, + size: CGSize( + width: ratio * contentRect.width, + height: ratio * contentRect.width + ) + ).centered(inRect: contentRect) } override func sizeThatFits(_ size: CGSize) -> CGSize { diff --git a/App/Script Policy UI/ScriptPolicyControl.swift b/App/Script Policy UI/ScriptPolicyControl.swift index 44f07c1..6455eb0 100644 --- a/App/Script Policy UI/ScriptPolicyControl.swift +++ b/App/Script Policy UI/ScriptPolicyControl.swift @@ -18,18 +18,16 @@ class ScriptPolicyControl: UIControl didSet { setNeedsLayout() } } - private class PolicyButton: UIButton { - override func imageRect(forContentRect contentRect: CGRect) -> CGRect { - contentRect.insetBy(dx: 8.0, dy: 8.0) - } - } - - private let allowButton = PolicyButton(frame: .zero) - private let denyButton = PolicyButton(frame: .zero) + private let allowButton = ReliefButton() + private let denyButton = ReliefButton() + private let segmentContainer = SegmentedReliefButton(children: []) convenience init() { self.init(frame: .zero) + segmentContainer.children = [ allowButton, denyButton ] + addSubview(segmentContainer) + allowButton.addAction(UIAction(handler: { [unowned self] _ in self.policyStatus = .allowed self.sendActions(for: .valueChanged) @@ -52,8 +50,7 @@ class ScriptPolicyControl: UIControl override func layoutSubviews() { super.layoutSubviews() - allowButton.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width / 2, height: bounds.height)) - denyButton.frame = CGRect(origin: CGPoint(x: allowButton.frame.maxX, y: 0), size: allowButton.frame.size) + segmentContainer.frame = bounds if policyStatus == .allowed { allowButton.tintColor = .blue diff --git a/App/Script Policy UI/ScriptPolicyViewController.swift b/App/Script Policy UI/ScriptPolicyViewController.swift index 83286e1..626428a 100644 --- a/App/Script Policy UI/ScriptPolicyViewController.swift +++ b/App/Script Policy UI/ScriptPolicyViewController.swift @@ -34,7 +34,13 @@ class ScriptPolicyControlListCell: UICollectionViewListCell override func layoutSubviews() { let policyControlWidth = CGFloat(80.0) - policyControl.frame = CGRect(x: bounds.maxX - policyControlWidth - layoutMargins.right, y: 0, width: policyControlWidth, height: bounds.height) + policyControl.frame = CGRect( + x: bounds.maxX - policyControlWidth - layoutMargins.right, + y: 0, + width: policyControlWidth, + height: bounds.height * 0.75 + ) + policyControl.frame = policyControl.frame.centeredY(inRect: bounds) bringSubviewToFront(policyControl) super.layoutSubviews() @@ -68,7 +74,8 @@ class SwitchListCell: UICollectionViewListCell super.layoutSubviews() let switchWidth: CGFloat = switchView.sizeThatFits(bounds.size).width - switchView.frame = CGRect(x: bounds.maxX - switchWidth - layoutMargins.right, y: 0, width: switchWidth, height: bounds.height) + switchView.frame = CGRect(x: bounds.maxX - switchWidth - layoutMargins.right, y: 0, + width: switchWidth, height: bounds.height * 0.85) switchView.frame = switchView.frame.centeredY(inRect: bounds) contentView.frame = CGRect(origin: contentView.frame.origin, size: CGSize(width: switchView.frame.minX, height: contentView.frame.height)) } @@ -88,6 +95,19 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate case origins } + override var traitCollection: UITraitCollection { + get { + let actualTraits = super.traitCollection + if actualTraits.userInterfaceIdiom == .mac { + // Override traits to be iPad like on mac. We dont want small list cells here. + let desiredTraits = UITraitCollection(userInterfaceIdiom: .pad) + return UITraitCollection(traitsFrom: [ actualTraits, desiredTraits ]) + } + + return actualTraits + } + } + private static let enableScriptsForTabItem: String = "enableScriptsForTab" convenience init(policyManager: ResourcePolicyManager, hostOrigin: String, loadedScripts: Set, scriptsAllowedForTab: Bool) { @@ -98,13 +118,11 @@ class ScriptPolicyViewController: UIViewController, UICollectionViewDelegate let listLayout = UICollectionViewCompositionalLayout.list(using: listConfig) let collectionView = UICollectionView(frame: .zero, collectionViewLayout: listLayout) - // Allowed scripts go to the top - let allowedScripts = loadedScripts.filter { policyManager.allowedOriginsForScriptResources().contains($0) } - // Make sure host origin goes first in the list. - let otherOriginScripts = loadedScripts.subtracting([ hostOrigin ]).subtracting(allowedScripts) + let otherOriginScripts = loadedScripts.subtracting([ hostOrigin ]) + let allowedScripts = otherOriginScripts.filter { policyManager.allowedOriginsForScriptResources().contains($0) } - let originItems = [ hostOrigin ] + allowedScripts + otherOriginScripts + let originItems = [ hostOrigin ] + allowedScripts + otherOriginScripts.subtracting(allowedScripts) let switchCellRegistry = UICollectionView.CellRegistration { [unowned self] (listCell, indexPath, item) in var config = listCell.defaultContentConfiguration() diff --git a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m index a8cdbed..6587f3b 100644 --- a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m +++ b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m @@ -66,6 +66,11 @@ // Inject bundle _WKProcessPoolConfiguration *poolConfiguration = [[_WKProcessPoolConfiguration alloc] init]; NSURL *bundleURL = [[[NSBundle mainBundle] builtInPlugInsURL] URLByAppendingPathComponent:@"SBrowserProcessBundle.bundle"]; + + // Make sure it exists. Bail if otherwise. + NSBundle *pluginBundle = [NSBundle bundleWithURL:bundleURL]; + NSAssert(pluginBundle != nil, @"Attix process bundle not found at %@", bundleURL.path); + [poolConfiguration setInjectedBundleURL:bundleURL]; // Set up process pool diff --git a/SBrowser.xcodeproj/project.pbxproj b/SBrowser.xcodeproj/project.pbxproj index 9e575f0..49be5ba 100644 --- a/SBrowser.xcodeproj/project.pbxproj +++ b/SBrowser.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -26,7 +26,7 @@ 1ADFF47924C7DFF8006DC7AE /* BrowserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF47824C7DFF8006DC7AE /* BrowserView.swift */; }; 1ADFF48424C8C12F006DC7AE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ADFF48324C8C12F006DC7AE /* Foundation.framework */; }; 1ADFF48D24C8C176006DC7AE /* SBRProcessBundleBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF48C24C8C176006DC7AE /* SBRProcessBundleBridge.m */; }; - 1ADFF4A724C8C271006DC7AE /* SBrowserProcessBundle.bundle in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1ADFF48124C8C12F006DC7AE /* SBrowserProcessBundle.bundle */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 1ADFF4A724C8C271006DC7AE /* SBrowserProcessBundle.bundle in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 1ADFF48124C8C12F006DC7AE /* SBrowserProcessBundle.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 1ADFF4AA24C8D477006DC7AE /* SBRProcessPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF4A924C8D477006DC7AE /* SBRProcessPlugin.m */; }; 1ADFF4AE24C8ED32006DC7AE /* ResourcePolicyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF4AD24C8ED32006DC7AE /* ResourcePolicyManager.swift */; }; 1ADFF4C024CA6964006DC7AE /* URLBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF4BF24CA6964006DC7AE /* URLBar.swift */; }; @@ -418,7 +418,6 @@ /* Begin PBXTargetDependency section */ 1ADFF48F24C8C230006DC7AE /* PBXTargetDependency */ = { isa = PBXTargetDependency; - platformFilter = ios; target = 1ADFF48024C8C12F006DC7AE /* SBrowserProcessBundle */; targetProxy = 1ADFF48E24C8C230006DC7AE /* PBXContainerItemProxy */; }; @@ -577,6 +576,7 @@ PRODUCT_NAME = "rossler\\\\attix"; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_OBJC_BRIDGING_HEADER = "App/Supporting Files/SBrowser-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -607,6 +607,7 @@ PRODUCT_NAME = "rossler\\\\attix"; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_OBJC_BRIDGING_HEADER = "App/Supporting Files/SBrowser-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,6"; @@ -622,8 +623,9 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos.internal; STRIP_INSTALLED_PRODUCT = NO; - SUPPORTS_MACCATALYST = NO; - TARGETED_DEVICE_FAMILY = "1,2"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = "1,2,6"; WRAPPER_EXTENSION = bundle; }; name = Debug; @@ -636,8 +638,9 @@ PRODUCT_BUNDLE_IDENTIFIER = net.buzzert.SBrowserProcessBundle; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos.internal; - SUPPORTS_MACCATALYST = NO; - TARGETED_DEVICE_FAMILY = "1,2"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = "1,2,6"; WRAPPER_EXTENSION = bundle; }; name = Release;