capacitor-gleap-plugin 19.0.0 → 19.1.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,10 +74,13 @@ 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),
79
82
  CAPPluginMethod(name: "openConversation", returnType: CAPPluginReturnPromise),
83
+ CAPPluginMethod(name: "openProtectedFileFromUrl", returnType: CAPPluginReturnPromise),
80
84
  CAPPluginMethod(name: "setNotificationContainerOffset", returnType: CAPPluginReturnPromise)
81
85
  ]
82
86
 
@@ -90,6 +94,9 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
90
94
  private var lastLogConfig: [String: Any]?
91
95
  // Set by disableConsoleLogOverwrite: WebView console logs are no longer attached.
92
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] = [:]
93
100
 
94
101
  @objc func initialize(_ call: CAPPluginCall) {
95
102
  // Check if key is present
@@ -111,6 +118,8 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
111
118
  // Initialize Gleap with API key
112
119
  Gleap.initialize(withToken: api_key)
113
120
 
121
+ registerLogFlushHandler()
122
+
114
123
  // A reloaded WebView calls initialize again: hand it the config that was already loaded.
115
124
  DispatchQueue.main.async {
116
125
  if let logConfig = self.lastLogConfig {
@@ -124,6 +133,38 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
124
133
  ])
125
134
  }
126
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
+
127
168
  // Data region & host overrides. All of them must be called before initialize.
128
169
  @objc func setRegion(_ call: CAPPluginCall) {
129
170
  guard let region = call.options["region"] as? String else {
@@ -757,6 +798,34 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
757
798
  ])
758
799
  }
759
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
+
760
829
  @objc func showFeedbackButton(_ call: CAPPluginCall) {
761
830
  let showFeedbackButton = call.getBool("show") ?? false
762
831
 
@@ -1027,6 +1096,29 @@ public class GleapPlugin: CAPPlugin, CAPBridgedPlugin, GleapDelegate {
1027
1096
  openConversations(call)
1028
1097
  }
1029
1098
 
1099
+ // Emailed protected file link (`gleapFile` query parameter). The SDK opens the conversation
1100
+ // once a verified identify (user hash) gave the session file access.
1101
+ @objc func openProtectedFileFromUrl(_ call: CAPPluginCall) {
1102
+ guard let urlString = call.getString("url") else {
1103
+ call.reject("No url provided")
1104
+ return;
1105
+ }
1106
+
1107
+ // A string that is no URL carries no file reference.
1108
+ guard let url = URL(string: urlString) else {
1109
+ call.resolve([
1110
+ "opened": false
1111
+ ])
1112
+ return;
1113
+ }
1114
+
1115
+ let opened = Gleap.openProtectedFile(from: url)
1116
+
1117
+ call.resolve([
1118
+ "opened": opened
1119
+ ])
1120
+ }
1121
+
1030
1122
  @objc func startFeedbackFlow(_ call: CAPPluginCall) {
1031
1123
  let feedbackFlow = call.getString("feedbackFlow") ?? "bugreporting"
1032
1124
  let showBackButton = call.getBool("showBackButton") ?? true
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.0",
4
+ "version": "19.1.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.1.0"
101
101
  }
102
102
  }