@@ -9,20 +9,62 @@ public struct ChatwootConfiguration {
99 public let accessToken : String
1010 public let pubsubToken : String
1111 public let websocketUrl : String
12+ public let inboxName : String
13+ public let disableEditor : Bool
14+ public let editorDisableUpload : Bool
15+ #if canImport(UIKit)
16+ public let backArrowIcon : UIImage
17+ public let connectedIcon : UIImage
18+ public let disconnectedIcon : UIImage
19+ #endif
1220
21+ #if canImport(UIKit)
1322 public init (
1423 accountId: Int ,
1524 apiHost: String ,
1625 accessToken: String ,
1726 pubsubToken: String ,
18- websocketUrl: String
27+ websocketUrl: String ,
28+ inboxName: String ,
29+ disableEditor: Bool = false ,
30+ editorDisableUpload: Bool = false ,
31+ backArrowIcon: UIImage ,
32+ connectedIcon: UIImage ,
33+ disconnectedIcon: UIImage
1934 ) {
2035 self . accountId = accountId
2136 self . apiHost = apiHost
2237 self . accessToken = accessToken
2338 self . pubsubToken = pubsubToken
2439 self . websocketUrl = websocketUrl
40+ self . inboxName = inboxName
41+ self . disableEditor = disableEditor
42+ self . editorDisableUpload = editorDisableUpload
43+ self . backArrowIcon = backArrowIcon
44+ self . connectedIcon = connectedIcon
45+ self . disconnectedIcon = disconnectedIcon
2546 }
47+ #else
48+ public init (
49+ accountId: Int ,
50+ apiHost: String ,
51+ accessToken: String ,
52+ pubsubToken: String ,
53+ websocketUrl: String ,
54+ inboxName: String ,
55+ disableEditor: Bool = false ,
56+ editorDisableUpload: Bool = false
57+ ) {
58+ self . accountId = accountId
59+ self . apiHost = apiHost
60+ self . accessToken = accessToken
61+ self . pubsubToken = pubsubToken
62+ self . websocketUrl = websocketUrl
63+ self . inboxName = inboxName
64+ self . disableEditor = disableEditor
65+ self . editorDisableUpload = editorDisableUpload
66+ }
67+ #endif
2668}
2769
2870public enum ChatwootSDK {
@@ -36,6 +78,78 @@ public enum ChatwootSDK {
3678 }
3779
3880#if canImport(UIKit)
81+ private static var currentThemeColor : UIColor = . white // Default as per theme.md
82+ private static var currentTextColor : UIColor ? = nil // nil means auto-detect based on theme color
83+ /// Sets the theme color for the Chatwoot UI
84+ /// - Parameter color: The UIColor to use for theming.
85+ public static func setThemeColor( _ color: UIColor ) {
86+ currentThemeColor = color
87+ }
88+
89+ /// Sets the theme color for the Chatwoot UI using a hex string
90+ /// - Parameter hex: Hex color string (supports formats: "#RRGGBB", "#RGB", "RRGGBB", "RGB")
91+ /// - Returns: True if the color was set successfully, false if the hex string is invalid
92+ @discardableResult
93+ public static func setThemeColor( hex: String ) -> Bool {
94+ guard let color = UIColor ( hex: hex) else {
95+ print ( " [Chatwoot] Warning: Invalid hex color string ' \( hex) '. Theme color not changed. " )
96+ return false
97+ }
98+ currentThemeColor = color
99+ return true
100+ }
101+
102+ /// Sets the theme color for the Chatwoot UI using a hex string (convenient overload)
103+ /// - Parameter hexString: Hex color string (supports formats: "#RRGGBB", "#RGB", "RRGGBB", "RGB")
104+ /// - Returns: True if the color was set successfully, false if the hex string is invalid
105+ @discardableResult
106+ public static func setThemeColor( _ hexString: String ) -> Bool {
107+ return setThemeColor ( hex: hexString)
108+ }
109+
110+ /// Sets the text color for the Chatwoot UI
111+ /// - Parameter color: The UIColor to use for text elements (close button, labels, etc.).
112+ public static func setTextColor( _ color: UIColor ) {
113+ currentTextColor = color
114+ }
115+
116+ /// Sets the text color for the Chatwoot UI using a hex string
117+ /// - Parameter hex: Hex color string (supports formats: "#RRGGBB", "#RGB", "RRGGBB", "RGB")
118+ /// - Returns: True if the color was set successfully, false if the hex string is invalid
119+ @discardableResult
120+ public static func setTextColor( hex: String ) -> Bool {
121+ guard let color = UIColor ( hex: hex) else {
122+ print ( " [Chatwoot] Warning: Invalid hex color string ' \( hex) '. Text color not changed. " )
123+ return false
124+ }
125+ currentTextColor = color
126+ return true
127+ }
128+
129+ /// Sets the text color for the Chatwoot UI using a hex string (convenient overload)
130+ /// - Parameter hexString: Hex color string (supports formats: "#RRGGBB", "#RGB", "RRGGBB", "RGB")
131+ /// - Returns: True if the color was set successfully, false if the hex string is invalid
132+ @discardableResult
133+ public static func setTextColor( _ hexString: String ) -> Bool {
134+ return setTextColor ( hex: hexString)
135+ }
136+
137+ /// Gets the current theme color
138+ /// - Returns: The currently set UIColor for the theme.
139+ public static func getCurrentThemeColor( ) -> UIColor {
140+ return currentThemeColor
141+ }
142+
143+ /// Gets the current text color (auto-detects based on theme if not explicitly set)
144+ /// - Returns: The UIColor to use for text elements.
145+ public static func getCurrentTextColor( ) -> UIColor {
146+ if let textColor = currentTextColor {
147+ return textColor
148+ }
149+ // Auto-detect based on theme color luminance
150+ return currentThemeColor. isLight ? . black : . white
151+ }
152+
39153 /// Creates and returns a UIViewController for the Chatwoot chat interface
40154 /// - Parameter conversationId: Conversation ID to load a specific conversation
41155 /// - Returns: A UIViewController that can be presented modally or pushed onto a navigation stack
0 commit comments