diff --git a/GliaWidgets.xcodeproj/project.pbxproj b/GliaWidgets.xcodeproj/project.pbxproj index 18d20f15e..2d315d0e2 100644 --- a/GliaWidgets.xcodeproj/project.pbxproj +++ b/GliaWidgets.xcodeproj/project.pbxproj @@ -250,7 +250,6 @@ 755D187929A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187829A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift */; }; 755D187B29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187A29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift */; }; 755D187F29A6B1B90009F5E8 /* Glia+StartEngagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */; }; - 7562B2ED28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */; }; 756979C52A1E5E3C002ED254 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 756979C42A1E5E3C002ED254 /* Assets.xcassets */; }; 756B8B1C2996B116001D2BB2 /* ChatCoordinator.Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756B8B1B2996B116001D2BB2 /* ChatCoordinator.Environment.swift */; }; 756B8B1E2996BAEA001D2BB2 /* HeaderButton.Props.swift in Sources */ = {isa = PBXBuildFile; fileRef = 756B8B1D2996BAEA001D2BB2 /* HeaderButton.Props.swift */; }; @@ -987,7 +986,6 @@ 755D187829A6A6F80009F5E8 /* WelcomeStyle+FilePickerButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WelcomeStyle+FilePickerButtonStyle.swift"; sourceTree = ""; }; 755D187A29A6A7180009F5E8 /* WelcomeStyle+TitleImageStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WelcomeStyle+TitleImageStyle.swift"; sourceTree = ""; }; 755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Glia+StartEngagement.swift"; sourceTree = ""; }; - 7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Glia.RemoteConfiguration.swift; sourceTree = ""; }; 756979C42A1E5E3C002ED254 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 756B8B1B2996B116001D2BB2 /* ChatCoordinator.Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatCoordinator.Environment.swift; sourceTree = ""; }; 756B8B1D2996BAEA001D2BB2 /* HeaderButton.Props.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderButton.Props.swift; sourceTree = ""; }; @@ -2799,7 +2797,6 @@ children = ( AFBBF5772851C391004993B3 /* Glia.Deprecated.swift */, 7594098E298D3929008B173A /* Glia.OpaqueAuthentication.swift */, - 7562B2EC28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift */, 1A60AF7D25656F0400E53F53 /* Glia.swift */, 755D187E29A6B1B90009F5E8 /* Glia+StartEngagement.swift */, ); @@ -4529,7 +4526,6 @@ 1A60AF93256674F900E53F53 /* Color.swift in Sources */, 1A38A8BA258B94D60089DE7B /* ImageView.swift in Sources */, C0857DE528D470C1008D171D /* Theme+Shadow.swift in Sources */, - 7562B2ED28CBD9AE0040C784 /* Glia.RemoteConfiguration.swift in Sources */, 9AB196E227C4045B00FD60AB /* ChatViewController.Mock.swift in Sources */, 1A60B031256BF81500E53F53 /* VisitorChatMessageView.swift in Sources */, 1A5892B12608C68000E183CC /* QuickLookController.swift in Sources */, diff --git a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift index ead149757..9ef8ff06b 100644 --- a/GliaWidgets/Public/Glia/Glia+StartEngagement.swift +++ b/GliaWidgets/Public/Glia/Glia+StartEngagement.swift @@ -7,7 +7,6 @@ extension Glia { /// - Parameters: /// - engagementKind: Engagement media type. /// - in: Queue identifiers - /// - theme: A custom theme to use with the engagement. /// - visitorContext: Visitor context. /// - features: Set of features to be enabled in the SDK. /// - sceneProvider: Used to provide `UIWindowScene` to the framework. Defaults to the first active foreground scene. @@ -24,7 +23,6 @@ extension Glia { public func startEngagement( engagementKind: EngagementKind, in queueIds: [String], - theme: Theme = Theme(), features: Features = .all, sceneProvider: SceneProvider? = nil ) throws { diff --git a/GliaWidgets/Public/Glia/Glia.Deprecated.swift b/GliaWidgets/Public/Glia/Glia.Deprecated.swift index dda59f821..2ea37ee6a 100644 --- a/GliaWidgets/Public/Glia/Glia.Deprecated.swift +++ b/GliaWidgets/Public/Glia/Glia.Deprecated.swift @@ -20,7 +20,7 @@ extension Glia { /// Deprecated. @available( *, - deprecated, + unavailable, message: "Use start(_:configuration:queueID:visitorContext:theme:features:sceneProvider:) with Optional instead." ) public func start( @@ -205,6 +205,85 @@ extension Glia { debugPrint("💥 Core SDK configuration is not valid. Unexpected error='\(error)'.") } } + + /// Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. + /// Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. + @available(*, deprecated, message: """ + Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. + Use ``configure(with configuration:uiConfig:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. + """ + ) + public func startEngagementWithConfig( + engagement: EngagementKind, + in queueIds: [String], + uiConfig: RemoteConfiguration, + assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, + features: Features = .all, + sceneProvider: SceneProvider? = nil + ) throws { + // Store assetsBuilder and apply remote config to have ability to + // apply them for Call Visualizer flow if integrator use + // old `configure` method + theme.apply(configuration: uiConfig, assetsBuilder: assetsBuilder) + self.assetsBuilder = assetsBuilder + + if let config = configuration { + theme.showsPoweredBy = !config.isWhiteLabelApp + theme.chat.connect.queue.firstText = config.companyName + theme.call.connect.queue.firstText = config.companyName + } + + try startEngagement( + engagementKind: engagement, + in: queueIds, + theme: theme, + features: features, + sceneProvider: sceneProvider + ) + } + + /// Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. + /// Use ``configure(with configuration:uiConfig:theme:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. + @available(*, deprecated, message: """ + Deprecated, use ``Glia.startEngagement(engagementKind:in queueIds:features:sceneProvider:)`` instead. + Use ``configure(with configuration:uiConfig:theme:assetsBuilder:completion:)`` to pass in ``RemoteConfiguration``. + """ + ) + public func startEngagement( + engagementKind: EngagementKind, + in queueIds: [String], + theme: Theme = Theme(), + features: Features = .all, + sceneProvider: SceneProvider? = nil + ) throws { + self.theme = theme + try startEngagement( + engagementKind: engagementKind, + in: queueIds, + features: features, + sceneProvider: sceneProvider + ) + } + + /// Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. + @available(*, deprecated, message: """ + Deprecated, use ``configure(with configuration:theme:uiConfig:assetsBuilder:completion:)`` instead. + """ + ) + public func configure( + with configuration: Configuration, + uiConfig: RemoteConfiguration? = nil, + assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, + completion: @escaping (Result) -> Void + ) throws { + try configure( + with: configuration, + theme: Theme(), + uiConfig: uiConfig, + assetsBuilder: assetsBuilder, + completion: completion + ) + } } extension Glia.Authentication { diff --git a/GliaWidgets/Public/Glia/Glia.RemoteConfiguration.swift b/GliaWidgets/Public/Glia/Glia.RemoteConfiguration.swift deleted file mode 100644 index d4d42fb32..000000000 --- a/GliaWidgets/Public/Glia/Glia.RemoteConfiguration.swift +++ /dev/null @@ -1,57 +0,0 @@ -import Foundation - -extension Glia { - - /// Starts the engagement. - /// - /// - Parameters: - /// - engagementKind: Engagement media type. - /// - in: Queue identifiers - /// - uiConfig: Remote UI configuration. - /// - assetsBuilder: Provides assets for remote configuration. - /// - features: Set of features to be enabled in the SDK. - /// - sceneProvider: Used to provide `UIWindowScene` to the framework. Defaults to the first active foreground scene. - /// - /// - throws: - /// - `GliaCoreSDK.ConfigurationError.invalidSite` - /// - `GliaCoreSDK.ConfigurationError.invalidEnvironment` - /// - `GliaError.engagementExists - /// - `GliaError.sdkIsNotConfigured` - /// - /// - Important: Note, that `configure(with:uiConfig:assetsBuilder:completion:)` must be called initially prior to this method, - /// because `GliaError.sdkIsNotConfigured` will occur otherwise. - /// - public func startEngagementWithConfig( - engagement: EngagementKind, - in queueIds: [String], - uiConfig: RemoteConfiguration, - assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, - features: Features = .all, - sceneProvider: SceneProvider? = nil - ) throws { - // Store uiConfig and assetsBuilder to have ability to - // apply them for Call Visualizer flow if integrator use - // old `configure` method - self.uiConfig = uiConfig - self.assetsBuilder = assetsBuilder - - // Apply remote configuration - let theme = Theme( - uiConfig: uiConfig, - assetsBuilder: assetsBuilder - ) - if let config = configuration { - theme.showsPoweredBy = !config.isWhiteLabelApp - theme.chat.connect.queue.firstText = config.companyName - theme.call.connect.queue.firstText = config.companyName - } - - try startEngagement( - engagementKind: engagement, - in: queueIds, - theme: theme, - features: features, - sceneProvider: sceneProvider - ) - } -} diff --git a/GliaWidgets/Public/Glia/Glia.swift b/GliaWidgets/Public/Glia/Glia.swift index a34c951b8..0cdb186cd 100644 --- a/GliaWidgets/Public/Glia/Glia.swift +++ b/GliaWidgets/Public/Glia/Glia.swift @@ -80,7 +80,7 @@ public class Glia { engagedOperator: { [weak self] in self?.environment.coreSdk.getCurrentEngagement()?.engagedOperator }, - uiConfig: { [weak self] in self?.uiConfig }, + theme: theme, assetsBuilder: { [weak self] in self?.assetsBuilder ?? .standard }, getCurrentEngagement: environment.coreSdk.getCurrentEngagement, eventHandler: onEvent, @@ -92,23 +92,26 @@ public class Glia { var interactor: Interactor? var environment: Environment var messageRenderer: MessageRenderer? = .webRenderer - var uiConfig: RemoteConfiguration? + var theme: Theme var assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard private(set) var configuration: Configuration? init(environment: Environment) { self.environment = environment + self.theme = Theme() } /// Setup SDK using specific engagement configuration without starting the engagement. /// - Parameters: /// - configuration: Engagement configuration. + /// - theme: A custom theme to use with the engagement. /// - uiConfig: Remote UI configuration. /// - assetsBuilder: Provides assets for remote configuration. /// - completion: Completion handler that will be fired once configuration is complete. public func configure( with configuration: Configuration, + theme: Theme = Theme(), uiConfig: RemoteConfiguration? = nil, assetsBuilder: RemoteConfiguration.AssetsBuilder = .standard, completion: @escaping (Result) -> Void @@ -116,7 +119,11 @@ public class Glia { guard environment.coreSdk.getCurrentEngagement() == nil else { throw GliaError.configuringDuringEngagementIsNotAllowed } - self.uiConfig = uiConfig + + if let uiConfig { + theme.apply(configuration: uiConfig, assetsBuilder: assetsBuilder) + } + self.theme = theme self.assetsBuilder = assetsBuilder // `configuration` should be erased to avoid cases when integrators // call `configure` and `startEngagement` asynchronously, and diff --git a/GliaWidgets/Sources/CallVisualizer/CallVisualizer+Environment.swift b/GliaWidgets/Sources/CallVisualizer/CallVisualizer+Environment.swift index 03d204825..c5d42b291 100644 --- a/GliaWidgets/Sources/CallVisualizer/CallVisualizer+Environment.swift +++ b/GliaWidgets/Sources/CallVisualizer/CallVisualizer+Environment.swift @@ -19,7 +19,7 @@ extension CallVisualizer { var audioSession: Glia.Environment.AudioSession var date: () -> Date var engagedOperator: () -> CoreSdkClient.Operator? - var uiConfig: () -> RemoteConfiguration? + var theme: Theme var assetsBuilder: () -> RemoteConfiguration.AssetsBuilder var getCurrentEngagement: CoreSdkClient.GetCurrentEngagement var eventHandler: ((GliaEvent) -> Void)? diff --git a/GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift b/GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift index bd9893135..53af4a3b2 100644 --- a/GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift +++ b/GliaWidgets/Sources/CallVisualizer/CallVisualizer.swift @@ -15,12 +15,8 @@ public final class CallVisualizer { private var environment: Environment var delegate: ((Action) -> Void)? lazy var coordinator: Coordinator = { - var theme = Theme() - if let uiConfig = environment.uiConfig() { - theme = .init(uiConfig: uiConfig, assetsBuilder: environment.assetsBuilder()) - } let viewFactory = ViewFactory( - with: theme, + with: environment.theme, messageRenderer: nil, environment: .init( data: environment.data, diff --git a/GliaWidgets/Sources/Theme/Theme.swift b/GliaWidgets/Sources/Theme/Theme.swift index dc1f06f6a..c0f53a27d 100644 --- a/GliaWidgets/Sources/Theme/Theme.swift +++ b/GliaWidgets/Sources/Theme/Theme.swift @@ -134,4 +134,50 @@ public class Theme { assetsBuilder: assetsBuilder ) } + + func apply( + configuration: RemoteConfiguration, + assetsBuilder: RemoteConfiguration.AssetsBuilder + ) { + color.apply( + configuration: configuration.globalColors + ) + + call.apply( + configuration: configuration.callScreen, + assetsBuilder: assetsBuilder + ) + survey.apply( + configuration: configuration.surveyScreen, + assetsBuilder: assetsBuilder + ) + alert.apply( + configuration: configuration.alert, + assetsBuilder: assetsBuilder + ) + minimizedBubble.apply( + configuration: configuration.bubble, + assetsBuilder: assetsBuilder + ) + chat.apply( + configuration: configuration.chatScreen, + assetsBuilder: assetsBuilder + ) + visitorCode.apply( + configuration: configuration.callVisualizer?.visitorCode, + assetBuilder: assetsBuilder + ) + screenSharing.apply( + configuration: configuration.callVisualizer?.screenSharing, + assetBuilder: assetsBuilder + ) + secureConversationsWelcome.apply( + configuration: configuration.secureConversationsWelcomeScreen, + assetsBuilder: assetsBuilder + ) + secureConversationsConfirmation.apply( + configuration: configuration.secureConversationsConfirmationScreen, + assetsBuilder: assetsBuilder + ) + } } diff --git a/GliaWidgets/Sources/Theme/ThemeColor.swift b/GliaWidgets/Sources/Theme/ThemeColor.swift index 061a676b4..56b678ac1 100644 --- a/GliaWidgets/Sources/Theme/ThemeColor.swift +++ b/GliaWidgets/Sources/Theme/ThemeColor.swift @@ -54,4 +54,40 @@ public struct ThemeColor { self.systemNegative = systemNegative ?? Color.systemNegative self.baseNeutral = baseNeutral ?? Color.baseNeutral } + + mutating func apply( + configuration: RemoteConfiguration.GlobalColors? + ) { + configuration?.primary.unwrap { + primary = UIColor(hex: $0) + } + + configuration?.secondary.unwrap { + secondary = UIColor(hex: $0) + } + + configuration?.baseNormal.unwrap { + baseNormal = UIColor(hex: $0) + } + + configuration?.baseLight.unwrap { + baseLight = UIColor(hex: $0) + } + + configuration?.baseDark.unwrap { + baseDark = UIColor(hex: $0) + } + + configuration?.baseShade.unwrap { + baseShade = UIColor(hex: $0) + } + + configuration?.systemNegative.unwrap { + systemNegative = UIColor(hex: $0) + } + + configuration?.baseNeutral.unwrap { + baseNeutral = UIColor(hex: $0) + } + } } diff --git a/GliaWidgetsTests/CallVisualizer/ScreenSharing/Mocks/CallVisualizer.Environment.Mock.swift b/GliaWidgetsTests/CallVisualizer/ScreenSharing/Mocks/CallVisualizer.Environment.Mock.swift index f6c8b3632..3b6500812 100644 --- a/GliaWidgetsTests/CallVisualizer/ScreenSharing/Mocks/CallVisualizer.Environment.Mock.swift +++ b/GliaWidgetsTests/CallVisualizer/ScreenSharing/Mocks/CallVisualizer.Environment.Mock.swift @@ -19,7 +19,7 @@ extension CallVisualizer.Environment { audioSession: .mock, date: { .mock }, engagedOperator: { .mock() }, - uiConfig: { nil }, + theme: .init(), assetsBuilder: { .standard }, getCurrentEngagement: CoreSdkClient.mock.getCurrentEngagement, orientationManager: .mock(), diff --git a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift index babd2907d..c6b36fafc 100644 --- a/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift +++ b/GliaWidgetsTests/Sources/Glia/GliaTests+StartEngagement.swift @@ -110,9 +110,9 @@ extension GliaTests { theme.call.connect.queue.firstText = "Glia 1" theme.chat.connect.queue.firstText = "Glia 2" - try sdk.configure(with: .mock()) { + try sdk.configure(with: .mock(), theme: theme) { _ in do { - try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) } catch { XCTFail("startEngagement unexpectedly failed with error \(error), but should succeed instead.") } @@ -275,9 +275,9 @@ extension GliaTests { theme.call.connect.queue.firstText = "Glia 1" theme.chat.connect.queue.firstText = "Glia 2" - try sdk.configure(with: .mock()) { + try sdk.configure(with: .mock(), theme: theme) { _ in do { - try sdk.startEngagement(engagementKind: .chat, in: ["queueId"], theme: theme) + try sdk.startEngagement(engagementKind: .chat, in: ["queueId"]) } catch { XCTFail("startEngagement unexpectedly failed with error \(error), but should succeed instead.") } diff --git a/GliaWidgetsTests/Sources/Glia/GliaTests.swift b/GliaWidgetsTests/Sources/Glia/GliaTests.swift index 25b7a9ebe..7025ea426 100644 --- a/GliaWidgetsTests/Sources/Glia/GliaTests.swift +++ b/GliaWidgetsTests/Sources/Glia/GliaTests.swift @@ -401,4 +401,52 @@ final class GliaTests: XCTestCase { XCTAssertEqual(screenShareHandler.status().value, .stopped) XCTAssertEqual(calls, [.ended]) } + + func test_remoteConfigIsAppliedToThemeUponConfigure() throws { + let themeColor: ThemeColor = .init( + primary: .red, + systemNegative: .red + ) + + let globalColors: RemoteConfiguration.GlobalColors = .init( + primary: "#00FF00", + secondary: "#00FF00", + baseNormal: "#00FF00", + baseLight: "#00FF00", + baseDark: "#00FF00", + baseShade: "#00FF00", + systemNegative: "#00FF00", + baseNeutral: "#00FF00" + ) + + let uiConfig: RemoteConfiguration = .init( + globalColors: globalColors, + callScreen: nil, + chatScreen: nil, + surveyScreen: nil, + alert: nil, + bubble: nil, + callVisualizer: nil, + secureConversationsWelcomeScreen: nil, + secureConversationsConfirmationScreen: nil + ) + + let theme = Theme(colorStyle: .custom(themeColor)) + var environment = Glia.Environment.failing + environment.coreSDKConfigurator.configureWithConfiguration = { _, completion in + completion(.success(())) + } + let sdk = Glia(environment: environment) + let configuration = Configuration.mock() + try sdk.configure( + with: configuration, + theme: theme, + uiConfig: uiConfig) + { _ in } + + let primaryColorHex = sdk.theme.color.primary.toRGBAHex(alpha: false) + let systemNegativeHex = sdk.theme.color.systemNegative.toRGBAHex(alpha: false) + XCTAssertEqual(primaryColorHex, "#00FF00") + XCTAssertEqual(systemNegativeHex, "#00FF00") + } } diff --git a/TestingApp/ViewController/ViewController.swift b/TestingApp/ViewController/ViewController.swift index 09f0b36d5..93b567284 100644 --- a/TestingApp/ViewController/ViewController.swift +++ b/TestingApp/ViewController/ViewController.swift @@ -121,11 +121,7 @@ class ViewController: UIViewController { @IBAction private func configureSDKTapped() { showRemoteConfigAlert { [weak self] fileName in - var config: RemoteConfiguration? - if let fileName = fileName { - config = self?.retrieveRemoteConfiguration(fileName) - } - self?.configureSDK(uiConfig: config) { [weak self] result in + self?.configureSDK(uiConfigName: fileName) { [weak self] result in guard case let .failure(error) = result else { return } self?.showErrorAlert(using: error) } @@ -137,7 +133,7 @@ class ViewController: UIViewController { // only if such engagement exists, we need // to configure SDK, and only then attempt // to end engagement. - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: Glia.sharedInstance.endEngagement { result in @@ -156,7 +152,7 @@ class ViewController: UIViewController { return } self?.showEngagementKindActionSheet { kind in - self?.startEngagement(with: kind, config: fileName) + self?.startEngagement(with: kind) } } } @@ -216,7 +212,7 @@ extension ViewController { } if autoConfigureSdkToggle.isOn { - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: startEngagement() @@ -230,7 +226,7 @@ extension ViewController { } func configureSDK( - uiConfig: RemoteConfiguration?, + uiConfigName: String?, completion: ((Result) -> Void)? = nil ) { let originalTitle = configureButton.title(for: .normal) @@ -244,9 +240,13 @@ extension ViewController { debugPrint(printable) } + let uiConfig = retrieveRemoteConfiguration(uiConfigName) + do { try Glia.sharedInstance.configure( - with: configuration + with: configuration, + theme: Theme(), + uiConfig: uiConfig ) { result in switch result { case .success: @@ -303,21 +303,18 @@ extension ViewController { present(alert, animated: true) } - private func startEngagement(with kind: EngagementKind, config name: String) { - guard let config = retrieveRemoteConfiguration(name) else { return } - + private func startEngagement(with kind: EngagementKind) { let startEngagement = { self.catchingError { - try Glia.sharedInstance.startEngagementWithConfig( - engagement: kind, - in: [self.queueId], - uiConfig: config + try Glia.sharedInstance.startEngagement( + engagementKind: kind, + in: [self.queueId] ) } } if autoConfigureSdkToggle.isOn { - configureSDK(uiConfig: nil) { [weak self] result in + configureSDK(uiConfigName: nil) { [weak self] result in switch result { case .success: startEngagement() @@ -364,13 +361,13 @@ extension ViewController { present(alert, animated: true) } - func retrieveRemoteConfiguration(_ fileName: String) -> RemoteConfiguration? { + func retrieveRemoteConfiguration(_ fileName: String?) -> RemoteConfiguration? { guard let url = Bundle.main.url(forResource: fileName, withExtension: "json", subdirectory: "UnifiedUI"), let jsonData = try? Data(contentsOf: url), let config = try? JSONDecoder().decode(RemoteConfiguration.self, from: .init(jsonData)) else { - alert(message: "Could not decode RemoteConfiguration.") + print("Could not decode RemoteConfiguration.") return nil } return config @@ -406,7 +403,10 @@ extension ViewController { @IBAction private func toggleAuthentication() { catchingError { - try Glia.sharedInstance.configure(with: configuration) { [weak self] result in + try Glia.sharedInstance.configure( + with: configuration, + theme: Theme() + ) { [weak self] result in guard let self = self else { return } switch result { @@ -423,7 +423,6 @@ extension ViewController { ) } } - case .failure(let error): self.showErrorAlert(using: error) }