Feature: make Reader use center window
This commit is contained in:
@@ -23,6 +23,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
if userActivity.activityType == SessionActivityType.SettingsWindow.rawValue {
|
||||
return UISceneConfiguration(name: "Settings", sessionRole: connectingSceneSession.role)
|
||||
}
|
||||
|
||||
if userActivity.activityType == SessionActivityType.ReaderWindow.rawValue {
|
||||
return UISceneConfiguration(name: "Reader", sessionRole: connectingSceneSession.role)
|
||||
}
|
||||
}
|
||||
|
||||
return UISceneConfiguration(name: "Browser", sessionRole: connectingSceneSession.role)
|
||||
|
||||
@@ -299,13 +299,26 @@ class BrowserViewController: UIViewController
|
||||
DispatchQueue.main.async {
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
|
||||
let readableViewController = ReaderViewController(readableHTMLString: string, baseURL: self.tab.bridge.webView.url)
|
||||
readableViewController.title = self.tab.bridge.webView.title
|
||||
readableViewController.darkModeEnabled = self.tab.bridge.darkModeEnabled
|
||||
readableViewController.delegate = self
|
||||
if self.traitCollection.userInterfaceIdiom == .phone {
|
||||
let readableViewController = ReaderViewController(readableHTMLString: string, baseURL: self.tab.bridge.webView.url)
|
||||
readableViewController.title = self.tab.bridge.webView.title
|
||||
readableViewController.darkModeEnabled = self.tab.bridge.darkModeEnabled
|
||||
readableViewController.delegate = self
|
||||
|
||||
let navigationController = UINavigationController(rootViewController: readableViewController)
|
||||
self.present(navigationController, animated: true, completion: nil)
|
||||
} else {
|
||||
let userActivity = NSUserActivity(activityType: SessionActivityType.ReaderWindow.rawValue)
|
||||
userActivity.title = self.tab.title
|
||||
userActivity.userInfo = [
|
||||
ReaderUserActivityKeys.baseURL.rawValue : self.tab.bridge.webView.url ?? NSNull(),
|
||||
ReaderUserActivityKeys.htmlString.rawValue : string,
|
||||
]
|
||||
let requestOptions = UIWindowScene.ActivationRequestOptions()
|
||||
requestOptions.preferredPresentationStyle = .prominent
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: userActivity, options: requestOptions)
|
||||
}
|
||||
|
||||
let navigationController = UINavigationController(rootViewController: readableViewController)
|
||||
self.present(navigationController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
}, for: .touchUpInside)
|
||||
|
||||
@@ -55,7 +55,13 @@ class ReaderViewController: UIViewController
|
||||
|
||||
@objc
|
||||
private func didTapDoneButton(_ sender: Any?) {
|
||||
dismiss(animated: true, completion: nil)
|
||||
if traitCollection.userInterfaceIdiom == .phone {
|
||||
dismiss(animated: true, completion: nil)
|
||||
} else {
|
||||
if let sceneSession = view.window?.windowScene?.session {
|
||||
UIApplication.shared.requestSceneSessionDestruction(sceneSession, options: nil, errorHandler: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// SceneDelegate.swift
|
||||
// BrowserSceneDelegate.swift
|
||||
// SBrowser
|
||||
//
|
||||
// Created by James Magahern on 7/21/20.
|
||||
@@ -10,9 +10,10 @@ import UIKit
|
||||
public enum SessionActivityType: String {
|
||||
case BrowserWindow = "net.buzzert.attractor.browser"
|
||||
case SettingsWindow = "net.buzzert.attractor.settings"
|
||||
case ReaderWindow = "net.buzzert.attractor.reader"
|
||||
}
|
||||
|
||||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
class BrowserSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
|
||||
var browserViewController: BrowserViewController?
|
||||
@@ -32,10 +33,24 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
browserViewController.tab.beginLoadingURL(url)
|
||||
}
|
||||
|
||||
#if targetEnvironment(macCatalyst)
|
||||
windowScene.titlebar?.titleVisibility = .hidden
|
||||
windowScene.titlebar?.separatorStyle = .none
|
||||
#endif
|
||||
#if targetEnvironment(macCatalyst)
|
||||
windowScene.titlebar?.titleVisibility = .hidden
|
||||
windowScene.titlebar?.separatorStyle = .none
|
||||
|
||||
if #available(macCatalyst 16.0, *) {
|
||||
let screenSize = windowScene.screen.bounds.size
|
||||
let preferredSize = CGSize(width: 1000, height: 1100)
|
||||
let geometryPreferences = UIWindowScene.GeometryPreferences.Mac(systemFrame: CGRect(
|
||||
origin: CGPoint(
|
||||
x: (screenSize.width - preferredSize.width) / 2,
|
||||
y: (screenSize.height - preferredSize.height) / 2
|
||||
),
|
||||
|
||||
size: preferredSize
|
||||
))
|
||||
windowScene.requestGeometryUpdate(geometryPreferences)
|
||||
}
|
||||
#endif
|
||||
|
||||
window.makeKeyAndVisible()
|
||||
self.window = window
|
||||
41
App/Scene Delegates/ReaderSceneDelegate.swift
Normal file
41
App/Scene Delegates/ReaderSceneDelegate.swift
Normal file
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// ReaderSceneDelegate.swift
|
||||
// App
|
||||
//
|
||||
// Created by James Magahern on 8/22/22.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
internal enum ReaderUserActivityKeys: String {
|
||||
case htmlString
|
||||
case baseURL
|
||||
}
|
||||
|
||||
class ReaderSceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
var window: UIWindow?
|
||||
var readerViewController: ReaderViewController?
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
|
||||
{
|
||||
guard let windowScene = (scene as? UIWindowScene) else { return }
|
||||
guard let activity = connectionOptions.userActivities.first else { return }
|
||||
|
||||
guard let userInfo = activity.userInfo, let htmlString: String = userInfo[ReaderUserActivityKeys.htmlString.rawValue] as? String else { return }
|
||||
let baseURL = userInfo[ReaderUserActivityKeys.baseURL.rawValue] as? URL
|
||||
|
||||
let window = UIWindow(windowScene: windowScene)
|
||||
|
||||
let readerViewController = ReaderViewController(readableHTMLString: htmlString, baseURL: baseURL)
|
||||
readerViewController.title = activity.title
|
||||
|
||||
self.readerViewController = readerViewController
|
||||
window.rootViewController = UINavigationController(rootViewController: readerViewController)
|
||||
|
||||
windowScene.title = activity.title ?? "Reader"
|
||||
windowScene.sizeRestrictions?.maximumSize = CGSize(width: 700.0, height: 1000.0)
|
||||
|
||||
window.makeKeyAndVisible()
|
||||
self.window = window
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>Browser</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
|
||||
<string>$(PRODUCT_MODULE_NAME).BrowserSceneDelegate</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>UISceneConfigurationName</key>
|
||||
@@ -61,6 +61,12 @@
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).SettingsSceneDelegate</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>Reader</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).ReaderSceneDelegate</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
1AD3104325254FB900A4A952 /* FindOnPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD3104225254FB900A4A952 /* FindOnPageViewController.swift */; };
|
||||
1AD310452525586B00A4A952 /* DocumentControlItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD310442525586B00A4A952 /* DocumentControlItemView.swift */; };
|
||||
1ADFF46024C7DE53006DC7AE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF45F24C7DE53006DC7AE /* AppDelegate.swift */; };
|
||||
1ADFF46224C7DE53006DC7AE /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF46124C7DE53006DC7AE /* SceneDelegate.swift */; };
|
||||
1ADFF46224C7DE53006DC7AE /* BrowserSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF46124C7DE53006DC7AE /* BrowserSceneDelegate.swift */; };
|
||||
1ADFF46924C7DE54006DC7AE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1ADFF46824C7DE54006DC7AE /* Assets.xcassets */; };
|
||||
1ADFF46C24C7DE54006DC7AE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1ADFF46A24C7DE54006DC7AE /* LaunchScreen.storyboard */; };
|
||||
1ADFF47424C7DE9C006DC7AE /* BrowserViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ADFF47324C7DE9C006DC7AE /* BrowserViewController.swift */; };
|
||||
@@ -63,6 +63,7 @@
|
||||
CD9B88C2272201E900DAAB7E /* SBRScriptPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = CD361CF5271A3718006E9CA5 /* SBRScriptPolicy.m */; };
|
||||
CDAD9CE8263A2DF200FF7199 /* DocumentControlsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDAD9CE7263A2DF200FF7199 /* DocumentControlsView.swift */; };
|
||||
CDAD9CEA263A318F00FF7199 /* ShareableURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDAD9CE9263A318F00FF7199 /* ShareableURL.swift */; };
|
||||
CDB6807D28B446FC007D787E /* ReaderSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB6807C28B446FC007D787E /* ReaderSceneDelegate.swift */; };
|
||||
CDC4A1CF25E9D8F7007D33C6 /* Tagger.js in Resources */ = {isa = PBXBuildFile; fileRef = CDC4A1CE25E9D8F7007D33C6 /* Tagger.js */; };
|
||||
CDC5DA3A25DB774D00BA8D99 /* Readability.js in Resources */ = {isa = PBXBuildFile; fileRef = CDC5DA3925DB774D00BA8D99 /* Readability.js */; };
|
||||
CDC5DA3E25DB7C2C00BA8D99 /* ReaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDC5DA3D25DB7C2C00BA8D99 /* ReaderViewController.swift */; };
|
||||
@@ -121,7 +122,7 @@
|
||||
1AD310442525586B00A4A952 /* DocumentControlItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentControlItemView.swift; sourceTree = "<group>"; };
|
||||
1ADFF45C24C7DE53006DC7AE /* Attractor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Attractor.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1ADFF45F24C7DE53006DC7AE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
1ADFF46124C7DE53006DC7AE /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
||||
1ADFF46124C7DE53006DC7AE /* BrowserSceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserSceneDelegate.swift; sourceTree = "<group>"; };
|
||||
1ADFF46824C7DE54006DC7AE /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
1ADFF46B24C7DE54006DC7AE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
1ADFF46D24C7DE54006DC7AE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@@ -170,6 +171,7 @@
|
||||
CD97CF9125D5BE6F00288FEE /* NavigationControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationControlsView.swift; sourceTree = "<group>"; };
|
||||
CDAD9CE7263A2DF200FF7199 /* DocumentControlsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentControlsView.swift; sourceTree = "<group>"; };
|
||||
CDAD9CE9263A318F00FF7199 /* ShareableURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareableURL.swift; sourceTree = "<group>"; };
|
||||
CDB6807C28B446FC007D787E /* ReaderSceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderSceneDelegate.swift; sourceTree = "<group>"; };
|
||||
CDC4A1CE25E9D8F7007D33C6 /* Tagger.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = Tagger.js; sourceTree = "<group>"; };
|
||||
CDC5DA3925DB774D00BA8D99 /* Readability.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = Readability.js; sourceTree = "<group>"; };
|
||||
CDC5DA3D25DB7C2C00BA8D99 /* ReaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReaderViewController.swift; sourceTree = "<group>"; };
|
||||
@@ -286,8 +288,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1ADFF45F24C7DE53006DC7AE /* AppDelegate.swift */,
|
||||
1ADFF46124C7DE53006DC7AE /* SceneDelegate.swift */,
|
||||
CDF3468D276C105900FB3141 /* SettingsSceneDelegate.swift */,
|
||||
CD7A89162519872D0075991E /* KeyboardShortcuts.swift */,
|
||||
CD7A89132519759D0075991E /* Autocomplete */,
|
||||
1ADFF47A24C7E176006DC7AE /* Backend */,
|
||||
@@ -297,6 +297,7 @@
|
||||
1AD3104125254FA300A4A952 /* Find on Page */,
|
||||
CD7F2133265DACEE0001D042 /* Hacks */,
|
||||
CDC5DA3C25DB7A5500BA8D99 /* Reader View */,
|
||||
CDB6807B28B4456B007D787E /* Scene Delegates */,
|
||||
1ADFF4CE24CBBCBD006DC7AE /* Script Policy UI */,
|
||||
CDE6A30225F023A000E912A4 /* Settings */,
|
||||
CDF255FB289DD7BD0059F021 /* Sync */,
|
||||
@@ -435,6 +436,16 @@
|
||||
path = History;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CDB6807B28B4456B007D787E /* Scene Delegates */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1ADFF46124C7DE53006DC7AE /* BrowserSceneDelegate.swift */,
|
||||
CDF3468D276C105900FB3141 /* SettingsSceneDelegate.swift */,
|
||||
CDB6807C28B446FC007D787E /* ReaderSceneDelegate.swift */,
|
||||
);
|
||||
path = "Scene Delegates";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CDC5DA3C25DB7A5500BA8D99 /* Reader View */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -612,12 +623,13 @@
|
||||
1A03810D24E71CA700826501 /* ToolbarView.swift in Sources */,
|
||||
CD936A3D289DB88B0093A1AC /* UIView+Utils.swift in Sources */,
|
||||
CD470C4425DE070400AFBE0E /* BrowserViewController+Keyboard.swift in Sources */,
|
||||
CDB6807D28B446FC007D787E /* ReaderSceneDelegate.swift in Sources */,
|
||||
CDD0522425F8055700DD1771 /* SearchProvider.swift in Sources */,
|
||||
CD853BD424E77BF900D2BDCC /* HistoryItem.swift in Sources */,
|
||||
1ADFF48D24C8C176006DC7AE /* SBRProcessBundleBridge.m in Sources */,
|
||||
1AB88F0624D4D3A90006F850 /* UIGestureRecognizer+Actions.swift in Sources */,
|
||||
CD7313E4270534B800053347 /* ScriptPolicyViewControllerDelegate.swift in Sources */,
|
||||
1ADFF46224C7DE53006DC7AE /* SceneDelegate.swift in Sources */,
|
||||
1ADFF46224C7DE53006DC7AE /* BrowserSceneDelegate.swift in Sources */,
|
||||
CD16844D269E709400B8F8A5 /* Box.swift in Sources */,
|
||||
CD853BCE24E7763900D2BDCC /* BrowserHistory.swift in Sources */,
|
||||
1A03810B24E71C5600826501 /* ToolbarButtonContainerView.swift in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user