diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift index 3b09f93..e0c1b4b 100644 --- a/Demo/AppDelegate.swift +++ b/Demo/AppDelegate.swift @@ -6,7 +6,7 @@ import UIKit class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { #if DEBUG - TurboLog.debugLoggingEnabled = true + Turbo.config.debugLoggingEnabled = true Strada.config.debugLoggingEnabled = true #endif diff --git a/Demo/SceneController.swift b/Demo/SceneController.swift index 9c315b4..9fc1236 100644 --- a/Demo/SceneController.swift +++ b/Demo/SceneController.swift @@ -13,10 +13,9 @@ final class SceneController: UIResponder { // MARK: - Setup private func configureStrada() { - TurboConfig.shared.userAgent += - " \(Strada.userAgentSubstring(for: BridgeComponent.allTypes))" + Turbo.config.userAgent += " \(Strada.userAgentSubstring(for: BridgeComponent.allTypes))" - TurboConfig.shared.makeCustomWebView = { config in + Turbo.config.makeCustomWebView = { config in config.defaultWebpagePreferences?.preferredContentMode = .mobile let webView = WKWebView(frame: .zero, configuration: .appConfiguration) diff --git a/Source/Logging.swift b/Source/Logging.swift index 375097e..b75f916 100644 --- a/Source/Logging.swift +++ b/Source/Logging.swift @@ -1,13 +1,13 @@ import Foundation -public struct TurboLog { - public static var debugLoggingEnabled = false +enum TurboLogger { + static var debugLoggingEnabled = false } /// Simple function to help in debugging, a noop in Release builds func debugLog(_ message: String, _ arguments: [String: Any] = [:]) { let timestamp = Date() - + log("\(timestamp) \(message) \(arguments)") } @@ -16,7 +16,7 @@ func debugPrint(_ message: String) { } private func log(_ message: String) { - if TurboLog.debugLoggingEnabled { + if TurboLogger.debugLoggingEnabled { print(message) } } diff --git a/Source/Turbo Navigator/TurboNavigator.swift b/Source/Turbo Navigator/TurboNavigator.swift index 583c93a..e5198a0 100644 --- a/Source/Turbo Navigator/TurboNavigator.swift +++ b/Source/Turbo Navigator/TurboNavigator.swift @@ -46,10 +46,10 @@ public class TurboNavigator { /// - pathConfiguration: /// - delegate: an optional delegate to handle custom view controllers public convenience init(pathConfiguration: PathConfiguration, delegate: TurboNavigatorDelegate? = nil) { - let session = Session(webView: TurboConfig.shared.makeWebView()) + let session = Session(webView: Turbo.config.makeWebView()) session.pathConfiguration = pathConfiguration - let modalSession = Session(webView: TurboConfig.shared.makeWebView()) + let modalSession = Session(webView: Turbo.config.makeWebView()) modalSession.pathConfiguration = pathConfiguration self.init(session: session, modalSession: modalSession, delegate: delegate) diff --git a/Source/Turbo Navigator/Helpers/TurboConfig.swift b/Source/Turbo.swift similarity index 84% rename from Source/Turbo Navigator/Helpers/TurboConfig.swift rename to Source/Turbo.swift index cf2122e..ab6d559 100644 --- a/Source/Turbo Navigator/Helpers/TurboConfig.swift +++ b/Source/Turbo.swift @@ -1,10 +1,12 @@ import WebKit +public enum Turbo { + public static var config = TurboConfig() +} + public class TurboConfig { public typealias WebViewBlock = (_ configuration: WKWebViewConfiguration) -> WKWebView - public static let shared = TurboConfig() - /// Override to set a custom user agent. /// Include "Turbo Native" to use `turbo_native_app?` on your Rails server. public var userAgent = "Turbo Native iOS" @@ -15,6 +17,12 @@ public class TurboConfig { WKWebView(frame: .zero, configuration: configuration) } + public var debugLoggingEnabled = false { + didSet { + TurboLogger.debugLoggingEnabled = debugLoggingEnabled + } + } + // MARK: - Internal public func makeWebView() -> WKWebView { @@ -25,8 +33,6 @@ public class TurboConfig { private let sharedProcessPool = WKProcessPool() - private init() {} - // A method (not a property) because we need a new instance for each web view. private func makeWebViewConfiguration() -> WKWebViewConfiguration { let configuration = WKWebViewConfiguration()