From b0b67290bed337b2cecafcf4e9e762ca75e9390f Mon Sep 17 00:00:00 2001 From: Josue Proano Date: Thu, 23 Jan 2025 21:12:41 -0500 Subject: [PATCH 1/4] test --- Tests/Turbo/HotwireConfigTests.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tests/Turbo/HotwireConfigTests.swift diff --git a/Tests/Turbo/HotwireConfigTests.swift b/Tests/Turbo/HotwireConfigTests.swift new file mode 100644 index 0000000..e69de29 From 2b7a713e34f3d0d36eddf44972be009199402bd9 Mon Sep 17 00:00:00 2001 From: Josue Proano Date: Thu, 23 Jan 2025 21:13:04 -0500 Subject: [PATCH 2/4] expose user agent get only --- Source/HotwireConfig.swift | 16 ++++++++++++---- Tests/Turbo/HotwireConfigTests.swift | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Source/HotwireConfig.swift b/Source/HotwireConfig.swift index fcd2744..6c97057 100644 --- a/Source/HotwireConfig.swift +++ b/Source/HotwireConfig.swift @@ -29,6 +29,17 @@ public struct HotwireConfig { HotwireLogger.debugLoggingEnabled = debugLoggingEnabled } } + + /// Getter for user-agent string + /// - returns: "`applicationUserAgentPrefix`; Native iOS; Turbo Native iOS; bridge-components: [your bridge components];" + public var userAgent: String { + get { + return UserAgent.build( + applicationPrefix: applicationUserAgentPrefix, + componentTypes: Hotwire.bridgeComponentTypes + ) + } + } // MARK: Turbo @@ -85,10 +96,7 @@ public struct HotwireConfig { private func makeWebViewConfiguration() -> WKWebViewConfiguration { let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences?.preferredContentMode = .mobile - configuration.applicationNameForUserAgent = UserAgent.build( - applicationPrefix: applicationUserAgentPrefix, - componentTypes: Hotwire.bridgeComponentTypes - ) + configuration.applicationNameForUserAgent = userAgent configuration.processPool = sharedProcessPool return configuration } diff --git a/Tests/Turbo/HotwireConfigTests.swift b/Tests/Turbo/HotwireConfigTests.swift index e69de29..9fd4f41 100644 --- a/Tests/Turbo/HotwireConfigTests.swift +++ b/Tests/Turbo/HotwireConfigTests.swift @@ -0,0 +1,18 @@ +import XCTest +@testable import HotwireNative + +final class HotwireConfigTests: XCTestCase { + func testUserAgent() { + var config = HotwireConfig() + config.applicationUserAgentPrefix = "TestApp/1.0" + + let testComponent = MockBridgeComponent.self + Hotwire.registerBridgeComponents([testComponent]) + + XCTAssertEqual(config.userAgent, "TestApp/1.0 Hotwire Native iOS; Turbo Native iOS; bridge-components: [MockComponent]") + } +} + +private class MockBridgeComponent: BridgeComponent { + static override var name: String { "MockComponent" } +} From 88623242d04ec9422ef3475edf2e08afbde682b1 Mon Sep 17 00:00:00 2001 From: Josue Proano Date: Sun, 26 Jan 2025 18:00:32 -0500 Subject: [PATCH 3/4] update name to `userAgentComponent` --- Source/HotwireConfig.swift | 4 ++-- Tests/Turbo/HotwireConfigTests.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/HotwireConfig.swift b/Source/HotwireConfig.swift index 6c97057..f1d4822 100644 --- a/Source/HotwireConfig.swift +++ b/Source/HotwireConfig.swift @@ -32,7 +32,7 @@ public struct HotwireConfig { /// Getter for user-agent string /// - returns: "`applicationUserAgentPrefix`; Native iOS; Turbo Native iOS; bridge-components: [your bridge components];" - public var userAgent: String { + public var userAgentComponent: String { get { return UserAgent.build( applicationPrefix: applicationUserAgentPrefix, @@ -96,7 +96,7 @@ public struct HotwireConfig { private func makeWebViewConfiguration() -> WKWebViewConfiguration { let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences?.preferredContentMode = .mobile - configuration.applicationNameForUserAgent = userAgent + configuration.applicationNameForUserAgent = userAgentComponent configuration.processPool = sharedProcessPool return configuration } diff --git a/Tests/Turbo/HotwireConfigTests.swift b/Tests/Turbo/HotwireConfigTests.swift index 9fd4f41..107247d 100644 --- a/Tests/Turbo/HotwireConfigTests.swift +++ b/Tests/Turbo/HotwireConfigTests.swift @@ -9,7 +9,7 @@ final class HotwireConfigTests: XCTestCase { let testComponent = MockBridgeComponent.self Hotwire.registerBridgeComponents([testComponent]) - XCTAssertEqual(config.userAgent, "TestApp/1.0 Hotwire Native iOS; Turbo Native iOS; bridge-components: [MockComponent]") + XCTAssertEqual(config.userAgentComponent, "TestApp/1.0 Hotwire Native iOS; Turbo Native iOS; bridge-components: [MockComponent]") } } From e9c66314e5bb8a623984ae0d7d700ef381845fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=A0vara?= Date: Wed, 29 Jan 2025 10:52:00 +0100 Subject: [PATCH 4/4] Rename `userAgentComponent` to `userAgent`. --- Source/HotwireConfig.swift | 13 +++++++++---- Tests/Turbo/HotwireConfigTests.swift | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/HotwireConfig.swift b/Source/HotwireConfig.swift index f1d4822..bc4662f 100644 --- a/Source/HotwireConfig.swift +++ b/Source/HotwireConfig.swift @@ -30,9 +30,14 @@ public struct HotwireConfig { } } - /// Getter for user-agent string - /// - returns: "`applicationUserAgentPrefix`; Native iOS; Turbo Native iOS; bridge-components: [your bridge components];" - public var userAgentComponent: String { + /// Gets the user agent that the library builds to identify the app + /// and its registered bridge components. + /// + /// The user agent includes: + /// - Your (optional) custom `applicationUserAgentPrefix` + /// - "Native iOS; Turbo Native iOS;" + /// - "bridge-components: [your bridge components];" + public var userAgent: String { get { return UserAgent.build( applicationPrefix: applicationUserAgentPrefix, @@ -96,7 +101,7 @@ public struct HotwireConfig { private func makeWebViewConfiguration() -> WKWebViewConfiguration { let configuration = WKWebViewConfiguration() configuration.defaultWebpagePreferences?.preferredContentMode = .mobile - configuration.applicationNameForUserAgent = userAgentComponent + configuration.applicationNameForUserAgent = userAgent configuration.processPool = sharedProcessPool return configuration } diff --git a/Tests/Turbo/HotwireConfigTests.swift b/Tests/Turbo/HotwireConfigTests.swift index 107247d..9fd4f41 100644 --- a/Tests/Turbo/HotwireConfigTests.swift +++ b/Tests/Turbo/HotwireConfigTests.swift @@ -9,7 +9,7 @@ final class HotwireConfigTests: XCTestCase { let testComponent = MockBridgeComponent.self Hotwire.registerBridgeComponents([testComponent]) - XCTAssertEqual(config.userAgentComponent, "TestApp/1.0 Hotwire Native iOS; Turbo Native iOS; bridge-components: [MockComponent]") + XCTAssertEqual(config.userAgent, "TestApp/1.0 Hotwire Native iOS; Turbo Native iOS; bridge-components: [MockComponent]") } }