capacitor-gleap-plugin 19.0.1 → 19.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,7 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
29
29
  CAPPluginMethod(name: "setEnvDataPropsToIgnore", returnType: CAPPluginReturnPromise),
30
30
  CAPPluginMethod(name: "attachNetworkLogs", returnType: CAPPluginReturnPromise),
31
31
  CAPPluginMethod(name: "attachConsoleLogs", returnType: CAPPluginReturnPromise),
32
+ CAPPluginMethod(name: "logsFlushed", returnType: CAPPluginReturnPromise),
32
33
  CAPPluginMethod(name: "attachCustomData", returnType: CAPPluginReturnPromise),
33
34
  CAPPluginMethod(name: "setCustomData", returnType: CAPPluginReturnPromise),
34
35
  CAPPluginMethod(name: "removeCustomData", returnType: CAPPluginReturnPromise),
@@ -73,6 +74,8 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
73
74
  CAPPluginMethod(name: "setDisableInAppNotifications", returnType: CAPPluginReturnPromise),
74
75
  CAPPluginMethod(name: "setDisableEnvData", returnType: CAPPluginReturnPromise),
75
76
  CAPPluginMethod(name: "setColorScheme", returnType: CAPPluginReturnPromise),
77
+ CAPPluginMethod(name: "setCaptureEnabled", returnType: CAPPluginReturnPromise),
78
+ CAPPluginMethod(name: "setRemoteLogCollectionEnabled", returnType: CAPPluginReturnPromise),
76
79
  CAPPluginMethod(name: "startClassicForm", returnType: CAPPluginReturnPromise),
77
80
  CAPPluginMethod(name: "startConversation", returnType: CAPPluginReturnPromise),
78
81
  CAPPluginMethod(name: "openConversations", returnType: CAPPluginReturnPromise),
@@ -91,6 +94,9 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
91
94
  private var lastLogConfig: [String: Any]?
92
95
  // Set by disableConsoleLogOverwrite: WebView console logs are no longer attached.
93
96
  private var webViewConsoleLogsDisabled = false
97
+ // Capture requests: log flushes the native SDK waits for (at most 500 ms) until the WebView log capture handed
98
+ // over what it buffers, by flush id (main queue only).
99
+ private var pendingLogFlushes: [String: () -> Void] = [:]
94
100
 
95
101
  @objc func initialize(_ call: CAPPluginCall) {
96
102
  // Check if key is present
@@ -112,6 +118,8 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
112
118
  // Initialize Gleap with API key
113
119
  Gleap.initialize(withToken: api_key)
114
120
 
121
+ registerLogFlushHandler()
122
+
115
123
  // A reloaded WebView calls initialize again: hand it the config that was already loaded.
116
124
  DispatchQueue.main.async {
117
125
  if let logConfig = self.lastLogConfig {
@@ -125,6 +133,38 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
125
133
  ])
126
134
  }
127
135
 
136
+ // Capture requests: before the native SDK collects the logs for a request, the WebView log capture hands over
137
+ // what it buffers (pushed at most every 500 ms otherwise). The SDK waits at most 500 ms for done; without a
138
+ // flushLogs listener it does not wait.
139
+ private func registerLogFlushHandler() {
140
+ Gleap.setLogFlushHandler { [weak self] done in
141
+ DispatchQueue.main.async {
142
+ guard let self = self, self.hasListeners("flushLogs") else {
143
+ done()
144
+ return
145
+ }
146
+ let flushId = UUID().uuidString
147
+ self.pendingLogFlushes[flushId] = done
148
+ self.notifyListeners("flushLogs", data: ["flushId": flushId])
149
+ // An unanswered flush (e.g. the page reloaded) is forgotten; the SDK stopped waiting long before.
150
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
151
+ self?.pendingLogFlushes.removeValue(forKey: flushId)
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ // The WebView log capture handed over what it buffered for the flush with this id.
158
+ @objc func logsFlushed(_ call: CAPPluginCall) {
159
+ let flushId = call.getString("flushId")
160
+ DispatchQueue.main.async {
161
+ if let flushId = flushId, let done = self.pendingLogFlushes.removeValue(forKey: flushId) {
162
+ done()
163
+ }
164
+ }
165
+ call.resolve()
166
+ }
167
+
128
168
  // Data region & host overrides. All of them must be called before initialize.
129
169
  @objc func setRegion(_ call: CAPPluginCall) {
130
170
  guard let region = call.options["region"] as? String else {
@@ -758,6 +798,34 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
758
798
  ])
759
799
  }
760
800
 
801
+ // Enables or disables screenshots and screen recordings for capture requests.
802
+ @objc func setCaptureEnabled(_ call: CAPPluginCall) {
803
+ guard let enabled = call.getBool("enabled") else {
804
+ call.reject("No enabled value provided")
805
+ return
806
+ }
807
+
808
+ Gleap.setCaptureEnabled(enabled)
809
+
810
+ call.resolve([
811
+ "captureEnabled": enabled
812
+ ])
813
+ }
814
+
815
+ // Enables or disables sending the app's logs for capture requests.
816
+ @objc func setRemoteLogCollectionEnabled(_ call: CAPPluginCall) {
817
+ guard let enabled = call.getBool("enabled") else {
818
+ call.reject("No enabled value provided")
819
+ return
820
+ }
821
+
822
+ Gleap.setRemoteLogCollectionEnabled(enabled)
823
+
824
+ call.resolve([
825
+ "remoteLogCollectionEnabled": enabled
826
+ ])
827
+ }
828
+
761
829
  @objc func showFeedbackButton(_ call: CAPPluginCall) {
762
830
  let showFeedbackButton = call.getBool("show") ?? false
763
831
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "homepage": "https://www.gleap.ai",
3
3
  "name": "capacitor-gleap-plugin",
4
- "version": "19.0.1",
4
+ "version": "19.2.0",
5
5
  "description": "Gleap SDK for Capacitor and Ionic: AI customer support, live chat, in-app bug reporting and customer feedback.",
6
6
  "main": "dist/plugin.cjs.js",
7
7
  "module": "dist/esm/index.js",
@@ -97,6 +97,6 @@
97
97
  }
98
98
  },
99
99
  "dependencies": {
100
- "gleap": "^19.0.0"
100
+ "gleap": "^19.2.0"
101
101
  }
102
102
  }